public bool Revert(DBMovieInfo movie) { // attempt to rename the folder if needed try { if (movie.OriginalDirectoryName != String.Empty) { DirectoryInfo originalDir = Utility.GetMovieBaseDirectory(movie.LocalMedia[0].File.Directory); int lastDirSeperator = originalDir.FullName.LastIndexOf(Path.DirectorySeparatorChar); string newDirName = originalDir.FullName.Remove(lastDirSeperator + 1) + movie.OriginalDirectoryName; if (originalDir.FullName != newDirName) { originalDir.MoveTo(newDirName); movie.OriginalDirectoryName = String.Empty; movie.Commit(); } } } catch (Exception e) { logger.ErrorException("Failed to revert renaming of directory: " + movie.LocalMedia[0].File.DirectoryName, e); return(false); } // wait a sec for directory changes to propagate. Thread.Sleep(100); foreach (DBLocalMedia currMedia in movie.LocalMedia) { if (currMedia.OriginalFileName == String.Empty) { continue; } string fileName = Path.GetFileNameWithoutExtension(currMedia.FullPath); string fileExt = Path.GetExtension(currMedia.FullPath); string filePath = currMedia.File.DirectoryName; // attempt to rename the file based on localMediaItem.OriginalFileName. try { File.Move(currMedia.FullPath, filePath + "\\" + currMedia.OriginalFileName + fileExt); // look for additional files with the same name. foreach (FileInfo currSubFile in currMedia.File.Directory.GetFiles(fileName + ".*")) { File.Move(currSubFile.FullName, filePath + "\\" + currMedia.OriginalFileName + currSubFile.Extension); Thread.Sleep(100); } // remove original file name from the DB. currMedia.OriginalFileName = String.Empty; } catch (Exception e) { logger.ErrorException("Failed to revert renaming of file: " + fileName, e); return(false); } } return(true); }
private void fileUpButton_Click(object sender, EventArgs e) { int index = fileList.SelectedIndex; if (index == 0) { return; } // swap the part# with the file above int partA = ((DBLocalMedia)fileList.Items[index]).Part; int partB = ((DBLocalMedia)fileList.Items[index - 1]).Part; ((DBLocalMedia)fileList.Items[index]).Part = partB; ((DBLocalMedia)fileList.Items[index - 1]).Part = partA; movie.LocalMedia.Sort(new DBLocalMediaComparer()); movie.Commit(); updateControls(); fileList.SelectedIndex = index - 1; }