Exemple #1
0
        private List <Renamable> GetSecondaryFiles(DBLocalMedia mainFile)
        {
            List <Renamable> secondaryFiles = new List <Renamable>();

            // grab information about files to be renamed
            DirectoryInfo targetDir = new DirectoryInfo(mainFile.File.DirectoryName);

            string[] fileExtensions = MovingPicturesCore.Settings.Rename_SecondaryFileTypes.Split('|');

            // loop through our possible files and flag any exist for renaming
            foreach (string currFileExt in fileExtensions)
            {
                string   originalNameBase = targetDir + @"\" + Path.GetFileNameWithoutExtension(mainFile.FullPath);
                string   newNameBase      = targetDir + @"\" + GetNewFileName(mainFile);
                FileInfo newFile          = new FileInfo(originalNameBase + currFileExt);

                if (newFile.Exists)
                {
                    RenamableFile newRenamable = new RenamableFile(mainFile.AttachedMovies[0], newFile);
                    newRenamable.NewName = newNameBase + currFileExt;
                    secondaryFiles.Add(newRenamable);
                }
            }

            return(secondaryFiles);
        }
Exemple #2
0
        // update the final filenames based on directory name changes and approval. this
        // is used purely for display purposes. druing the actual rename process, files are
        // renamed first to avoid any directory conflicts and unapproved files are skipped
        public static void UpdateFinalFilenames(this IList <Renamable> list)
        {
            // initialize final names
            foreach (Renamable currItem in list)
            {
                currItem.FinalNewName = currItem.NewName;
            }


            // update all final filenames based on pending directory name changes
            foreach (Renamable currItem in list)
            {
                // check if we have found an approved directory rename
                RenamableDirectory currDir = currItem as RenamableDirectory;
                if (currDir == null)
                {
                    continue;
                }
                if (!currDir.Approved)
                {
                    currItem.FinalNewName = currItem.OriginalName;
                    continue;
                }

                // and if so, replace the directory path in the finalfilename of all files
                foreach (Renamable currSubItem in list)
                {
                    RenamableFile currFile = currSubItem as RenamableFile;
                    if (currFile == null)
                    {
                        continue;
                    }

                    currFile.FinalNewName = currFile.NewName.Replace(currDir.OriginalName, currDir.NewName);
                }
            }

            // reset the final name for any unapproved file rename operations
            foreach (Renamable currItem in list)
            {
                RenamableFile currFile = currItem as RenamableFile;
                if (currFile == null || currFile.Approved)
                {
                    continue;
                }

                // remove the new filename for this movie and add the old one
                int lastDirSeperator = currFile.FinalNewName.LastIndexOf(Path.DirectorySeparatorChar);
                currFile.FinalNewName = currFile.FinalNewName.Remove(lastDirSeperator + 1) + currFile.OriginalFile.Name;
            }
        }
Exemple #3
0
        // Returns a list of files and directories ready to be renamed, based on this movie.
        // To perform a rename on this list call list.RenameApprovedItems();
        public List <Renamable> GetRenameActionList(DBMovieInfo movie)
        {
            List <Renamable> renamableList = new List <Renamable>();

            // if this is a disk or a ripped disk, we dont want to rename any files
            if (movie.LocalMedia[0].ImportPath.IsOpticalDrive ||
                movie.LocalMedia[0].IsBluray ||
                movie.LocalMedia[0].IsDVD ||
                movie.LocalMedia[0].IsHDDVD)
            {
                return(renamableList);
            }

            foreach (DBLocalMedia currFile in movie.LocalMedia)
            {
                string primaryExtension = Path.GetExtension(currFile.FullPath);
                string path             = Path.GetDirectoryName(currFile.FullPath);
                string newFileName      = GetNewFileName(currFile);

                // generate primary renamable file for the current video file
                if (MovingPicturesCore.Settings.RenameFiles)
                {
                    RenamableFile primaryRenamable = new RenamableFile(movie, currFile);
                    primaryRenamable.NewName = path + @"\" + newFileName + primaryExtension;
                    renamableList.Add(primaryRenamable);
                }

                // generate secondary renamable files for subtitles, etc
                if (MovingPicturesCore.Settings.RenameSecondaryFiles)
                {
                    renamableList.AddRange(GetSecondaryFiles(currFile));
                }
            }

            // generate a renamable object for the directory as needed
            if (MovingPicturesCore.Settings.RenameFolders)
            {
                RenamableDirectory renamableDir = GetDirectoryRenamable(movie);
                if (renamableDir != null)
                {
                    renamableList.Add(renamableDir);
                }
            }

            renamableList.UpdateFinalFilenames();
            return(renamableList);
        }
        // Returns a list of files and directories ready to be renamed, based on this movie.
        // To perform a rename on this list call list.RenameApprovedItems();
        public List<Renamable> GetRenameActionList(DBMovieInfo movie)
        {
            List<Renamable> renamableList = new List<Renamable>();

            // if this is a disk or a ripped disk, we dont want to rename any files
            if (movie.LocalMedia[0].ImportPath.IsOpticalDrive ||
                movie.LocalMedia[0].IsBluray ||
                movie.LocalMedia[0].IsDVD ||
                movie.LocalMedia[0].IsHDDVD) {

                return renamableList;
            }

            foreach (DBLocalMedia currFile in movie.LocalMedia) {
                string primaryExtension = Path.GetExtension(currFile.FullPath);
                string path = Path.GetDirectoryName(currFile.FullPath);
                string newFileName = GetNewFileName(currFile);

                // generate primary renamable file for the current video file
                if (MovingPicturesCore.Settings.RenameFiles) {
                    RenamableFile primaryRenamable = new RenamableFile(movie, currFile);
                    primaryRenamable.NewName = path + @"\" + newFileName + primaryExtension;
                    renamableList.Add(primaryRenamable);
                }

                // generate secondary renamable files for subtitles, etc
                if (MovingPicturesCore.Settings.RenameSecondaryFiles) {
                    renamableList.AddRange(GetSecondaryFiles(currFile));
                }
            }

            // generate a renamable object for the directory as needed
            if (MovingPicturesCore.Settings.RenameFolders) {
                RenamableDirectory renamableDir = GetDirectoryRenamable(movie);
                if (renamableDir != null) renamableList.Add(renamableDir);
            }

            renamableList.UpdateFinalFilenames();
            return renamableList;
        }
        private List<Renamable> GetSecondaryFiles(DBLocalMedia mainFile)
        {
            List<Renamable> secondaryFiles = new List<Renamable>();

            // grab information about files to be renamed
            DirectoryInfo targetDir = new DirectoryInfo(mainFile.File.DirectoryName);
            string[] fileExtensions = MovingPicturesCore.Settings.Rename_SecondaryFileTypes.Split('|');

            // loop through our possible files and flag any exist for renaming
            foreach(string currFileExt in fileExtensions) {
                string originalNameBase = targetDir + @"\" + Path.GetFileNameWithoutExtension(mainFile.FullPath);
                string newNameBase = targetDir + @"\" + GetNewFileName(mainFile);
                FileInfo newFile = new FileInfo(originalNameBase + currFileExt);

                if (newFile.Exists) {
                    RenamableFile newRenamable = new RenamableFile(mainFile.AttachedMovies[0], newFile);
                    newRenamable.NewName = newNameBase + currFileExt;
                    secondaryFiles.Add(newRenamable);
                }
            }

            return secondaryFiles;
        }