| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace System.Fire.Container {
- public partial class ContainerList {
- /// <summary>
- /// Imports an array of file or directory pathes
- /// </summary>
- /// <param name="FilePath">Array of file pathes</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(string[] FilePath) {
- int c = 0;
- foreach (string s in FilePath)
- if (this.ImportFile(s))
- c++;
- return c > 0;
- }
- /// <summary>
- /// Imports a file or a directory
- /// </summary>
- /// <param name="FilePath">The file or directory path</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(string FilePath) {
- if (System.IO.Directory.Exists(FilePath) && !System.IO.File.Exists(FilePath)) {
- return this.ImportFile(new DirectoryInfo(FilePath));
- }
- if (System.IO.File.Exists(FilePath)) {
- return this.ImportFile(new FileInfo(FilePath));
- }
- return false;
- }
- /// <summary>
- /// Imports a directory
- /// </summary>
- /// <param name="nfo">The directory info</param>
- /// <param name="filePattern">The file pattern</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(DirectoryInfo nfo, string filePattern) {
- bool bRes1 = ImportFile(nfo.GetFiles(filePattern));
- //bool bRes2 = ImportFile(nfo.GetDirectories());
- return bRes1;// || bRes2;
- }
- /// <summary>
- /// Imports a directory
- /// </summary>
- /// <param name="nfo">The directory info</param>
- /// <param name="filePattern">The file pattern</param>
- /// <param name="fileSearchOption">Search options for deep directory searching</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(DirectoryInfo nfo, string filePattern, SearchOption fileSearchOption) {
- bool bRes1 = ImportFile(nfo.GetFiles(filePattern, fileSearchOption));
- //bool bRes2 = ImportFile(nfo.GetDirectories(""));
- return bRes1;// || bRes2;
- }
- /// <summary>
- /// Imports a directory
- /// </summary>
- /// <param name="nfo">The directory info</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(DirectoryInfo nfo) {
- bool bRes1 = ImportFile(nfo.GetFiles());
- //bool bRes2 = ImportFile(nfo.GetDirectories());
- return bRes1;// || bRes2;
- }
- /// <summary>
- /// Imports a n array of directories
- /// </summary>
- /// <param name="nfo">The directory infos</param>
- /// <param name="filePattern">The file pattern</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(DirectoryInfo[] nfo, string filePattern) {
- int c = 0;
- foreach (DirectoryInfo fi in nfo)
- if (this.ImportFile(fi, filePattern))
- c++;
- return c > 0;
- }
- /// <summary>
- /// Imports a n array of directories
- /// </summary>
- /// <param name="nfo">The directory infos</param>
- /// <param name="filePattern">The file pattern</param>
- /// <param name="fileSearchOption">Search options for deep directory searching</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(DirectoryInfo[] nfo, string filePattern, SearchOption fileSearchOption) {
- int c = 0;
- foreach (DirectoryInfo fi in nfo)
- if (this.ImportFile(fi, filePattern, fileSearchOption))
- c++;
- return c > 0;
- }
- /// <summary>
- /// Imports a n array of directories
- /// </summary>
- /// <param name="nfo">The directory infos</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(DirectoryInfo[] nfo) {
- int c = 0;
- foreach (DirectoryInfo fi in nfo)
- if (this.ImportFile(fi))
- c++;
- return c > 0;
- }
- /// <summary>
- /// Imports an array of file infos
- /// </summary>
- /// <param name="nfo">Array of file infos</param>
- /// <returns>Returns true if atleast one file was imported</returns>
- public bool ImportFile(FileInfo[] nfo) {
- int c = 0;
- foreach (FileInfo fi in nfo)
- if (this.ImportFile(fi))
- c++;
- return c > 0;
- }
- /// <summary>
- /// Imports a file info
- /// </summary>
- /// <param name="nfo">The file info to import</param>
- /// <returns>Returns true if the file was imported successfully</returns>
- public bool ImportFile(FileInfo nfo) {
- if (nfo.Exists) {
- System.Diagnostics.Debug.WriteLine("Import '" + nfo.Name + "'");
- FileStream fs = nfo.OpenRead();
- byte[] readed = new byte[this._maxContainerSize];
- int StackId = this.CreateStack(nfo.Name);
- while (fs.Position < fs.Length - this._maxContainerSize) {
- fs.Read(readed, 0, this._maxContainerSize);
- this.Write(StackId, readed);
- System.Diagnostics.Debug.WriteLine(
- StackId.ToString().PadRight(4) + " | " +
- readed[0].ToString().PadRight(3) + " | " +
- readed[1].ToString().PadRight(3) + " | " +
- readed[2].ToString().PadRight(3) + " | " +
- readed[3].ToString().PadRight(3)
- );
- }
- if (fs.Position != fs.Length) {
- byte[] readedFin = new byte[fs.Length - fs.Position];
- fs.Read(readedFin, 0, (int)(fs.Length - fs.Position));
- this.Write(StackId, readedFin);
- }
- this.CloseStack(StackId);
- fs.Close();
- return true;
- }
- return false;
- }
- }
- }
|