private void copyAdditionalInfo(CompressedFile compressedFileToReplace) { if (compressedFileToReplace != null) { foreach (FolderInDatabase folder in folderImpl.Folders) { FolderInDatabase folderToReplace = compressedFileToReplace.findFolder(folder.Name); if (folderToReplace != null) { folder.CopyAdditionalInfo(folderToReplace); } } foreach (FileInDatabase file in folderImpl.Files) { FileInDatabase fileToReplace = compressedFileToReplace.findFile(file.Name); if (fileToReplace != null) { file.Keywords = fileToReplace.Keywords; foreach (LogicalFolder logicalFolder in fileToReplace.LogicalFolders) { logicalFolder.AddItem(file); } } } } }
internal FileInDatabase ProcessCompressed(FolderInDatabase owner, string fullpath) { FileInDatabase newFile; if (Properties.Settings.Default.BrowseInsideCompressed && (CompressedFile.IsCompressedFile(fullpath))) { newFile = new CompressedFile(owner); CompressedFile cf = newFile as CompressedFile; try { cf.BrowseFiles(fullpath, null); //fileToReplace as CompressedFile); } catch (Exception ex) { // TODO KBR how to replicate this? //cf.Comments = ex.Message; } ((IFolder)owner).AddToFolders(cf); } else { newFile = new FileInDatabase(owner); } return(newFile); }
private static void ReadFolders(SQLiteConnection conn, IFolder did) { if (_readFoldCmd == null) { _readFoldCmd = new SQLiteCommand(conn); _readFoldCmd.CommandText = "select * from [Folds] WHERE Owner = @own"; } _readFoldCmd.Parameters.Clear(); _readFoldCmd.Parameters.AddWithValue("@own", (did as ItemInDatabase).DbId); using (SQLiteDataReader rdr = _readFoldCmd.ExecuteReader()) { while (rdr.Read()) { /* * [ID] INTEGER NOT NULL PRIMARY KEY, * [Owner] INTEGER NOT NULL, * [Name] TEXT, * [Ext] TEXT, * [FullName] TEXT, * [Attributes] INTEGER, * [CreateT] INTEGER, * [AccessT] INTEGER, * [WriteT] INTEGER */ ItemInDatabase afile; int attrib = rdr.GetInt32(5); long dbid = rdr.GetInt64(0); // Check the magic flag for a compressed file; remove the flag below if ((attrib & COMPRESSED_FLAG) != 0) { afile = new CompressedFile((int)dbid, did); } else { afile = new FolderInDatabase((int)dbid, did); } afile.Name = rdr.GetString(2); afile.Extension = rdr.GetString(3); afile.FullName = rdr.GetString(4); afile.Attributes = (FileAttributes)(attrib & ~COMPRESSED_FLAG); afile.CreationTime = new DateTime(rdr.GetInt64(6)); afile.LastAccessTime = new DateTime(rdr.GetInt64(7)); afile.LastWriteTime = new DateTime(rdr.GetInt64(8)); did.AddToFolders(afile as IFolder); _foldHash.Add((int)dbid, afile); } } foreach (var afold in did.Folders) { ReadFolders(conn, afold); } }
internal void BrowseFiles(string fullName, CompressedFile fileToReplace) { this.FullName = fullName; string ext = Path.GetExtension(fullName.ToLower()); if ((ext == EXT_ZIP) || (ext == EXT_JAR)) { using (ZipFile zipFile = new ZipFile(fullName)) { foreach (ZipEntry zipEntry in zipFile) { if (zipEntry.IsDirectory) { addDirectory(zipEntry); } else if (zipEntry.IsFile) { addFile(zipEntry); } } } } else if ((ext == ".gz") || (ext == ".gzip")) // tar+gzip { using (var f = File.OpenRead(fullName)) using (Stream inStream = new GZipInputStream(f)) { TarArchive tarArchive = TarArchive.CreateInputTarArchive(inStream); tarArchive.ProgressMessageEvent += new ProgressMessageHandler(tarArchive_ProgressMessageEvent); tarArchive.ListContents(); } } else if ((ext == ".bz2") || (ext == ".bzip2")) // tar+bz { using (var f = File.OpenRead(fullName)) using (Stream inStream = new BZip2InputStream(f)) { TarArchive tarArchive = TarArchive.CreateInputTarArchive(inStream); tarArchive.ProgressMessageEvent += new ProgressMessageHandler(tarArchive_ProgressMessageEvent); tarArchive.ListContents(); } } else if (ext == ".tar") { TarArchive tarArchive = TarArchive.CreateInputTarArchive(File.OpenRead(fullName)); tarArchive.ProgressMessageEvent += new ProgressMessageHandler(tarArchive_ProgressMessageEvent); tarArchive.ListContents(); } else if (ext == EXT_RAR) { openRarFile(fullName); } copyAdditionalInfo(fileToReplace); }
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 } }