Ejemplo n.º 1
0
        private int PostOrden(DirectoryDataInfo currentDir, List <FileDataInfo> filesList, ref int count)
        {
            //Push all directories
            var subdirs = Delimon.Win32.IO.Directory.GetDirectories(currentDir.FullName);

            DirectoryDataInfo child = null;
            DirectoryInfo     dinfo = null;
            FileDataInfo      file  = null;

            //Retrieve the amount of files inside currentDir.
            int filesCount = 0;

            try
            {
                #region Algorihtmy

                //All childs in PostOrden
                foreach (var d in subdirs)
                {
                    child = new DirectoryDataInfo
                    {
                        FullName    = d,
                        DestinyPath = Path.Combine(currentDir.DestinyPath, Path.GetFileName(d))
                    };

                    filesCount += PostOrden(child, filesList, ref count);
                }

                //Retrieve all files
                dinfo = new DirectoryInfo(currentDir.FullName);
                var files = dinfo.GetFiles();
                filesCount += files.Length;
                foreach (var f in files)
                {
                    file = new FileDataInfo()
                    {
                        SourceDirectoryLength = this.SourceDirectoryLength,
                        Destiny              = this.Destiny,
                        FullName             = Path.Combine(dinfo.FullName, f.Name),
                        DestinyDirectoryPath = currentDir.DestinyPath,
                        Name           = Path.GetFileName(f.Name),
                        DestinyPath    = Path.Combine(currentDir.DestinyPath, f.Name),
                        Size           = f.Length,
                        FileAttributes = f.Attributes,
                        CreationTime   = f.CreationTime,
                        LastAccessTime = f.LastAccessTime,
                        LastWriteTime  = f.LastWriteTime
                    };

                    filesList.Add(file);

                    count++;//Increase Reference Count
                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(Error.GetErrorLog(ex.Message, "NeathCopyEngine", "DirectoryDataInfo", "PostOrden"));

                var message = Error.GetErrorLogInLine(ex.Message, "NeathCopyEngine", "DirectoryDataInfo", "PostOrden");
                using (var w = new System.IO.StreamWriter(new System.IO.FileStream("Errors Log.txt", System.IO.FileMode.Append, System.IO.FileAccess.Write)))
                {
                    w.WriteLine("-------------------------------");
                    w.WriteLine(System.DateTime.Now);
                    w.WriteLine(message);
                }
            }

            if (filesCount == 0)
            {
                EmptyDirs.Add(currentDir);
            }

            return(filesCount);
        }
Ejemplo n.º 2
0
 static int Compare(FileDataInfo f1, FileDataInfo f2)
 {
     return(f1.Name.CompareTo(f2.Name));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Parse the FileSystemName and retrieve a FileDataInfo or DirectoryDataInfo
        /// with DestinyPath as destPath param.
        /// </summary>
        /// <param name="FileSystemName"></param>
        /// <param name="destPath"></param>
        /// <returns></returns>
        public static DataInfo Parse(string fileSystemName, string destinyPath)
        {
            var resultingDestinyPath = Path.Combine(destinyPath, Path.GetFileName(fileSystemName));

            var di = new Delimon.Win32.IO.DirectoryInfo(fileSystemName);

            //If is directory
            if (Alphaleonis.Win32.Filesystem.Directory.Exists(fileSystemName))
            {
                if (resultingDestinyPath == fileSystemName)
                {
                    resultingDestinyPath += " - Copy";

                    for (int i = 1; DestinyPathsNames.Contains(resultingDestinyPath) ||
                         Directory.Exists(resultingDestinyPath); i++)
                    {
                        resultingDestinyPath += i.ToString();
                    }
                }

                return(new DirectoryDataInfo
                {
                    SourceDirectoryLength = Path.GetDirectoryName(fileSystemName).Length,
                    Destiny = destinyPath,
                    FullName = fileSystemName,
                    DestinyPath = resultingDestinyPath,
                    FileAttributes = di.Attributes
                });
            }
            //if is a file
            else if (Alphaleonis.Win32.Filesystem.File.Exists(fileSystemName))
            {
                if (resultingDestinyPath == fileSystemName)
                {
                    var ext     = System.IO.Path.GetExtension(fileSystemName);
                    var extLess = resultingDestinyPath.Remove(resultingDestinyPath.Length - 4, 4);
                    resultingDestinyPath = string.Format("{0} - Copy{1}", extLess, ext);

                    for (int i = 1; DestinyPathsNames.Contains(resultingDestinyPath) ||
                         File.Exists(resultingDestinyPath); i++)
                    {
                        extLess = resultingDestinyPath.Remove(resultingDestinyPath.Length - 4, 4);
                        resultingDestinyPath = string.Format("{0}_{1}{2}", extLess, i, ext);
                    }
                }

                var finfo = new FileInfo(fileSystemName);

                //Delimon.Win32.IO.File.GetCreationTime(fileSystemName);
                var res = new FileDataInfo
                {
                    SourceDirectoryLength = Path.GetDirectoryName(fileSystemName).Length,
                    Destiny              = destinyPath,
                    FullName             = fileSystemName,
                    Name                 = finfo.Name,
                    DestinyDirectoryPath = destinyPath,
                    DestinyPath          = resultingDestinyPath,
                    Size                 = finfo.Length,
                    FileAttributes       = finfo.Attributes,
                    CreationTime         = finfo.CreationTime,
                    LastAccessTime       = finfo.LastAccessTime,
                    LastWriteTime        = finfo.LastWriteTime
                };

                return(res);
            }

            //This filesystem do not exist
            throw new FileSystemNotExistException(fileSystemName);
        }