Exemplo n.º 1
0
        private void AddFiles(string driveUnitLetter, IsoFolder currentFolder, FileScanResult fileScanResult, IsoVolume iso)
        {
            string[] filePaths;

            try
            {
                filePaths = DirectoryProvider.GetFiles(currentFolder.Path.Replace("/", driveUnitLetter + @":\"), "*.*");
                fileScanResult.ProcessedFolderCount += 1;
            }
            catch (UnauthorizedAccessException)
            {
                fileScanResult.Log.AppendLine(string.Format("ERROR folder-access rights-:'{0}'", currentFolder.Path));
                fileScanResult.FoldersWithErrorCount += 1;
                return;
            }
            catch (Exception)
            {
                fileScanResult.Log.AppendLine(string.Format("ERROR folder-unknown-:'{0}'", currentFolder.Path));
                fileScanResult.FoldersWithErrorCount += 1;
                return;
            }

            foreach (var filePath in filePaths)
            {
                IsoFile isoFile;
                try
                {
                    isoFile             = FileProvider.GetIsoFile(filePath);
                    isoFile.IsoVolumeId = iso.Id;
                }
                catch (UnauthorizedAccessException)
                {
                    fileScanResult.Log.AppendLine(string.Format("ERROR file-access rights-:'{0}'", filePath));
                    fileScanResult.FilesWithErrorCount += 1;
                    continue;
                }
                catch (Exception)
                {
                    fileScanResult.Log.AppendLine(string.Format("ERROR file-unknown-:'{0}'", filePath));
                    fileScanResult.FilesWithErrorCount += 1;
                    continue;
                }

                isoFile.Parent = currentFolder;
                fileScanResult.ProcessedFileCount += 1;
                currentFolder.ChildFiles.Add(isoFile);

                fileScanResult.Log.AppendLine(
                    string.Format(
                        "FILE name:'{0}', extension:'{1}', path:'{2}', dateCreated:{3}, dateModified:{4}, size:{5}",
                        isoFile.Name,
                        isoFile.Extension,
                        filePath,
                        isoFile.Created,
                        isoFile.Modified,
                        GetSizeString(isoFile.Size)
                        ));
            }
        }
Exemplo n.º 2
0
        public IsoFolder ScanFolderForFiles(string driveUnitLetter, FileScanResult fileScanResult, IsoVolume iso)
        {
            string fullDrivePath = driveUnitLetter + ":\\";
            var    currentTime   = DateTime.Now;
            var    rootFolder    = new IsoFolder
            {
                Name        = "/",
                Path        = fullDrivePath.Replace(driveUnitLetter + @":\", "/"),
                Parent      = null,
                IsoVolumeId = iso.Id
            };

            var folders = new List <IsoFolder> {
                rootFolder
            };

            for (int i = 0; i < folders.Count; i++)
            {
                var currentFolder = folders[i];

                AddFiles(driveUnitLetter, currentFolder, fileScanResult, iso);

                AddFolders(driveUnitLetter, currentFolder, folders, iso);
            }

            fileScanResult.TotalTime = DateTime.Now.Subtract(currentTime);
            fileScanResult.Log.AppendLine(
                string.Format(
                    "Scan finished:{0}hs:{1}min:{2}sec:{3}msec, files:{4}, fileErrors:{5}, folders:{6}, folderErrors:{7}",
                    fileScanResult.TotalTime.Hours, fileScanResult.TotalTime.Minutes,
                    fileScanResult.TotalTime.Seconds, fileScanResult.TotalTime.Milliseconds,
                    fileScanResult.ProcessedFileCount, fileScanResult.FilesWithErrorCount,
                    fileScanResult.ProcessedFolderCount, fileScanResult.FoldersWithErrorCount));

            return(rootFolder);
        }