Example #1
0
 void IFolder.AddToFiles(FileInDatabase file)
 {
     folderImpl.AddToFiles(file);
     file.Parent = this;
 }
Example #2
0
 void IFolder.AddToFiles(FileInDatabase file)
 {
     folderImpl.AddToFiles(file);
 }
Example #3
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
            }
        }