예제 #1
0
 public Crc32(DlgReadingProgress dlgProgress, long fileCount, long baseFileSize, string itemName) : base()
 {
     this.dlgProgress  = dlgProgress;
     this.baseFileSize = baseFileSize;
     this.itemName     = itemName;
     this.fileCount    = fileCount;
 }
예제 #2
0
        public FolderReader(List <string> excludedItems, DlgReadingProgress dlgReadingProgress, FolderInDatabase folderToReplace)
        {
            _excludedItems      = excludedItems;
            _dlgReadingProgress = dlgReadingProgress;
            _folderToReplace    = folderToReplace;

            _runningFileCount = 0;
            _runningFileSize  = 0;

            if (Properties.Settings.Default.ComputeCrc)
            {
                _md5 = new MD5CryptoServiceProvider();
            }
        }
예제 #3
0
        // TODO KBR move to FolderReader.cs
        internal void ReadFromDrive(string drive, List <string> excludedElements, DlgReadingProgress dlgReadingProgress, DiscInDatabase discToReplace)
        {
            var FR = new FolderReader(excludedElements, dlgReadingProgress, discToReplace);

            FR.ReadFromFolder(drive, this);

            DriveInfo di = new DriveInfo(drive);

            DriveFormat    = di.DriveFormat;
            DriveType      = di.DriveType;
            TotalFreeSpace = di.TotalFreeSpace;
            TotalSize      = di.TotalSize;
            if (!string.IsNullOrEmpty(di.VolumeLabel))
            {
                VolumeLabel = di.VolumeLabel;
            }
            SerialNumber = Win32.GetVolumeSerialNumber(drive);
            ScannedCrc   = Properties.Settings.Default.ComputeCrc;
            ScannedZip   = Properties.Settings.Default.BrowseInsideCompressed;
            FromDrive    = drive;

            // TODO KBR must calculate first and pass to FolderReader. That code must track running total cluster sizes.
            ClusterSize = GetClusterSize(drive);

            if (discToReplace != null)
            {
                if ((Keywords != string.Empty) && (discToReplace.Keywords != string.Empty))
                {
                    Keywords = Keywords + ";";
                }
                Keywords = Keywords + discToReplace.Keywords;
                if ((PhysicalLocation != string.Empty) && (discToReplace.PhysicalLocation != string.Empty))
                {
                    PhysicalLocation = PhysicalLocation + ";";
                }
                PhysicalLocation = PhysicalLocation + discToReplace.PhysicalLocation;
                foreach (LogicalFolder logicalFolder in discToReplace.LogicalFolders)
                {
                    logicalFolder.AddItem(this);
                }
            }
        }
예제 #4
0
        internal void ReadFromDrive(string drive, List <string> elementsToRead, ref long runningFileCount, ref long runningFileSize, bool useSize, DlgReadingProgress dlgReadingProgress, DiscInDatabase discToReplace)
        {
            ReadFromFolder(drive, elementsToRead, ref runningFileCount, ref runningFileSize, useSize, dlgReadingProgress, discToReplace);
            DriveInfo di = new DriveInfo(drive);

            driveFormat        = di.DriveFormat;
            driveType          = di.DriveType;
            totalFreeSpace     = di.TotalFreeSpace;
            totalSize          = di.TotalSize;
            volumeLabel        = di.VolumeLabel;
            serialNumber       = Win32.GetVolumeSerialNumber(drive);
            scannedCrc         = Properties.Settings.Default.ComputeCrc;
            scannedZip         = Properties.Settings.Default.BrowseInsideCompressed;
            scannedFileVersion = Properties.Settings.Default.ReadFileInfo;
            fromDrive          = drive;
            if (discToReplace != null)
            {
                if ((Keywords != string.Empty) && (discToReplace.Keywords != string.Empty))
                {
                    Keywords = Keywords + ";";
                }
                Keywords = Keywords + discToReplace.Keywords;
                if ((physicalLocation != string.Empty) && (discToReplace.physicalLocation != string.Empty))
                {
                    physicalLocation = physicalLocation + ";";
                }
                physicalLocation = physicalLocation + discToReplace.physicalLocation;
                foreach (LogicalFolder logicalFolder in discToReplace.LogicalFolders)
                {
                    logicalFolder.AddItem(this);
                }
            }
        }
예제 #5
0
        internal void ReadFromFolder(string folder, List <string> excludedFolders, ref long runningFileCount, ref long runningFileSize, bool useSize, DlgReadingProgress dlgReadingProgress, FolderInDatabase folderToReplace)
        {
            try {
                System.IO.DirectoryInfo   di         = new System.IO.DirectoryInfo(folder);
                System.IO.DirectoryInfo[] subFolders = di.GetDirectories();
                foreach (System.IO.DirectoryInfo subFolder in subFolders)
                {
                    if (!excludedFolders.Contains(subFolder.FullName.ToLower()))
                    {
                        FolderInDatabase newFolder = new FolderInDatabase(this);
                        newFolder.Name           = subFolder.Name;
                        newFolder.Attributes     = subFolder.Attributes;
                        newFolder.CreationTime   = subFolder.CreationTime;
                        newFolder.Extension      = subFolder.Extension;
                        newFolder.FullName       = subFolder.FullName;
                        newFolder.LastAccessTime = subFolder.LastAccessTime;
                        newFolder.LastWriteTime  = subFolder.LastWriteTime;
                        FolderInDatabase subFolderToReplace;
                        if (folderToReplace != null)
                        {
                            subFolderToReplace = folderToReplace.findFolder(subFolder.Name);
                        }
                        else
                        {
                            subFolderToReplace = null;
                        }
                        newFolder.ReadFromFolder(subFolder.FullName, excludedFolders, ref runningFileCount, ref runningFileSize, useSize, dlgReadingProgress, subFolderToReplace);
                        if (subFolderToReplace != null)
                        {
                            newFolder.Keywords = subFolderToReplace.Keywords;
                            foreach (LogicalFolder logicalFolder in subFolderToReplace.LogicalFolders)
                            {
                                logicalFolder.AddItem(newFolder);
                            }
                        }
                        folderImpl.AddToFolders(newFolder);

                        //FrmMain.dlgProgress.SetReadingProgress(0, "Adding: " + newFolder.FullName);
                    }
                }

                System.IO.FileInfo[] filesInFolder = di.GetFiles();
                foreach (System.IO.FileInfo fileInFolder in filesInFolder)
                {
                    if (!excludedFolders.Contains(fileInFolder.FullName.ToLower()))
                    {
                        FileInDatabase newFile;
                        FileInDatabase fileToReplace;
                        if (folderToReplace != null)
                        {
                            fileToReplace = folderToReplace.findFile(fileInFolder.Name);
                        }
                        else
                        {
                            fileToReplace = null;
                        }
                        if (Properties.Settings.Default.BrowseInsideCompressed && (CompressedFile.IsCompressedFile(fileInFolder.Name)))
                        {
                            CompressedFile compressedFile = new CompressedFile(this);
                            try {
                                compressedFile.BrowseFiles(fileInFolder.FullName, fileToReplace as CompressedFile);
                            }
                            catch (Exception ex) {
                                compressedFile.Comments = ex.Message;
                            }
                            // tu idzie jako katalog
                            folderImpl.AddToFolders(compressedFile);

                            // a teraz jako plik
                            newFile = compressedFile;
                        }
                        else
                        {
                            newFile          = new FileInDatabase(this);
                            newFile.FullName = fileInFolder.FullName;
                        }

                        newFile.Name         = fileInFolder.Name;
                        newFile.Attributes   = fileInFolder.Attributes;
                        newFile.CreationTime = fileInFolder.CreationTime;
                        newFile.Extension    = fileInFolder.Extension;

                        newFile.LastAccessTime = fileInFolder.LastAccessTime;
                        newFile.LastWriteTime  = fileInFolder.LastWriteTime;
                        newFile.IsReadOnly     = fileInFolder.IsReadOnly;
                        newFile.Length         = fileInFolder.Length;
                        if (Properties.Settings.Default.ReadFileInfo)
                        {
                            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileInFolder.FullName);
                            newFile.Comments        = fvi.Comments;
                            newFile.CompanyName     = fvi.CompanyName;
                            newFile.FileVersion     = fvi.FileVersion;
                            newFile.FileDescription = fvi.FileDescription;
                            newFile.LegalCopyright  = fvi.LegalCopyright;
                            newFile.ProductName     = fvi.ProductName;
                        }

                        if (Properties.Settings.Default.ComputeCrc)
                        {
                            Crc32 crc32 = new Crc32(dlgReadingProgress, runningFileCount, runningFileSize, newFile.FullName);
                            try {
                                using (FileStream inputStream = new FileStream(newFile.FullName, FileMode.Open, FileAccess.Read)) {
                                    crc32.ComputeHash(inputStream);
                                    newFile.Crc = crc32.CrcValue;
                                }
                            }
                            catch (IOException) {
                                // eat the exception
                            }
                        }

                        if (fileToReplace != null)
                        {
                            newFile.Keywords = fileToReplace.Keywords;
                            foreach (LogicalFolder logicalFolder in fileToReplace.LogicalFolders)
                            {
                                logicalFolder.AddItem(newFile);
                            }
                        }

                        folderImpl.AddToFiles(newFile);

                        runningFileCount++;
                        runningFileSize += fileInFolder.Length;
                        dlgReadingProgress.SetReadingProgress(runningFileCount, runningFileSize, newFile.FullName, "Adding...");
                    }
                }
            }
            catch (UnauthorizedAccessException) {
                // eat the exception
            }
        }