コード例 #1
0
        private void addFile(RARFileInfo rarEntry)
        {
            string path = rarEntry.FileName;

            if (path.EndsWith("\\")) // backslash
            {
                path = path.Substring(0, path.Length - 1);
            }
            string[] pathParts      = path.Split('\\');
            IFolder  searchInFolder = this;

            for (int i = 0; i < pathParts.Length; i++)
            {
                if (i != pathParts.Length - 1)
                {
                    searchInFolder = findOrCreateFolder(pathParts[i], searchInFolder, rarEntry);
                }
                else   // ostatnia nazwa to nazwa pliku
                {
                    FileInDatabase file = new FileInDatabase(searchInFolder);
                    if (rarEntry.FileAttributes > 0)
                    {
                        file.Attributes = (FileAttributes)rarEntry.FileAttributes;
                    }
                    file.Crc          = (uint)rarEntry.FileCRC;
                    file.CreationTime = rarEntry.FileTime;
                    file.Name         = pathParts[i];
                    file.Length       = rarEntry.UnpackedSize;
                    file.Extension    = Path.GetExtension(file.Name);
                    searchInFolder.AddToFiles(file);
                }
            }
        }
コード例 #2
0
 internal void CopyAdditionalInfo(FolderInDatabase folderToReplace)
 {
     foreach (FolderInDatabase folder in folderImpl.Folders)
     {
         FolderInDatabase subFolderToReplace = folderToReplace.findFolder(folder.Name);
         if (subFolderToReplace != null)
         {
             folder.CopyAdditionalInfo(subFolderToReplace);
         }
     }
     foreach (FileInDatabase file in folderImpl.Files)
     {
         FileInDatabase fileToReplace = folderToReplace.findFile(file.Name);
         if (fileToReplace != null)
         {
             file.Keywords = fileToReplace.Keywords;
             foreach (LogicalFolder logicalFolder in fileToReplace.LogicalFolders)
             {
                 logicalFolder.AddItem(file);
             }
         }
     }
     Keywords = folderToReplace.Keywords;
     foreach (LogicalFolder logicalFolder in folderToReplace.LogicalFolders)
     {
         logicalFolder.AddItem(this);
     }
 }
コード例 #3
0
ファイル: FolderReader.cs プロジェクト: fire-eggs/octopus
        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);
        }
コード例 #4
0
        private void addFile(TarEntry tarEntry)
        {
            string path = tarEntry.Name;

            if (path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }
            string[] pathParts      = path.Split('/');
            IFolder  searchInFolder = this;

            for (int i = 0; i < pathParts.Length; i++)
            {
                if (i != pathParts.Length - 1)
                {
                    searchInFolder = findOrCreateFolder(pathParts[i], searchInFolder, tarEntry);
                }
                else   // ostatnia nazwa to nazwa pliku
                {
                    FileInDatabase file = new FileInDatabase(searchInFolder);
                    file.CreationTime = tarEntry.ModTime;
                    file.Name         = pathParts[i];
                    file.Length       = tarEntry.Size;
                    file.Extension    = Path.GetExtension(file.Name);
                    searchInFolder.AddToFiles(file);
                }
            }
        }
コード例 #5
0
 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);
                 }
             }
         }
     }
 }
コード例 #6
0
ファイル: DlgFileProperties.cs プロジェクト: DevGra/octopus
 public DlgFileProperties(FileInDatabase fileInDatabase)
     : base(fileInDatabase)
 {
     InitializeComponent();
     if (fileInDatabase.Crc != 0)
         llCrc.Text = fileInDatabase.Crc.ToString("X");
     else
         llCrc.Text = "(not computed)";
     llFileSize.Text = fileInDatabase.Length.ToKBAndB();
     llFileDescription.Text = string.IsNullOrEmpty(fileInDatabase.FileDescription) ? "(empty)" : fileInDatabase.FileDescription;
     llFileVersion.Text = string.IsNullOrEmpty(fileInDatabase.FileVersion) ? "(empty)" : fileInDatabase.FileVersion;
     pbIcon.Image = Win32.GetFileIcon(fileInDatabase.Name, Win32.FileIconSize.Large).ToBitmap();
 }
コード例 #7
0
        private static void insertSimilarToList(FileInDatabase file, List <FileInDatabase> foundFilesNoCrc, List <ItemInDatabase> list, FileComparer noCrcComparer)
        {
            int index;

            do
            {
                index = foundFilesNoCrc.BinarySearch(file, noCrcComparer);
                if (index >= 0)
                {
                    list.Add(foundFilesNoCrc[index]);
                    foundFilesNoCrc.RemoveAt(index);
                }
            }while (index > 0);
        }
コード例 #8
0
ファイル: SQLite.cs プロジェクト: fire-eggs/octopus
        private static FileInDatabase FileFromRow(SQLiteDataReader rdr, out int ownerId)
        {
            /*
             * [ID] INTEGER NOT NULL PRIMARY KEY,
             * [Owner] INTEGER NOT NULL,
             * [Name] TEXT,
             * [Ext] TEXT,
             * [FullName] TEXT,
             * [Attributes] INTEGER, // 5
             * [Length] INTEGER,
             * [CreateT] TEXT,
             * [AccessT] TEXT,
             * [WriteT] TEXT,
             * [Keywords] TEXT, // 10
             * [Desc] TEXT,
             * [Hash]
             */
            FileInDatabase afile = new FileInDatabase();

            afile.DbId       = rdr.GetInt32(0);
            ownerId          = rdr.GetInt32(1);
            afile.Name       = rdr.GetString(2);
            afile.Extension  = rdr.GetString(3);
            afile.FullName   = rdr.GetString(4);
            afile.Attributes = (FileAttributes)rdr.GetInt64(5);
            afile.Length     = rdr.GetInt64(6);

            afile.CreationTime   = new DateTime(rdr.GetInt64(7));
            afile.LastAccessTime = new DateTime(rdr.GetInt64(8));
            afile.LastWriteTime  = new DateTime(rdr.GetInt64(9));

            afile.Keywords = rdr.GetString(10);
            object tmp2 = rdr[11];

            if (tmp2 is DBNull)
            {
                // TODO KBR file inside a compressed file
            }
            else
            {
                afile.Description = (string)tmp2; //rdr.GetString(11);
            }
            string tmp = rdr.GetString(12);       // SQLite doesn't support unsigned

            afile.Hash = UInt64.Parse(tmp);
            return(afile);
        }
コード例 #9
0
        private void addFile(ZipEntry zipEntry)
        {
            string path = zipEntry.Name;

            if (path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }
            string[] pathParts      = path.Split('/');
            IFolder  searchInFolder = this;

            for (int i = 0; i < pathParts.Length; i++)
            {
                if (i != pathParts.Length - 1)
                {
                    searchInFolder = findOrCreateFolder(pathParts[i], searchInFolder, zipEntry);
                }
                else   // ostatnia nazwa to nazwa pliku
                {
                    FileInDatabase file = new FileInDatabase(searchInFolder);
                    file.Description = zipEntry.Comment;
                    if (zipEntry.HasCrc)
                    {
                        file.Crc = (uint)zipEntry.Crc;
                    }
                    file.CreationTime = zipEntry.DateTime;
                    //if (zipEntry.ExternalFileAttributes < 1)
                    //    file.Attributes = FileAttributes.Normal;
                    //else
                    if (zipEntry.ExternalFileAttributes > 0)
                    {
                        file.Attributes = (FileAttributes)zipEntry.ExternalFileAttributes;
                    }

                    file.Name      = pathParts[i];
                    file.Length    = zipEntry.Size;
                    file.Extension = Path.GetExtension(file.Name);
                    searchInFolder.AddToFiles(file);
                }
            }
        }
コード例 #10
0
ファイル: FolderInDatabase.cs プロジェクト: fire-eggs/octopus
 public static void CopyFolderInfo(FolderImpl folderImpl, FolderInDatabase folderToReplace)
 {
     // TODO KBR duplicated in CompressedFile but problems with class structure
     foreach (FolderInDatabase folder in folderImpl.Folders)
     {
         FolderInDatabase subFolderToReplace = folderToReplace.findFolder(folder.Name);
         if (subFolderToReplace != null)
         {
             folder.CopyAdditionalInfo(subFolderToReplace);
         }
     }
     foreach (FileInDatabase file in folderImpl.Files)
     {
         FileInDatabase fileToReplace = folderToReplace.findFile(file.Name);
         if (fileToReplace != null)
         {
             file.Keywords = fileToReplace.Keywords;
             foreach (LogicalFolder logicalFolder in fileToReplace.LogicalFolders)
             {
                 logicalFolder.AddItem(file);
             }
         }
     }
 }
コード例 #11
0
 void IFolder.AddToFiles(FileInDatabase file)
 {
     folderImpl.AddToFiles(file);
 }
コード例 #12
0
 public void AddToFiles(FileInDatabase file)
 {
     files.Add(file);
 }
コード例 #13
0
 void IFolder.RemoveFromFiles(FileInDatabase file)
 {
     folderImpl.RemoveFromFiles(file);
 }
コード例 #14
0
        private void search(SearchEventArgs e, List <ItemInDatabase> list)
        {
            Cursor oldCursor = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                // usuwanie podtekstów ".*", gdy przed tekstem nie ma œrednika lub pocz¹tku tekstu, a za tekstem jest œrednik lub koniec tekstu
                int i = 0;
                while ((i = e.FileMask.IndexOf(".*", i, StringComparison.Ordinal)) > -1)
                {
                    // i > -1
                    if ((i > 0) && (e.FileMask[i - 1] != ';') && ((i == e.FileMask.Length - 2) || (e.FileMask[i + 2] == ';')))
                    {
                        e.FileMask = e.FileMask.Substring(0, i) + e.FileMask.Substring(i + 2);
                    }
                }

                Regex fileMaskRegex = new Regex(e.FileMask.ToRegex(e.TreatFileMaskAsWildcard), RegexOptions.Compiled | RegexOptions.IgnoreCase);

                KeywordMatcher keywordMatcher = new KeywordMatcher(e.Keywords, e.AllKeywordsNeeded, e.CaseSensitiveKeywords, e.TreatKeywordsAsWildcard);

                list.Clear();

                if (e.OnlyDuplicates)
                {
                    List <FileInDatabase> foundFilesCrc   = new List <FileInDatabase>();
                    List <FileInDatabase> foundFilesNoCrc = new List <FileInDatabase>();

                    foreach (DiscInDatabase disc in e.SearchInVolumes)
                    {
                        disc.InsertFilesToList(fileMaskRegex, e.DateFrom, e.DateTo, e.SizeFrom, e.SizeTo, keywordMatcher, foundFilesCrc, foundFilesNoCrc);
                    }

                    foundFilesCrc.Sort(new FileComparer(true));
                    FileComparer noCrcComparer = new FileComparer(false);
                    foundFilesNoCrc.Sort(noCrcComparer);
                    FileInDatabase lastFile = null; ulong lastCrc = 0;
                    foreach (FileInDatabase file in foundFilesCrc)
                    {
                        if (file.Hash != 0)
                        {
                            if (lastCrc != file.Hash)
                            {
                                lastCrc  = file.Hash;
                                lastFile = file;
                            }
                            else
                            {
                                if (lastFile != null)
                                { // lastFile dodajemy tylko raz
                                    insertSimilarToList(lastFile, foundFilesNoCrc, list, noCrcComparer);
                                    list.Add(lastFile);
                                    lastFile = null;
                                }
                                list.Add(file);
                                insertSimilarToList(file, foundFilesNoCrc, list, noCrcComparer);
                            }
                        }
                    }
                    lastFile = null; string lastKey = null;
                    foreach (FileInDatabase file in foundFilesNoCrc)
                    {
                        if (lastKey != file.NameLengthKey)
                        {
                            lastKey  = file.NameLengthKey;
                            lastFile = file;
                        }
                        else
                        {
                            if (lastFile != null)
                            { // lastFile dodajemy tylko raz
                                list.Add(lastFile);
                                lastFile = null;
                            }
                            list.Add(file);
                        }
                    }
                }
                else
                {
                    foreach (DiscInDatabase disc in e.SearchInVolumes)
                    {
                        disc.InsertFilesToList(fileMaskRegex, e.DateFrom, e.DateTo, e.SizeFrom, e.SizeTo, keywordMatcher, list /*, lvSearchResults*/);
                    }
                }
            }
            finally
            {
                Cursor.Current = oldCursor;
            }
        }
コード例 #15
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
            }
        }
コード例 #16
0
 void IFolder.AddToFiles(FileInDatabase file)
 {
     folderImpl.AddToFiles(file);
     file.Parent = this;
 }
コード例 #17
0
 public void RemoveFromFiles(FileInDatabase file)
 {
     files.Remove(file);
 }