Example #1
0
 public static void DoWork(string fullName, bool lookup)
 {
     SourceFile src = new SourceFile(fullName, lookup);
     NewFile nf = new NewFile();
     nf.LoadInfo(src);
     if (src.Series != null && src.Episode != null && !lookup)
     {
         string strEpisode = (src.Episode.Episode < 10) ? "0" + src.Episode.Episode.ToString() : src.Episode.Episode.ToString();
         string strSeason = src.Episode.Season.ToString();
         if (MessageBox.Show(string.Format("Old name: '{0}'\nNew name: '{1} - {2}{3} - {4}'\nIs this correct?", fullName, src.Series.Name, strSeason, strEpisode, src.Episode.Name), "Found a match!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             FileInfo oldFile = new FileInfo(fullName);
             while (true)
             {
                 Rename rn = new Rename(string.Format(@"{0} - {1}{2} - {3}", src.Series.Name, strSeason, strEpisode, src.Episode.Name));
                 DialogResult res = rn.ShowDialog();
                 if (res == DialogResult.OK)
                 {
                     if (File.Exists(oldFile.DirectoryName + "\\" + rn.NewFile + oldFile.Extension))
                     {
                         if (MessageBox.Show(string.Format("The file: {0} already exists! Try another name.", rn.NewFile), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel)
                             break;
                     }
                     else
                     {
                         string newName = oldFile.DirectoryName + "\\" + rn.NewFile + oldFile.Extension;
                         if (File.Exists(oldFile.FullName))
                         {
                             int count = 0;
                             while (true)
                             {
                                 try
                                 {
                                     oldFile.MoveTo(newName);
                                     break;
                                 }
                                 catch
                                 {
                                     Thread.Sleep(1000);
                                     count++;
                                     if (count == 60)
                                     {
                                         MessageBox.Show(string.Format("File cannot be moved after {0} attempts! Program will now terminate.", count), "File cannot be moved!", MessageBoxButtons.OK);
                                         break;
                                     }
                                 }
                             }
                         }
                         else
                             MessageBox.Show("Original file cannot be found! Program will now terminate.", "File not found!", MessageBoxButtons.OK);
                         return;
                     }
                 }
                 else if (res == DialogResult.Cancel)
                     break;
             }
         }
     }
     nf.ShowDialog();
 }
Example #2
0
 private void MoveFile(string newFile)
 {
     string newName = "";
     FileInfo oldFile = new FileInfo(_src.FullName);
     while (true)
     {
         Rename rn = new Rename(newFile);
         if (rn.ShowDialog() == DialogResult.OK)
         {
             if (File.Exists(oldFile.DirectoryName + "\\" + rn.NewFile + oldFile.Extension))
             {
                 if (MessageBox.Show(string.Format("The file: {0} already exists! Try another name.", rn.NewFile), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel)
                     break;
             }
             else
             {
                 newName = oldFile.DirectoryName + "\\" + rn.NewFile + oldFile.Extension;
                 break;
             }
         }
     }
     if (File.Exists(oldFile.FullName) && newName != "")
     {
         int count = 0;
         while (true)
         {
             try
             {
                 oldFile.MoveTo(newName);
                 break;
             }
             catch
             {
                 Thread.Sleep(1000);
                 count++;
                 if (count == 600)
                     break;
             }
         }
     }
     this.Close();
 }