Ejemplo n.º 1
0
        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}");
                }
            }
        }
Ejemplo n.º 2
0
        public void SetPath(string newPath)
        {
            DirectoryInfo prevDir = CurrentDirectory;

            try
            {
                if (Path.IsPathRooted(newPath))
                {
                    CurrentDirectory = new DirectoryInfo(newPath);
                    UpdateContent();
                    ManagerLogger.Log("Set_Path", $"{prevDir.FullName} -> {newPath}");
                }
                else
                {
                    throw new Exception("Incorrect path");
                }
            }
            catch (Exception e)
            {
                ManagerDialogWindows.ErrorMessage(e.Message);
                ManagerLogger.Log("Set_Path_Failure", $"{e.Message}; Path - {newPath}");
                CurrentDirectory = prevDir;
            }
            ContentState = State.Default;
            MainMenu.NullPos();
        }
Ejemplo n.º 3
0
 public void CreateFile(string file)
 {
     if (file != String.Empty)
     {
         if (ContentState == State.Searched || ContentState == State.History)
         {
             MoveOut();
         }
         file = Path.Combine(CurrentDirectory.FullName, file);
         if (!File.Exists(file) || FileReplace(file))
         {
             try
             {
                 using (File.Create(file)) { }
                 UpdateContent();
                 ManagerLogger.Log("Create_File", file);
             }
             catch (Exception e)
             {
                 ManagerDialogWindows.ErrorMessage(e.Message);
                 ManagerLogger.Log("File_Create_Failure", $"{e.Message}; Path - {file}");
             }
         }
     }
 }
Ejemplo n.º 4
0
 public void CreateDirectory(string dir)
 {
     if (dir != String.Empty)
     {
         if (ContentState == State.Searched || ContentState == State.History)
         {
             MoveOut();
         }
         dir = Path.Combine(CurrentDirectory.FullName, dir);
         if (Directory.Exists(dir))
         {
             ManagerDialogWindows.ErrorMessage($"Directory called {dir} already exists");
             ManagerLogger.Log("Create_Directory_Failure", $"Directory called {dir} already exists; Path - {dir}");
         }
         else
         {
             try
             {
                 Directory.CreateDirectory(dir);
                 UpdateContent();
                 ManagerLogger.Log("Create_Directory", dir);
             }
             catch (Exception e)
             {
                 ManagerDialogWindows.Message(e.Message);
                 ManagerLogger.Log("Create_Directory_Failure", $"{e.Message}; Path - {dir}");
             }
         }
     }
 }
Ejemplo n.º 5
0
 public void Rename(string newName)
 {
     try
     {
         if (MainMenu.Content.Count > 0 && newName != String.Empty)
         {
             if (MainMenu.GetCurrentElement().ToDirectoryInfo().Exists)
             {
                 newName = Path.Combine(MainMenu.GetCurrentElement().ToDirectoryInfo().Parent.FullName, newName);
             }
             else
             {
                 newName = Path.Combine(MainMenu.GetCurrentElement().ToFileInfo().DirectoryName, newName);
             }
             if ((!Directory.Exists(newName)) && (!File.Exists(newName) || FileReplace(newName)))
             {
                 MainMenu.GetCurrentElement().ToDirectoryInfo().MoveTo(newName);
             }
             UpdateContent();
             ManagerLogger.Log("Rename", $"{MainMenu.GetCurrentElement()} -> {newName}");
         }
     }
     catch (Exception e)
     {
         ManagerDialogWindows.ErrorMessage(e.Message);
         ManagerLogger.Log("Rename_Failure", $"{e.Message}; Path - {MainMenu.GetCurrentElement()} -> {newName}");
     }
 }
Ejemplo n.º 6
0
 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;
     }
 }
Ejemplo n.º 7
0
 public void History()
 {
     MainMenu.Content = ManagerLogger.History().Inverse();
     if (MainMenu.Content.Count == 0)
     {
         ManagerDialogWindows.ErrorMessage("History is empty");
         UpdateContent();
     }
     else
     {
         ContentState = State.History;
     }
     MainMenu.NullPos();
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 public void Help(string helpFileName)
 {
     if (!File.Exists(helpFileName))
     {
         ManagerDialogWindows.ErrorMessage($"File {helpFileName} doesn't exist");
     }
     else
     if (FileOpeningPriorities().ContainsKey(Path.GetExtension(helpFileName)))
     {
         System.Diagnostics.Process.Start(FileOpeningPriorities()[Path.GetExtension(helpFileName)], helpFileName);
     }
     else
     {
         System.Diagnostics.Process.Start(helpFileName);
     }
 }
Ejemplo n.º 10
0
        public void MoveOut()
        {
            DirectoryInfo prevDir = CurrentDirectory;

            try
            {
                if (ContentState == State.Default)
                {
                    CurrentDirectory = CurrentDirectory.Parent;
                }
                ContentState = State.Default;
                UpdateContent();
                MainMenu.NullPos();
                ManagerLogger.Log("Move_Out", prevDir.FullName);
            }
            catch
            {
                ManagerDialogWindows.ErrorMessage("There is no way out");
                CurrentDirectory = prevDir;
            }
        }
Ejemplo n.º 11
0
 public void MoveIn(Menu menu)
 {
     try
     {
         if (menu.GetCurrentElement().ToDirectoryInfo().Exists)
         {
             DirectoryInfo prevDir = CurrentDirectory;
             try
             {
                 CurrentDirectory = menu.GetCurrentElement().ToDirectoryInfo();
                 ContentState     = State.Default;
                 UpdateContent();
                 MainMenu.NullPos();
                 ManagerLogger.Log("Move_In", CurrentDirectory.FullName);
             }
             catch (Exception e)
             {
                 CurrentDirectory = prevDir;
                 throw e;
             }
         }
         else
         {
             if (FileOpeningPriorities().ContainsKey(menu.GetCurrentElement().Extension))
             {
                 System.Diagnostics.Process.Start(FileOpeningPriorities()[menu.GetCurrentElement().Extension], menu.GetCurrentElement().FullName);
             }
             else
             {
                 System.Diagnostics.Process.Start(menu.GetCurrentElement().FullName);
             }
             ManagerLogger.Log("Move_In", menu.GetCurrentElement().FullName);
         }
     }
     catch (Exception e)
     {
         ManagerDialogWindows.ErrorMessage(e.Message);
         ManagerLogger.Log("Move_In_Failure", $"{e.Message}; Path - {MainMenu.GetCurrentElement()}");
     }
 }
Ejemplo n.º 12
0
 public void Search(string param)
 {
     if (param != String.Empty)
     {
         if (ContentState == State.Searched || ContentState == State.History)
         {
             MoveOut();
         }
         MainMenu.Content = CurrentDirectory.Search(param);
         Sort(new DirFilesComparer());
         SearchRes = new List <FileSystemInfo>(MainMenu.Content);
         ManagerLogger.Log("Search", CurrentDirectory.FullName);
         if (MainMenu.Content.Count == 0)
         {
             ManagerDialogWindows.ErrorMessage("No results :(");
             UpdateContent();
         }
         else
         {
             ContentState = State.Searched;
         }
         MainMenu.NullPos();
     }
 }