예제 #1
0
 private void btn_Undo_Click(object sender, RoutedEventArgs e)
 {
     if (lView_TargetList.Items.Count > 0)
     {
         List <ItemToRename> UndoList = new List <ItemToRename>();
         foreach (ItemToRename vi in lView_TargetList.Items)
         {
             ItemToRename ftr = new ItemToRename()
             {
                 Path     = vi.Path,
                 Before   = vi.Before,
                 AlterKey = vi.AlterKey,
                 After    = vi.After,
                 Result   = vi.Result
             };
             UndoList.Add(ftr);
         }
         if (UndoList.Any())
         {
             foreach (ItemToRename fileCandidate in UndoList)
             {
                 if (string.IsNullOrEmpty(fileCandidate.After))
                 {
                     fileCandidate.Result = GlobalConst.EMPTY_STRING;
                     continue;
                 }
                 if (Directory.Exists(Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After))
                 {
                     try
                     {
                         Directory.Move(Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After, fileCandidate.Path);
                         fileCandidate.Result = GlobalConst.RESULT_UNDO_OK;
                     }
                     catch (Exception)
                     {
                         fileCandidate.Result = GlobalConst.RESULT_UNDO_FAIL;
                     }
                 }
             }
             for (int i = 0; i < UndoList.Count; i++)
             {
                 int index = Targets.IndexOf(Targets.Where(X => X.Path == UndoList[i].Path).FirstOrDefault());
                 Targets[index].Result = UndoList[i].Result;
             }
         }
         UndoList.Clear();
         lView_TargetList.Items.Refresh();
         btn_Undo.IsEnabled    = false;
         tbx_TitleKeyword.Text = "";
         tbx_AnidbID.Text      = "";
         RichTextBoxHepler.SetText(rtb_GroupMembers, "");
         RichTextBoxHepler.SetText(rtb_Presenter, "");
         MessageBox.Show("Undo Completed!");
     }
 }
예제 #2
0
 private void btn_Preview_Click(object sender, RoutedEventArgs e)
 {
     if (lView_Groups.Items.Count > 0 && lView_TargetList.Items.Count > 0)
     {
         lView_TargetList.ItemsSource = null;
         List <ItemToRename> newFilenameList = new List <ItemToRename>();
         foreach (ItemToRename vi in Targets)
         {
             ItemToRename ftr = new ItemToRename()
             {
                 Path     = vi.Path,
                 AlterKey = vi.AlterKey,
                 Before   = vi.Before
             };
             newFilenameList.Add(ftr);
         }
         if (groups.Any())
         {
             newFilenameList = GroupHandler.ReplaceFolderName(newFilenameList, groups.ToList(), chkbox_PresenterOnly.IsChecked, chkbox_UNC.IsChecked);
             for (int i = 0; i < Targets.Count; i++)
             {
                 int index = Targets.IndexOf(Targets.Where(X => X.Path == newFilenameList[i].Path).FirstOrDefault());
                 if (Targets[index].Before != newFilenameList[i].Before)
                 {
                     Targets[index].After = newFilenameList[i].Before;
                 }
             }
         }
         newFilenameList.Clear();
         lView_TargetList.ItemsSource = Targets;
         lView_TargetList.Items.Refresh();
         tbx_TitleKeyword.Text = "";
         tbx_AnidbID.Text      = "";
         tbx_GroupMembers.Text = "";
         tbx_Presenter.Text    = "";
     }
 }
예제 #3
0
 private void btn_GO_Click(object sender, RoutedEventArgs e)
 {
     btn_Preview_Click(null, null);
     if (lView_Groups.Items.Count > 0 && lView_TargetList.Items.Count > 0)
     {
         lView_TargetList.ItemsSource = null;
         List <ItemToRename> RenameList = new List <ItemToRename>();
         foreach (ItemToRename vi in Targets)
         {
             ItemToRename ftr = new ItemToRename()
             {
                 Path     = vi.Path,
                 Before   = vi.Before,
                 AlterKey = vi.AlterKey,
                 After    = vi.After
             };
             RenameList.Add(ftr);
         }
         if (RenameList.Any())
         {
             foreach (ItemToRename fileCandidate in RenameList)
             {
                 if (Directory.Exists(fileCandidate.Path))
                 {
                     try
                     {
                         if (string.IsNullOrEmpty(fileCandidate.After))
                         {
                             fileCandidate.Result = GlobalConst.EMPTY_STRING;
                             continue;
                         }
                         if (!string.IsNullOrEmpty(Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After))
                         {
                             if (fileCandidate.Path != Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After)
                             {
                                 log.Info(Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After);
                                 try
                                 {
                                     try
                                     {
                                         if (File.Exists(Path.Combine(fileCandidate.Path, Path.GetFileName(fileCandidate.Path) + ".md5")))
                                         {
                                             File.Move(Path.Combine(fileCandidate.Path, Path.GetFileName(fileCandidate.Path) + ".md5"), Path.Combine(fileCandidate.Path, fileCandidate.After + ".md5"));
                                         }
                                     }
                                     catch (Exception) { throw; }
                                     try
                                     {
                                         if (Directory.Exists(Path.Combine(fileCandidate.Path.ToLowerInvariant(), "chi")))
                                         {
                                             foreach (var file in Directory.EnumerateFiles(Path.Combine(fileCandidate.Path.ToLowerInvariant(), "chi")))
                                             {
                                                 File.Move(file, Path.Combine(fileCandidate.Path, Path.GetFileName(file)));
                                             }
                                             Directory.Delete(Path.Combine(fileCandidate.Path.ToLowerInvariant(), "chi"));
                                         }
                                         if (Directory.Exists(Path.Combine(fileCandidate.Path.ToLowerInvariant(), "screenlists")))
                                         {
                                             foreach (var file in Directory.EnumerateFiles(Path.Combine(fileCandidate.Path.ToLowerInvariant(), "screenlists")))
                                             {
                                                 File.Move(file, Path.Combine(fileCandidate.Path, Path.GetFileName(file)));
                                             }
                                             Directory.Delete(Path.Combine(fileCandidate.Path.ToLowerInvariant(), "screenlists"));
                                         }
                                     }
                                     catch (Exception) { throw; }
                                     Directory.Move(fileCandidate.Path, Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After);
                                     fileCandidate.Result = GlobalConst.RESULT_RENAME_OK;
                                 }
                                 catch (Exception ex)
                                 {
                                     try
                                     {
                                         FileSystem.MoveDirectory(fileCandidate.Path, Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After, false /* Overwrite */);
                                         fileCandidate.Result = GlobalConst.RESULT_FOLDER_MERGED;
                                     }
                                     catch (Exception)
                                     {
                                         throw ex;
                                     }
                                 }
                             }
                             else
                             {
                                 fileCandidate.Result = GlobalConst.RESULT_NO_RENAME;
                             }
                         }
                         else
                         {
                             fileCandidate.Result = GlobalConst.RESULT_INVALID_NEW_FOLDERNAME;
                         }
                     }
                     catch (Exception ex)
                     {
                         log.Error(ex.ToString());
                         fileCandidate.Result = GlobalConst.RESULT_RENAME_FAIL;
                     }
                 }
                 else if (File.Exists(fileCandidate.Path))
                 {
                     try
                     {
                         if (string.IsNullOrEmpty(fileCandidate.After))
                         {
                             fileCandidate.Result = GlobalConst.EMPTY_STRING;
                             continue;
                         }
                         string newFilepath = Path.Combine(Path.GetDirectoryName(fileCandidate.Path), fileCandidate.After);
                         if (!string.IsNullOrEmpty(newFilepath))
                         {
                             if (fileCandidate.Path != newFilepath)
                             {
                                 log.Info(newFilepath);
                                 try
                                 {
                                     File.Move(fileCandidate.Path, newFilepath);
                                     fileCandidate.Result = GlobalConst.RESULT_RENAME_OK;
                                 }
                                 catch (Exception)
                                 {
                                     throw;
                                 }
                             }
                             else
                             {
                                 fileCandidate.Result = GlobalConst.RESULT_NO_RENAME;
                             }
                         }
                         else
                         {
                             fileCandidate.Result = GlobalConst.RESULT_INVALID_NEW_FOLDERNAME;
                         }
                     }
                     catch (Exception ex)
                     {
                         log.Error(ex.ToString());
                         fileCandidate.Result = GlobalConst.RESULT_RENAME_FAIL;
                     }
                 }
             }
         }
         for (int i = 0; i < RenameList.Count; i++)
         {
             int index = Targets.IndexOf(Targets.Where(X => X.Path == RenameList[i].Path).FirstOrDefault());
             Targets[index].Result = RenameList[i].Result;
         }
         RenameList.Clear();
         lView_TargetList.ItemsSource = Targets;
         lView_TargetList.Items.Refresh();
         btn_Undo.IsEnabled    = true;
         tbx_TitleKeyword.Text = "";
         tbx_AnidbID.Text      = "";
         tbx_GroupMembers.Text = "";
         tbx_Presenter.Text    = "";
         MessageBox.Show("Rename Completed!");
     }
 }
예제 #4
0
 private void btn_GO_Click(object sender, RoutedEventArgs e)
 {
     btn_Preview_Click(null, null);
     if (lView_Groups.Items.Count > 0 && lView_TargetList.Items.Count > 0)
     {
         lView_TargetList.ItemsSource = null;
         List <ItemToRename> RenameList = new List <ItemToRename>();
         foreach (ItemToRename vi in Targets)
         {
             ItemToRename ftr = new ItemToRename()
             {
                 Path     = vi.Path,
                 Before   = vi.Before,
                 AlterKey = vi.AlterKey,
                 After    = vi.After
             };
             RenameList.Add(ftr);
         }
         if (RenameList.Any())
         {
             foreach (ItemToRename fileCandidate in RenameList)
             {
                 if (Directory.Exists(fileCandidate.Path))
                 {
                     try
                     {
                         if (string.IsNullOrEmpty(fileCandidate.After))
                         {
                             fileCandidate.Result = GlobalConst.EMPTY_STRING;
                             continue;
                         }
                         if (!string.IsNullOrEmpty(Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After))
                         {
                             if (fileCandidate.Path != Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After)
                             {
                                 log.Info(Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After);
                                 Directory.Move(fileCandidate.Path, Directory.GetParent(fileCandidate.Path).FullName + "\\" + fileCandidate.After);
                                 fileCandidate.Result = GlobalConst.RESULT_RENAME_OK;
                             }
                             else
                             {
                                 fileCandidate.Result = GlobalConst.RESULT_NO_RENAME;
                             }
                         }
                         else
                         {
                             fileCandidate.Result = GlobalConst.RESULT_INVALID_NEW_FOLDERNAME;
                         }
                     }
                     catch (Exception ex)
                     {
                         log.Error(ex.ToString());
                         fileCandidate.Result = GlobalConst.RESULT_RENAME_FAIL;
                     }
                 }
             }
         }
         for (int i = 0; i < RenameList.Count; i++)
         {
             int index = Targets.IndexOf(Targets.Where(X => X.Path == RenameList[i].Path).FirstOrDefault());
             Targets[index].Result = RenameList[i].Result;
         }
         RenameList.Clear();
         lView_TargetList.ItemsSource = Targets;
         lView_TargetList.Items.Refresh();
         btn_Undo.IsEnabled    = true;
         tbx_TitleKeyword.Text = "";
         tbx_AnidbID.Text      = "";
         RichTextBoxHepler.SetText(rtb_GroupMembers, "");
         RichTextBoxHepler.SetText(rtb_Presenter, "");
         MessageBox.Show("Rename Completed!");
     }
 }