private bool notVisibleAfterRenaming(MediaFile mediaFile) { int destinationDirDepth = Filepath.GetSubdirectoryLevel(Helper.ReadProperty(ConfigKeyConstants.LAST_DIRECTORY_KEY), mediaFile.DestinationPath); if (destinationDirDepth == -1) { return(true); } else { int maxDirDepth = Helper.ReadInt(ConfigKeyConstants.MAX_SEARCH_DEPTH_KEY); return(destinationDirDepth > maxDirDepth); } }
/// <summary> /// Sets new title to some files and takes care of storing it properly (last [TitleHistorySize] Titles are stored) /// </summary> /// <param name="files">files to which this title should be set to</param> /// <param name="title">name to be set</param> public void SetNewTitle(List <InfoEntry> files, string title) { string[] LastTitlesOld = Helper.ReadProperties(Config.LastTitles); foreach (InfoEntry ie in files) { if (ie.Showname != title) { ie.Showname = title; } } //check if list of titles contains new title int Index = -1; for (int i = 0; i < LastTitlesOld.Length; i++) { string str = LastTitlesOld[i]; if (str == title) { Index = i; break; } } //if the title is new if (Index == -1) { List <string> LastTitlesNew = new List <string>(); LastTitlesNew.Add(title); foreach (string s in LastTitlesOld) { LastTitlesNew.Add(s); } int size = Helper.ReadInt(Config.TitleHistorySize); Helper.WriteProperties(Config.LastTitles, LastTitlesNew.GetRange(0, Math.Min(LastTitlesNew.Count, size)).ToArray()); } //if the title is in the list already, bring it to the front else { List <string> items = new List <string>(LastTitlesOld); items.RemoveAt(Index); items.Insert(0, title); Helper.WriteProperties(Config.LastTitles, items.ToArray()); } }
/// <summary> /// Sets new episode to some files and takes care of storing it properly (last [TITLE_HISTORY_SIZE_KEY] Titles are stored) /// </summary> /// <param name="someMediaFiles">files to which this episode should be set to</param> /// <param name="newShowname">name to be set</param> public void setNewShowname(List <MediaFile> someMediaFiles, string newShowname) { foreach (MediaFile mediaFile in someMediaFiles) { if (mediaFile.Showname != newShowname) { mediaFile.Showname = newShowname; } } List <string> lastSearchedShownames = new List <string>(Helper.ReadProperties(ConfigKeyConstants.LAST_SEARCHED_SHOWNAMES_KEY)); //check if list of shownames contains new showname int Index = -1; for (int i = 0; i < lastSearchedShownames.Count; i++) { string searchedShowname = lastSearchedShownames[i]; if (searchedShowname == newShowname) { Index = i; break; } } //if the episode is new if (Index == -1) { lastSearchedShownames.Insert(0, newShowname); } //if the episode is in the list already, bring it to the front else { lastSearchedShownames.RemoveAt(Index); lastSearchedShownames.Insert(0, newShowname); } int shownameHistorySize = Helper.ReadInt(ConfigKeyConstants.SHOWNAME_HISTORY_SIZE_KEY); Helper.WriteProperties(ConfigKeyConstants.LAST_SEARCHED_SHOWNAMES_KEY, lastSearchedShownames.GetRange(0, Math.Min(lastSearchedShownames.Count, shownameHistorySize)).ToArray()); }
/// <summary> /// Main Rename function /// </summary> public void Rename(BackgroundWorker worker, DoWorkEventArgs e) { this.worker = worker; this.dwea = e; long TotalBytes = 0; long Bytes = 0; foreach (InfoEntry ie in episodes) { if (ie.ProcessingRequested && ie.Destination != "" && ie.FilePath.Fullfilename.ToLower()[0] != ie.Destination.ToLower()[0]) { FileInfo info = new FileInfo(ie.FilePath.Fullfilename); TotalBytes += info.Length; } } //Go through all files and do stuff for (int i = 0; i < this.episodes.Count; i++) { if (worker.CancellationPending) { e.Cancel = true; Logger.Instance.LogMessage("Renaming Cancelled.", LogLevel.INFO); return; } InfoEntry ie = InfoEntryManager.Instance[i]; if (ie.MarkedForDeletion && ie.ProcessingRequested) { try { File.Delete(ie.FilePath.Fullfilename); episodes.Remove(ie); //Go back so no entry is skipped after removal of current entry i--; continue; } catch (Exception ex) { Logger.Instance.LogMessage("Couldn't delete " + ie.FilePath.Fullfilename + ": " + ex.Message, LogLevel.ERROR); } } //need to set before ie.Rename because it resets some conditions bool copyfile = ie.ProcessingRequested && ie.Destination != "" && ie.FilePath.Fullfilename.ToLower()[0] != ie.Destination.ToLower()[0]; //if there are files which actually need to be copied since they're on a different drive, only count those for the progress bar status since they take much longer if (TotalBytes > 0) { ProgressAtCopyStart = ((double)Bytes / (double)TotalBytes * 100); if (copyfile) { ProgressAtCopyEnd = Math.Min(ProgressAtCopyStart + (long)(((double)new FileInfo(ie.FilePath.Fullfilename).Length) / (double)TotalBytes * 100), 100); } else { ProgressAtCopyEnd = ProgressAtCopyStart; } } else { ProgressAtCopyStart = i; ProgressAtCopyEnd = i; } worker.ReportProgress((int)ProgressAtCopyStart); //if a InfoEntry is moved to a different destination directory that isn't visible in the current basedir, remove it int subdirlevel = Filepath.GetSubdirectoryLevel(Helper.ReadProperty(Config.LastDirectory), ie.Destination); bool remove = subdirlevel > Helper.ReadInt(Config.MaxDepth) || subdirlevel == -1; //this call will also report progress more detailed by calling ReportSingleFileProgress() ie.Rename(worker, e); if (remove) { episodes.Remove(ie); //Go back so no entry is skipped after removal of current entry i--; } //after file is (really) copied, add its size if (copyfile) { Bytes += new FileInfo(ie.FilePath.Fullfilename).Length; } } if (Helper.ReadBool(Config.DeleteEmptyFolders)) { //Delete all empty folders code Helper.DeleteAllEmptyFolders(Helper.ReadProperty(Config.LastDirectory), new List <string>(Helper.ReadProperties(Config.IgnoreFiles)), worker, e); } if (!e.Cancel) { Logger.Instance.LogMessage("Renaming (and possibly moving and deleting) finished!", LogLevel.INFO); } else { Logger.Instance.LogMessage("Renaming Cancelled.", LogLevel.INFO); } }