public void DeleteSelectedFiles(MainForm mainForm, ImageListView imageListView, HashSet <FileEntry> fileEntries, bool deleteFromFileSystemAlso) { try { GlobalData.DoNotTrigger_ImageListView_SelectionChanged = true; ImageListViewHandler.SuspendLayout(imageListView); using (new WaitCursor()) { foreach (FileEntry fileEntry in fileEntries) { try { mainForm.UpdateStatusAction("Deleting the file " + fileEntry.FileFullPath + " and records in database"); if (deleteFromFileSystemAlso) { FileHandler.Delete(fileEntry.FileFullPath, Properties.Settings.Default.MoveToRecycleBin); } this.DeleteFileAndHistory(fileEntry.FileFullPath); imageListView.Items.Remove(ImageListViewHandler.FindItem(imageListView.Items, fileEntry.FileFullPath)); } catch (Exception ex) { KryptonMessageBox.Show("Was not able to delete the file: " + fileEntry.FileFullPath + "\r\n\r\n" + ex.Message, "Deleting file failed", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } } } } catch (Exception ex) { Logger.Error(ex); KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n", "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } finally { ImageListViewHandler.ResumeLayout(imageListView); GlobalData.DoNotTrigger_ImageListView_SelectionChanged = false; } }
private void RenameFile_Thread_UpdateTreeViewFolderBrowser(TreeViewFolderBrowser folderTreeView, ImageListView imageListView, int renameQueueCount, string sourceFullFilename, string targetFullFilename) { if (InvokeRequired) { this.BeginInvoke(new Action <TreeViewFolderBrowser, ImageListView, int, string, string>(RenameFile_Thread_UpdateTreeViewFolderBrowser), folderTreeView, imageListView, renameQueueCount, sourceFullFilename, targetFullFilename); return; } try { GlobalData.DoNotTrigger_ImageListView_SelectionChanged = true; //ImageListViewHandler.SuspendLayout(imageListView1); using (new WaitCursor()) { try { bool directoryCreated = filesCutCopyPasteDrag.MoveFile(sourceFullFilename, targetFullFilename); if (directoryCreated) { GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = true; TreeViewFolderBrowserHandler.RefreshFolderWithName(folderTreeView, targetFullFilename, true); GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = false; } ImageListViewItem foundItem = ImageListViewHandler.FindItem(imageListView.Items, sourceFullFilename); if (foundItem != null) { ImageListViewHandler.ImageListViewRemoveItem(imageListView, foundItem); #region Add new renames back to list lock (keepTrackOfLoadedMetadataLock) { ImageListViewHandler.ImageListViewAddItem(imageListView1, targetFullFilename, ref hasTriggerLoadAllMetadataActions, ref keepTrackOfLoadedMetadata); } #endregion #region Select back all Items renamed foundItem = ImageListViewHandler.FindItem(imageListView.Items, targetFullFilename); if (foundItem != null) { foundItem.Selected = true; } #endregion } } catch (Exception ex) { #region Error Handling DateTime dateTimeLastWriteTime = DateTime.Now; try { dateTimeLastWriteTime = FileHandler.GetLastWriteTime(sourceFullFilename); } catch { } FileStatus fileStatus = FileHandler.GetFileStatus( sourceFullFilename, checkLockedStatus: true, hasErrorOccured: true, errorMessage: ex.Message); ImageListView_UpdateItemFileStatusInvoke(sourceFullFilename, fileStatus); FileStatus fileStatusTarget = FileHandler.GetFileStatus( targetFullFilename, checkLockedStatus: true, hasErrorOccured: true, errorMessage: ex.Message, exiftoolProcessStatus: ExiftoolProcessStatus.DoNotUpdate); ImageListView_UpdateItemFileStatusInvoke(targetFullFilename, fileStatus); AddError( Path.GetDirectoryName(sourceFullFilename), Path.GetFileName(sourceFullFilename), dateTimeLastWriteTime, AddErrorFileSystemRegion, AddErrorFileSystemMove, sourceFullFilename, targetFullFilename, "Issue: Failed moving file.\r\n" + "From File name : " + sourceFullFilename + "\r\n" + "From File staus: " + fileStatus.ToString() + "\r\n" + "To File name : " + targetFullFilename + "\r\n" + "To File staus: " + fileStatusTarget.ToString() + "\r\n" + "Error message: " + ex.Message); Logger.Error(ex, "Error when move file. From: " + sourceFullFilename + " to:" + targetFullFilename); #endregion } } } catch (Exception ex) { Logger.Error(ex); KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n", "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } finally { //ImageListViewHandler.ResumeLayout(imageListView1); GlobalData.DoNotTrigger_ImageListView_SelectionChanged = false; } if (renameQueueCount == 0) { //To avoid selected files becomes added back to read queue, and also exist in rename queue, //that rename item can get removed after rename. With old name in read queue, and this file will then not exist when read ImageListView_SelectionChanged_Action_ImageListView_DataGridView(false); } }
private void MoveFilesNoRename_UpdateTreeViewFolderBrowser(TreeViewFolderBrowser folderTreeView, ImageListView imageListView, StringCollection files, string targetNodeDirectory, TreeNode treeNodeTarget) { if (GlobalData.IsApplicationClosing) { return; } if (InvokeRequired) { this.BeginInvoke(new Action <TreeViewFolderBrowser, ImageListView, StringCollection, string, TreeNode>(MoveFilesNoRename_UpdateTreeViewFolderBrowser), folderTreeView, imageListView, files, targetNodeDirectory, treeNodeTarget); return; } if (GlobalData.IsApplicationClosing) { return; } if (DoNotTrigger_ImageListView_SelectionChanged()) { return; } try { GlobalData.DoNotTrigger_ImageListView_SelectionChanged = true; ImageListViewHandler.SuspendLayout(imageListView1); #region Do the work using (new WaitCursor()) { foreach (string oldPath in files) //Move all files to target directory { string sourceFullFilename = oldPath; string filename = Path.GetFileName(sourceFullFilename); string targetFullFilename = Path.Combine(targetNodeDirectory, filename); try { bool directoryCreated = filesCutCopyPasteDrag.MoveFile(sourceFullFilename, targetFullFilename); //------ Update node tree ----- GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = true; if (treeNodeTarget == null) { string targetFolder = Path.GetDirectoryName(targetFullFilename); TreeViewFolderBrowserHandler.RemoveFolderWithName(folderTreeView, targetFolder); } else { TreeViewFolderBrowserHandler.RefreshTreeNode(folderTreeView, treeNodeTarget); } GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = false; ImageListViewItem foundItem = ImageListViewHandler.FindItem(imageListView.Items, sourceFullFilename); if (foundItem != null) { ImageListViewHandler.ImageListViewRemoveItem(imageListView, foundItem); } } catch (Exception ex) { DateTime dateTimeLastWriteTime = DateTime.Now; try { dateTimeLastWriteTime = FileHandler.GetLastWriteTime(sourceFullFilename); } catch { } FileStatus fileStatus = FileHandler.GetFileStatus( sourceFullFilename, checkLockedStatus: true, hasErrorOccured: true, errorMessage: ex.Message); ImageListView_UpdateItemFileStatusInvoke(sourceFullFilename, fileStatus); FileStatus fileStatusTarget = FileHandler.GetFileStatus( targetFullFilename, checkLockedStatus: true, hasErrorOccured: true, errorMessage: ex.Message, exiftoolProcessStatus: ExiftoolProcessStatus.DoNotUpdate); ImageListView_UpdateItemFileStatusInvoke(targetFullFilename, fileStatus); AddError( Path.GetDirectoryName(sourceFullFilename), Path.GetFileName(sourceFullFilename), dateTimeLastWriteTime, AddErrorFileSystemRegion, AddErrorFileSystemMove, sourceFullFilename, targetFullFilename, "Issue: Failed moving file.\r\n" + "From File name : " + sourceFullFilename + "\r\n" + "From File staus: " + fileStatus.ToString() + "\r\n" + "To File name : " + targetFullFilename + "\r\n" + "To File staus: " + fileStatusTarget.ToString() + "\r\n" + "Error message: " + ex.Message); Logger.Error(ex, "Error when move file."); } } } #endregion } catch (Exception ex) { Logger.Error(ex); KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n", "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } finally { GlobalData.IsPerformingAButtonAction = false; ImageListViewHandler.ResumeLayout(imageListView1); GlobalData.DoNotTrigger_ImageListView_SelectionChanged = false; ImageListView_SelectionChanged_Action_ImageListView_DataGridView(false); } }