ContainerList_Import.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. namespace System.Fire.Container {
  8. public partial class ContainerList {
  9. /// <summary>
  10. /// Imports an array of file or directory pathes
  11. /// </summary>
  12. /// <param name="FilePath">Array of file pathes</param>
  13. /// <returns>Returns true if atleast one file was imported</returns>
  14. public bool ImportFile(string[] FilePath) {
  15. int c = 0;
  16. foreach (string s in FilePath)
  17. if (this.ImportFile(s))
  18. c++;
  19. return c > 0;
  20. }
  21. /// <summary>
  22. /// Imports a file or a directory
  23. /// </summary>
  24. /// <param name="FilePath">The file or directory path</param>
  25. /// <returns>Returns true if atleast one file was imported</returns>
  26. public bool ImportFile(string FilePath) {
  27. if (System.IO.Directory.Exists(FilePath) && !System.IO.File.Exists(FilePath)) {
  28. return this.ImportFile(new DirectoryInfo(FilePath));
  29. }
  30. if (System.IO.File.Exists(FilePath)) {
  31. return this.ImportFile(new FileInfo(FilePath));
  32. }
  33. return false;
  34. }
  35. /// <summary>
  36. /// Imports a directory
  37. /// </summary>
  38. /// <param name="nfo">The directory info</param>
  39. /// <param name="filePattern">The file pattern</param>
  40. /// <returns>Returns true if atleast one file was imported</returns>
  41. public bool ImportFile(DirectoryInfo nfo, string filePattern) {
  42. bool bRes1 = ImportFile(nfo.GetFiles(filePattern));
  43. //bool bRes2 = ImportFile(nfo.GetDirectories());
  44. return bRes1;// || bRes2;
  45. }
  46. /// <summary>
  47. /// Imports a directory
  48. /// </summary>
  49. /// <param name="nfo">The directory info</param>
  50. /// <param name="filePattern">The file pattern</param>
  51. /// <param name="fileSearchOption">Search options for deep directory searching</param>
  52. /// <returns>Returns true if atleast one file was imported</returns>
  53. public bool ImportFile(DirectoryInfo nfo, string filePattern, SearchOption fileSearchOption) {
  54. bool bRes1 = ImportFile(nfo.GetFiles(filePattern, fileSearchOption));
  55. //bool bRes2 = ImportFile(nfo.GetDirectories(""));
  56. return bRes1;// || bRes2;
  57. }
  58. /// <summary>
  59. /// Imports a directory
  60. /// </summary>
  61. /// <param name="nfo">The directory info</param>
  62. /// <returns>Returns true if atleast one file was imported</returns>
  63. public bool ImportFile(DirectoryInfo nfo) {
  64. bool bRes1 = ImportFile(nfo.GetFiles());
  65. //bool bRes2 = ImportFile(nfo.GetDirectories());
  66. return bRes1;// || bRes2;
  67. }
  68. /// <summary>
  69. /// Imports a n array of directories
  70. /// </summary>
  71. /// <param name="nfo">The directory infos</param>
  72. /// <param name="filePattern">The file pattern</param>
  73. /// <returns>Returns true if atleast one file was imported</returns>
  74. public bool ImportFile(DirectoryInfo[] nfo, string filePattern) {
  75. int c = 0;
  76. foreach (DirectoryInfo fi in nfo)
  77. if (this.ImportFile(fi, filePattern))
  78. c++;
  79. return c > 0;
  80. }
  81. /// <summary>
  82. /// Imports a n array of directories
  83. /// </summary>
  84. /// <param name="nfo">The directory infos</param>
  85. /// <param name="filePattern">The file pattern</param>
  86. /// <param name="fileSearchOption">Search options for deep directory searching</param>
  87. /// <returns>Returns true if atleast one file was imported</returns>
  88. public bool ImportFile(DirectoryInfo[] nfo, string filePattern, SearchOption fileSearchOption) {
  89. int c = 0;
  90. foreach (DirectoryInfo fi in nfo)
  91. if (this.ImportFile(fi, filePattern, fileSearchOption))
  92. c++;
  93. return c > 0;
  94. }
  95. /// <summary>
  96. /// Imports a n array of directories
  97. /// </summary>
  98. /// <param name="nfo">The directory infos</param>
  99. /// <returns>Returns true if atleast one file was imported</returns>
  100. public bool ImportFile(DirectoryInfo[] nfo) {
  101. int c = 0;
  102. foreach (DirectoryInfo fi in nfo)
  103. if (this.ImportFile(fi))
  104. c++;
  105. return c > 0;
  106. }
  107. /// <summary>
  108. /// Imports an array of file infos
  109. /// </summary>
  110. /// <param name="nfo">Array of file infos</param>
  111. /// <returns>Returns true if atleast one file was imported</returns>
  112. public bool ImportFile(FileInfo[] nfo) {
  113. int c = 0;
  114. foreach (FileInfo fi in nfo)
  115. if (this.ImportFile(fi))
  116. c++;
  117. return c > 0;
  118. }
  119. /// <summary>
  120. /// Imports a file info
  121. /// </summary>
  122. /// <param name="nfo">The file info to import</param>
  123. /// <returns>Returns true if the file was imported successfully</returns>
  124. public bool ImportFile(FileInfo nfo) {
  125. if (nfo.Exists) {
  126. System.Diagnostics.Debug.WriteLine("Import '" + nfo.Name + "'");
  127. FileStream fs = nfo.OpenRead();
  128. byte[] readed = new byte[this._maxContainerSize];
  129. int StackId = this.CreateStack(nfo.Name);
  130. while (fs.Position < fs.Length - this._maxContainerSize) {
  131. fs.Read(readed, 0, this._maxContainerSize);
  132. this.Write(StackId, readed);
  133. System.Diagnostics.Debug.WriteLine(
  134. StackId.ToString().PadRight(4) + " | " +
  135. readed[0].ToString().PadRight(3) + " | " +
  136. readed[1].ToString().PadRight(3) + " | " +
  137. readed[2].ToString().PadRight(3) + " | " +
  138. readed[3].ToString().PadRight(3)
  139. );
  140. }
  141. if (fs.Position != fs.Length) {
  142. byte[] readedFin = new byte[fs.Length - fs.Position];
  143. fs.Read(readedFin, 0, (int)(fs.Length - fs.Position));
  144. this.Write(StackId, readedFin);
  145. }
  146. this.CloseStack(StackId);
  147. fs.Close();
  148. return true;
  149. }
  150. return false;
  151. }
  152. }
  153. }