コード例 #1
0
        private HashSet <FileEntry> GetFilesInSelectedFolderCached()
        {
            try
            {
                string folder = GetSelectedNodeFullRealPath();
                if (folder == null || !Directory.Exists(folder))
                {
                    KryptonMessageBox.Show("Can't reach the folder. Not a valid folder selected.", "Invalid folder...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true);
                    cachedFolder            = "";
                    fileEntriesFolderCached = new HashSet <FileEntry>();
                    return(fileEntriesFolderCached);
                }

                if (cachedFolder != folder) //Need updated cache
                {
                    IEnumerable <FileData> fileDatas         = ImageAndMovieFileExtentionsUtility.GetFilesByEnumerableFast(folder, false);
                    HashSet <FileEntry>    fileEntriesFolder = new HashSet <FileEntry>();
                    foreach (FileData fileData in fileDatas)
                    {
                        if (ImageAndMovieFileExtentionsUtility.IsMediaFormat(fileData))
                        {
                            fileEntriesFolder.Add(new FileEntry(fileData.Path, fileData.LastWriteTime));
                        }
                    }
                    fileEntriesFolderCached = fileEntriesFolder;
                    cachedFolder            = folder;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "");
            }

            return(fileEntriesFolderCached);
        }
コード例 #2
0
        private IEnumerable <FileData> GetFilesInSelectedFolder(string folder, bool recursive = false)
        {
            IEnumerable <FileData> fileDatas = null;

            try
            {
                if (folder == null || !Directory.Exists(folder))
                {
                    KryptonMessageBox.Show("Can't reach the folder. Not a valid folder selected.", "Invalid folder...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true);
                    return(fileDatas);
                }
                fileDatas = ImageAndMovieFileExtentionsUtility.GetFilesByEnumerableFast(folder, recursive);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "");
            }
            return(fileDatas);
        }
コード例 #3
0
        private void CopyFolder_UpdateTreeViewFolderBrowser(TreeViewFolderBrowser folderTreeView, string sourceDirectory, string tagretDirectory, TreeNode targetNode)
        {
            IEnumerable <FileData> allSourceFileDatas = ImageAndMovieFileExtentionsUtility.GetFilesByEnumerableFast(sourceDirectory, true);

            //----- Create directories and sub-directories
            Directory.CreateDirectory(tagretDirectory);
            foreach (string dirPath in Directory.GetDirectories(sourceDirectory, "*", SearchOption.AllDirectories))
            {
                try
                {
                    Directory.CreateDirectory(dirPath.Replace(sourceDirectory, tagretDirectory));
                }
                catch (SystemException ex)
                {
                    Logger.Error(ex, "Error when create directory when copy all files from folder");
                    AddError(
                        dirPath, AddErrorFileSystemRegion, AddErrorFileSystemCreateFolder, dirPath.Replace(sourceDirectory, tagretDirectory), dirPath.Replace(sourceDirectory, tagretDirectory),
                        "Issue: Failed create directory\r\n" +
                        "Directory: " + dirPath + "\r\n" +
                        "Error message: " + ex.Message);
                }
            }
            using (new WaitCursor())
            {
                //Copy all the files & Replaces any files with the same name
                foreach (FileData sourceFileData in allSourceFileDatas)
                {
                    string sourceFilename     = Path.GetFileName(sourceFileData.Path);
                    string targetFullFilename = Path.Combine(tagretDirectory, sourceFilename);
                    try
                    {
                        Logger.Trace("Copy from:" + sourceFileData.Path + " to: " + targetFullFilename);
                        File.Copy(sourceFileData.Path, sourceFileData.Path.Replace(sourceDirectory, tagretDirectory), false);

                        if (targetNode != null)
                        {
                            TreeViewFolderBrowserHandler.RefreshTreeNode(folderTreeView, targetNode);
                        }

                        databaseAndCacheMetadataExiftool.Copy(
                            Path.GetDirectoryName(sourceFileData.Path), Path.GetFileName(sourceFileData.Path),
                            Path.GetDirectoryName(sourceFileData.Path), Path.GetFileName(sourceFileData.Path));
                    }
                    catch (SystemException ex)
                    {
                        DateTime dateTimeLastWriteTime = DateTime.Now;
                        try
                        {
                            dateTimeLastWriteTime = FileHandler.GetLastWriteTime(sourceFileData.Path);
                        }
                        catch { }

                        FileStatus fileStatusSource = FileHandler.GetFileStatus(
                            sourceFileData.Path, checkLockedStatus: true, hasErrorOccured: true, errorMessage: ex.Message);
                        ImageListView_UpdateItemFileStatusInvoke(sourceFileData.Path, fileStatusSource);

                        FileStatus fileStatusTarget = FileHandler.GetFileStatus(
                            targetFullFilename, checkLockedStatus: true);
                        //ImageListView_UpdateItemFileStatusInvoke(targetFullFilename, fileStatusTarget);

                        AddError(
                            Path.GetDirectoryName(sourceFileData.Path), Path.GetFileName(sourceFileData.Path), dateTimeLastWriteTime,
                            AddErrorFileSystemRegion, AddErrorFileSystemCopy, sourceFileData.Path, targetFullFilename,
                            "Issue: Failed copying file.\r\n" +
                            "From File Name:  " + sourceFileData.Path + "\r\n" +
                            "From File Staus: " + fileStatusSource.ToString() + "\r\n" +
                            "To   File Name:  " + targetFullFilename + "\r\n" +
                            "To   File Staus: " + fileStatusTarget.ToString() + "\r\n" +
                            "Error message: " + ex.Message);
                    }
                }
            }

            //------ Update node tree -----
            GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = true;
            TreeViewFolderBrowserHandler.RefreshTreeNode(folderTreeView, targetNode);
            GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = false;
        }