public void Delete() { bool file = true; if (MainMenu.Content.Count > 0) { string name = MainMenu.GetCurrentElement().FullName; try { if (ManagerDialogWindows.Confirmation($"Are you sure, you want delete {MainMenu.GetCurrentElement()}?")) { if (MainMenu.GetCurrentElement().ToDirectoryInfo().Exists) { file = false; MainMenu.GetCurrentElement().ToDirectoryInfo().Delete(true); } else { MainMenu.GetCurrentElement().ToFileInfo().Delete(); } MainMenu.ControllPos(); UpdateContent(); ManagerLogger.Log("Delete", name); } } catch (Exception e) { ManagerDialogWindows.ErrorMessage(e.Message); ManagerLogger.Log($"{(file ? "File" : "Directory")}_Delete_Failure", $"{e.Message}; Path - {name}"); } } }
public void Paste() { if (CopyPath == string.Empty) { ManagerDialogWindows.ErrorMessage("Buffer is empty"); } else { if (ContentState == State.Searched || ContentState == State.History) { MoveOut(); } string newPath = Path.Combine(CurrentDirectory.FullName, Path.GetFileName(CopyPath)); try { if (!IsCopy && CurrentDirectory.Root.FullName == Directory.GetDirectoryRoot(CopyPath) && ((!File.Exists(newPath) && !Directory.Exists(newPath)) || (File.Exists(CopyPath) && FileReplace(newPath)))) { Directory.Move(CopyPath, newPath); } else { if (Directory.Exists(CopyPath) && (!Directory.Exists(newPath) || ManagerDialogWindows.Confirmation($"Directory called {Path.GetFileName(CopyPath)} already exists here. Do you want to concatanate folders?"))) { new DirectoryInfo(CopyPath).CopyTo(CurrentDirectory.FullName); } else if (File.Exists(CopyPath) && (!File.Exists(newPath) || FileReplace(newPath))) { File.Copy(CopyPath, newPath); } if (!IsCopy) { if (Directory.Exists(CopyPath)) { Directory.Delete(CopyPath, true); } else { File.Delete(CopyPath); } } } ManagerLogger.Log(IsCopy ? "Copy" : "Move", $"{CopyPath} -> {Directory.GetParent(newPath)}"); UpdateContent(); } catch (Exception e) { ManagerDialogWindows.ErrorMessage(e.Message); ManagerLogger.Log(IsCopy ? "Copy_Failure" : "Move_Failure", $"{e.Message}; Path - {CopyPath} -> {newPath}"); } CopyPath = String.Empty; } }
bool FileReplace(string file) { bool conf = ManagerDialogWindows.Confirmation($"File called {file} already exists. Are you sure, you want delete and replace it?"); if (conf) { try { File.Delete(file); } catch (Exception e) { ManagerDialogWindows.ErrorMessage(e.Message); ManagerLogger.Log("File_Delete_Failure", $"{e.Message}; Path - {file}"); } } return(conf); }