예제 #1
0
        internal long ProcessFile(FolderInDatabase owner, Win32.WIN32_FIND_DATAW findData, string fullpath)
        {
            //var newFile = new FileInDatabase(owner);
            var newFile = ProcessCompressed(owner, fullpath);

            ProcessCommon(newFile, findData, fullpath);

            newFile.IsReadOnly = (findData.dwFileAttributes & FileAttributes.ReadOnly) != 0;

            long highSize = (uint)findData.nFileSizeHigh;

            highSize       = highSize << 32;
            highSize      += (uint)findData.nFileSizeLow;
            newFile.Length = highSize;

            if (Properties.Settings.Default.ComputeCrc &&
                highSize < M250)
            {
                try
                {
                    var    buf   = File.ReadAllBytes(fullpath);
                    var    hash  = _md5.ComputeHash(buf);
                    UInt64 hash2 = BitConverter.ToUInt64(hash, 0);
                    newFile.Hash = hash2;
                }
                catch (Exception)
                {
                    // File might be locked
                }
            }

            ((IFolder)owner).AddToFiles(newFile);
            return(newFile.Length);
        }
예제 #2
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);
                 }
             }
         }
     }
 }
예제 #3
0
        private static IFolder findOrCreateFolder(string folderName, IFolder searchInFolder, ZipEntry zipEntry)
        {
            foreach (IFolder folder in searchInFolder.Folders)
            {
                if ((folder as ItemInDatabase).Name == folderName)
                {
                    return(folder);
                }
            }
            FolderInDatabase newFolder = new FolderInDatabase(searchInFolder);

            newFolder.Description  = zipEntry.Comment;
            newFolder.CreationTime = zipEntry.DateTime;
            newFolder.Name         = folderName;
            if (zipEntry.ExternalFileAttributes > 0)
            {
                newFolder.Attributes = (FileAttributes)zipEntry.ExternalFileAttributes;
            }
            else
            {
                newFolder.Attributes = FileAttributes.Directory;
            }
            searchInFolder.AddToFolders(newFolder);
            return(newFolder);
        }
예제 #4
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);
     }
 }
예제 #5
0
        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);
        }
예제 #6
0
파일: SQLite.cs 프로젝트: fire-eggs/octopus
        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);
            }
        }
예제 #7
0
        internal void ProcessFolder(FolderInDatabase owner, Win32.WIN32_FIND_DATAW findData, string fullpath)
        {
            FolderInDatabase newFolder = new FolderInDatabase(owner);

            ProcessCommon(newFolder, findData, fullpath);
            ((IFolder)owner).AddToFolders(newFolder);

            ReadFromFolder(fullpath, newFolder);
        }
예제 #8
0
 internal void CopyAdditionalInfo(FolderInDatabase folderToReplace)
 {
     CopyFolderInfo(folderImpl, folderToReplace);
     Keywords = folderToReplace.Keywords;
     foreach (LogicalFolder logicalFolder in folderToReplace.LogicalFolders)
     {
         logicalFolder.AddItem(this);
     }
 }
예제 #9
0
        public void ReadFromFolder(string folder, FolderInDatabase owner)
        {
            IntPtr findHandle = INVALID_HANDLE_VALUE;

            try
            {
                Win32.WIN32_FIND_DATAW findData;
                findHandle = Win32.FindFirstFileW(folder + @"\*", out findData);
                if (findHandle == INVALID_HANDLE_VALUE)
                {
                    return;
                }

                do
                {
                    if (findData.cFileName == "." || findData.cFileName == "..")
                    {
                        continue;
                    }

                    string fullpath = Path.Combine(folder, findData.cFileName).ToLower(); // folder + (folder.EndsWith("\\") ? "" : "\\") + findData.cFileName;

                    if (_excludedItems.Contains(fullpath))
                    {
                        continue;
                    }

                    // KBR TODO folder to replace

                    if ((findData.dwFileAttributes & FileAttributes.Directory) != 0)
                    {
                        ProcessFolder(owner, findData, fullpath);
                    }
                    else
                    {
                        long len = ProcessFile(owner, findData, fullpath);
                        _runningFileCount++;
                        _runningFileSize += len;
                        if (_runningFileCount % 5 == 1)
                        {
                            _dlgReadingProgress.SetReadingProgress(_runningFileCount, _runningFileSize, fullpath, "Adding...");
                        }
                    }
                }while (Win32.FindNextFile(findHandle, out findData));
            }
            finally
            {
                if (findHandle != INVALID_HANDLE_VALUE)
                {
                    Win32.FindClose(findHandle);
                }
            }
        }
예제 #10
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();
            }
        }
예제 #11
0
        private static IFolder findOrCreateFolder(string folderName, IFolder searchInFolder, TarEntry tarEntry)
        {
            foreach (IFolder folder in searchInFolder.Folders)
            {
                if ((folder as ItemInDatabase).Name == folderName)
                {
                    return(folder);
                }
            }
            FolderInDatabase newFolder = new FolderInDatabase(searchInFolder);

            // newFolder.Description = tarEntry.Comment;
            newFolder.CreationTime = tarEntry.ModTime;
            newFolder.Name         = folderName;
            newFolder.Attributes   = FileAttributes.Directory; // na sztywno
            searchInFolder.AddToFolders(newFolder);
            return(newFolder);
        }
예제 #12
0
 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);
             }
         }
     }
 }
예제 #13
0
 public CompressedFile(FolderInDatabase parent)
     : base(parent)
 {
     folderImpl = new FolderImpl(this, 2);
 }
예제 #14
0
 public DlgFolderProperties(FolderInDatabase folderInDatabase)
     : base(folderInDatabase)
 {
     InitializeComponent();
     pbIcon.Image = Win32.GetFolderIcon(folderInDatabase.Name, Win32.FileIconSize.Large).ToBitmap();
 }
예제 #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
            }
        }