public override bool SameAs(Item o) { ActionCopyMoveRename cmr = o as ActionCopyMoveRename; return((cmr != null) && (Operation == cmr.Operation) && FileHelper.Same(From, cmr.From) && FileHelper.Same(To, cmr.To)); }
public override bool SameAs(Item o) { return(o is ActionCopyMoveRename cmr && Operation == cmr.Operation && FileHelper.Same(From, cmr.From) && FileHelper.Same(To, cmr.To)); }
public override bool SameAs(Item o) { return((o is ActionCopyMoveRename cmr) && (this.Operation == cmr.Operation) && FileHelper.Same(this.From, cmr.From) && FileHelper.Same(this.To, cmr.To)); }
private void DoCopyRename(TVRenameStats stats) { try { //we use a temp name just in case we are interrupted or some other problem occurs string tempName = TempFor(To); // If both full filenames are the same then we want to move it away and back //This deals with an issue on some systems (XP?) that case insensitive moves did not occur if (IsMoveRename() || FileHelper.Same(From, To)) { // This step could be slow, so report progress CopyMoveResult moveResult = File.Move(From.FullName, tempName, MoveOptions.CopyAllowed | MoveOptions.ReplaceExisting, CopyProgressCallback, null); if (moveResult.ErrorCode != 0) { throw new TheTVDB.TVDBException(moveResult.ErrorMessage); } } else { //we are copying Debug.Assert(Operation == Op.copy); // This step could be slow, so report progress CopyMoveResult copyResult = File.Copy(From.FullName, tempName, CopyOptions.None, true, CopyProgressCallback, null); if (copyResult.ErrorCode != 0) { throw new TheTVDB.TVDBException(copyResult.ErrorMessage); } } // Copying the temp file into the correct name is very quick, so no progress reporting File.Move(tempName, To.FullName, MoveOptions.ReplaceExisting); LOGGER.Info($"{Name} completed: {From.FullName} to {To.FullName } "); Done = true; UpdateStats(stats); } catch (Exception e) { LOGGER.Warn(e, $"Error occurred while {Name}: {From.FullName} to {To.FullName } "); Done = true; Error = true; ErrorText = e.Message; LastError = e; } }
private void OSMoveRename(TVRenameStats stats) { try { if (FileHelper.Same(From, To)) { // XP won't actually do a rename if its only a case difference string tempName = TempFor(To); From.MoveTo(tempName); File.Move(tempName, To.FullName); } else { From.MoveTo(To.FullName); } KeepTimestamps(From, To); Done = true; Debug.Assert((Operation == Op.Move) || (Operation == Op.Rename)); switch (Operation) { case Op.Move: stats.FilesMoved++; break; case Op.Rename: stats.FilesRenamed++; break; case Op.Copy: break; default: throw new ArgumentOutOfRangeException(); } } catch (Exception e) { Done = true; Error = true; ErrorText = e.Message; } }
protected static void ReorganiseToLeaveOriginals([NotNull] ItemList newList) { // go through and change last of each operation on a given source file to a 'Move' // ideally do that move within same filesystem // sort based on source file, and destination drive, putting last if destdrive == sourcedrive newList.Sort(new ActionItemSorter()); // sort puts all the CopyMoveRenames together // then set the last of each source file to be a move for (int i = 0; i < newList.Count; i++) { ActionCopyMoveRename cmr1 = newList[i] as ActionCopyMoveRename; bool ok1 = cmr1 != null; if (!ok1) { continue; } bool last = i == newList.Count - 1; ActionCopyMoveRename cmr2 = !last ? newList[i + 1] as ActionCopyMoveRename : null; bool ok2 = cmr2 != null; if (ok2) { ActionCopyMoveRename a1 = cmr1; ActionCopyMoveRename a2 = cmr2; if (!FileHelper.Same(a1.From, a2.From)) { a1.Operation = ActionCopyMoveRename.Op.move; } } else { // last item, or last copymoverename item in the list ActionCopyMoveRename a1 = cmr1; a1.Operation = ActionCopyMoveRename.Op.move; } } }
private void OSMoveRename(TVRenameStats stats) { try { if (FileHelper.Same(this.From, this.To)) { // XP won't actually do a rename if its only a case difference string tempName = TempFor(this.To); this.From.MoveTo(tempName); File.Move(tempName, this.To.FullName); } else { this.From.MoveTo(this.To.FullName); } KeepTimestamps(this.From, this.To); this.Done = true; System.Diagnostics.Debug.Assert((this.Operation == ActionCopyMoveRename.Op.Move) || (this.Operation == ActionCopyMoveRename.Op.Rename)); if (this.Operation == ActionCopyMoveRename.Op.Move) { stats.FilesMoved++; } else if (this.Operation == ActionCopyMoveRename.Op.Rename) { stats.FilesRenamed++; } } catch (System.Exception e) { this.Done = true; this.Error = true; this.ErrorText = e.Message; } }
public bool SameSource([NotNull] ActionDeleteFile o) => FileHelper.Same(toRemove, o.toRemove);
public override bool SameAs(Item o) { return(o is ActionDeleteFile cmr && FileHelper.Same(toRemove, cmr.toRemove)); }
public override void Check(SetProgressDelegate prog, int startpct, int totPct) { prog.Invoke(startpct); ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int fileCount = 0; foreach (string s in TVSettings.Instance.DownloadFolders) { fileCount += DirCache.CountFiles(s, true); } DirCache dirCache = new DirCache(); foreach (string s in TVSettings.Instance.DownloadFolders) { if (ActionCancel) { return; } dirCache.AddFolder(prog, 0, fileCount, s, true); } int currentItem = 0; int totalN = ActionList.Count; foreach (ItemMissing me in ActionList.MissingItems()) { if (ActionCancel) { return; } prog.Invoke(startpct + ((totPct - startpct) * (++currentItem) / (totalN + 1))); ItemList thisRound = new ItemList(); List <DirCacheEntry> matchedFiles = new List <DirCacheEntry>(); foreach (DirCacheEntry dce in dirCache) { if (!ReviewFile(me, thisRound, dce)) { continue; } matchedFiles.Add(dce); } if (matchedFiles.Count == 1) { if (!OtherActionsMatch(matchedFiles[0], me)) { toRemove.Add(me); newList.AddRange(thisRound); } else { LOGGER.Warn($"Ignoring potential match for {me.Episode.Show.ShowName} S{me.Episode.AppropriateSeasonNumber} E{me.Episode.AppropriateEpNum}: with file {matchedFiles[0]?.TheFile.FullName} as there are multiple actions for that file"); me.AddComment( $"Ignoring potential match with file {matchedFiles[0]?.TheFile.FullName} as there are multiple actions for that file"); } } else if (matchedFiles.Count > 1) { List <DirCacheEntry> bestMatchedFiles = IdentifyBestMatches(matchedFiles); if (bestMatchedFiles.Count == 1) { //We have one file that is better, lets use it toRemove.Add(me); newList.AddRange(thisRound); } else { foreach (DirCacheEntry matchedFile in matchedFiles) { LOGGER.Warn( $"Ignoring potential match for {me.Episode.Show.ShowName} S{me.Episode.AppropriateSeasonNumber} E{me.Episode.AppropriateEpNum}: with file {matchedFile?.TheFile.FullName} as there are multiple files for that action"); me.AddComment( $"Ignoring potential match with file {matchedFile?.TheFile.FullName} as there are multiple files for that action"); } } } } if (TVSettings.Instance.KeepTogether) { KeepTogether(newList); } prog.Invoke(totPct); if (!TVSettings.Instance.LeaveOriginals) { // go through and change last of each operation on a given source file to a 'Move' // ideally do that move within same filesystem // sort based on source file, and destination drive, putting last if destdrive == sourcedrive newList.Sort(new ActionItemSorter()); // sort puts all the CopyMoveRenames together // then set the last of each source file to be a move for (int i = 0; i < newList.Count; i++) { ActionCopyMoveRename cmr1 = newList[i] as ActionCopyMoveRename; bool ok1 = cmr1 != null; if (!ok1) { continue; } bool last = i == (newList.Count - 1); ActionCopyMoveRename cmr2 = !last ? newList[i + 1] as ActionCopyMoveRename : null; bool ok2 = cmr2 != null; if (ok2) { ActionCopyMoveRename a1 = cmr1; ActionCopyMoveRename a2 = cmr2; if (!FileHelper.Same(a1.From, a2.From)) { a1.Operation = ActionCopyMoveRename.Op.move; } } else { // last item, or last copymoverename item in the list ActionCopyMoveRename a1 = cmr1; a1.Operation = ActionCopyMoveRename.Op.move; } } } foreach (Item i in toRemove) { ActionList.Remove(i); } foreach (Item i in newList) { ActionList.Add(i); } }
public override ActionOutcome Go(TVRenameStats stats) { // read NTFS permissions (if any) FileSecurity security = null; try { security = From.GetAccessControl(); } catch { // ignored } try { //we use a temp name just in case we are interrupted or some other problem occurs string tempName = TempFor(To); if (!Directory.Exists(To.Directory.FullName)) { Directory.CreateDirectory(To.Directory.FullName); } // If both full filenames are the same then we want to move it away and back //This deals with an issue on some systems (XP?) that case insensitive moves did not occur if (IsMoveRename() || FileHelper.Same(From, To)) { // This step could be slow, so report progress CopyMoveResult moveResult = File.Move(From.FullName, tempName, MoveOptions.CopyAllowed | MoveOptions.ReplaceExisting, CopyProgressCallback, null); if (moveResult.ErrorCode != 0) { throw new ActionFailedException(moveResult.ErrorMessage); } } else { //we are copying Debug.Assert(Operation == Op.copy); // This step could be slow, so report progress CopyMoveResult copyResult = File.Copy(From.FullName, tempName, CopyOptions.None, true, CopyProgressCallback, null); if (copyResult.ErrorCode != 0) { throw new ActionFailedException(copyResult.ErrorMessage); } } // Copying the temp file into the correct name is very quick, so no progress reporting File.Move(tempName, To.FullName, MoveOptions.ReplaceExisting); LOGGER.Info($"{Name} completed: {From.FullName} to {To.FullName } "); UpdateStats(stats); if (To.IsMovieFile()) { //File is correct name LOGGER.Debug($"Just copied {To.FullName} to the right place. Marking it as 'seen'."); if (Episode != null) { //Record this episode as seen TVSettings.Instance.PreviouslySeenEpisodes.EnsureAdded(SourceEpisode); if (TVSettings.Instance.IgnorePreviouslySeen) { doc.SetDirty(); } } if (Movie != null) { //Record this movie as seen TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(Movie); if (TVSettings.Instance.IgnorePreviouslySeenMovies) { doc.SetDirty(); } } } } catch (Exception e) { LOGGER.Warn(e, $"Error occurred while {Name}: {From.FullName} to {To.FullName } "); return(new ActionOutcome(e)); } // set NTFS permissions try { if (security != null) { To.SetAccessControl(security); } } catch { // ignored } try { if (Operation == Op.move && Tidyup != null && Tidyup.DeleteEmpty) { LOGGER.Info($"Testing {From.Directory.FullName} to see whether it should be tidied up"); DoTidyUp(From.Directory); } } catch (Exception e) { return(new ActionOutcome(e)); } return(ActionOutcome.Success()); }
public bool SameSource(ActionCopyMoveRename o) { return(FileHelper.Same(this.From, o.From)); }
public override bool SameAs(Item o) { return((o is ActionDeleteDirectory cmr) && FileHelper.Same(toRemove, cmr.toRemove)); }
public bool SameSource(ActionCopyMoveRename o) => FileHelper.Same(this.From, o.From);
public override void Check(SetProgressDelegate prog, int startpct, int totPct) { prog.Invoke(0); ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int fileCount = 0; foreach (string s in this.mDoc.SearchFolders) { fileCount += DirCache.CountFiles(s, true); } int c = 0; DirCache dirCache = new DirCache(); foreach (String s in this.mDoc.SearchFolders) { if (this.ActionCancel) { return; } c = dirCache.AddFolder(prog, c, fileCount, s, true); } c = 0; int totalN = this.TheActionList.Count; foreach (Item action1 in this.TheActionList) { if (this.ActionCancel) { return; } prog.Invoke(50 + 50 * (++c) / (totalN + 1)); // second 50% of progress bar if (action1 is ItemMissing) { if (this.FindMissingEp(dirCache, (ItemMissing)(action1), newList, ActionCopyMoveRename.Op.Copy)) { toRemove.Add(action1); } } } if (TVSettings.Instance.KeepTogether) { this.KeepTogether(newList); } prog.Invoke(100); if (!TVSettings.Instance.LeaveOriginals) { // go through and change last of each operation on a given source file to a 'Move' // ideally do that move within same filesystem // sort based on source file, and destination drive, putting last if destdrive == sourcedrive newList.Sort(new ActionItemSorter()); // sort puts all the CopyMoveRenames together // then set the last of each source file to be a move for (int i = 0; i < newList.Count; i++) { ActionCopyMoveRename cmr1 = newList[i] as ActionCopyMoveRename; bool ok1 = cmr1 != null; if (!ok1) { continue; } bool last = i == (newList.Count - 1); ActionCopyMoveRename cmr2 = !last ? newList[i + 1] as ActionCopyMoveRename : null; bool ok2 = cmr2 != null; if (ok2) { ActionCopyMoveRename a1 = cmr1; ActionCopyMoveRename a2 = cmr2; if (!FileHelper.Same(a1.From, a2.From)) { a1.Operation = ActionCopyMoveRename.Op.Move; } } else { // last item, or last copymoverename item in the list ActionCopyMoveRename a1 = cmr1; a1.Operation = ActionCopyMoveRename.Op.Move; } } } foreach (Item i in toRemove) { this.TheActionList.Remove(i); } foreach (Item i in newList) { this.TheActionList.Add(i); } // if (Settings->ExportFOXML) // ExportFOXML(Settings->ExportFOXMLTo); }
public override bool SameAs(Item o) { ActionDeleteFile cmr = o as ActionDeleteFile; return((cmr != null) && FileHelper.Same(this.toRemove, cmr.toRemove)); }
public bool SameSource(ActionDeleteDirectory o) => FileHelper.Same(this.toRemove, o.toRemove);
public override bool Go(ref bool pause, TVRenameStats stats) { // read NTFS permissions (if any) FileSecurity security = null; try { security = From.GetAccessControl(); } catch { // ignored } try { if (FileHelper.Same(this.From, this.To)) { // XP won't actually do a rename if its only a case difference string tempName = TempFor(this.To); //From.MoveTo(tempName); //File.Move(tempName, To.FullName); if (IsMoveRename()) { // This step could be slow, so report progress CopyMoveResult moveResult = Alphaleonis.Win32.Filesystem.File.Move(this.From.FullName, tempName, MoveOptions.CopyAllowed | MoveOptions.ReplaceExisting, CopyProgressCallback, null); if (moveResult.ErrorCode != 0) { throw new Exception(moveResult.ErrorMessage); } } else { //we are copying // This step could be slow, so report progress CopyMoveResult moveResult = Alphaleonis.Win32.Filesystem.File.Copy(this.From.FullName, tempName, CopyOptions.None, true, CopyProgressCallback, null); if (moveResult.ErrorCode != 0) { throw new Exception(moveResult.ErrorMessage); } } // This step very quick, so no progress reporting Alphaleonis.Win32.Filesystem.File.Move(tempName, this.To.FullName, MoveOptions.ReplaceExisting); } else { //From.MoveTo(To.FullName); CopyMoveResult moveResult = Alphaleonis.Win32.Filesystem.File.Move(this.From.FullName, this.To.FullName, MoveOptions.CopyAllowed | MoveOptions.ReplaceExisting, CopyProgressCallback, null); if (moveResult.ErrorCode != 0) { throw new Exception(moveResult.ErrorMessage); } } this.Done = true; switch (Operation) { case Op.Move: stats.FilesMoved++; break; case Op.Rename: stats.FilesRenamed++; break; case Op.Copy: stats.FilesCopied++; break; default: throw new ArgumentOutOfRangeException(); } } catch (System.Exception e) { this.Done = true; this.Error = true; this.ErrorText = e.Message; } // set NTFS permissions try { if (security != null) { To.SetAccessControl(security); } } catch { // ignored } if (Operation == Op.Move && _tidyup != null && _tidyup.DeleteEmpty) { DoTidyup(From.Directory); } return(!Error); }
public override bool SameAs(Item o) { ActionDeleteDirectory cmr = o as ActionDeleteDirectory; return((cmr != null) && FileHelper.Same(toRemove, cmr.toRemove)); }
public override bool Go(ref bool pause, TVRenameStats stats) { // read NTFS permissions (if any) FileSecurity security = null; try { security = this.From.GetAccessControl(); } catch { // ignored } try { //we use a temp name just in case we are interruted or some other problem occurs string tempName = TempFor(this.To); // If both full filenames are the same then we want to move it away and back //This deals with an issue on some systems (XP?) that case insensitive moves did not occur if (IsMoveRename() || FileHelper.Same(this.From, this.To)) { // This step could be slow, so report progress CopyMoveResult moveResult = File.Move(this.From.FullName, tempName, MoveOptions.CopyAllowed | MoveOptions.ReplaceExisting, CopyProgressCallback, null); if (moveResult.ErrorCode != 0) { throw new Exception(moveResult.ErrorMessage); } } else { //we are copying Debug.Assert(this.Operation == Op.Copy); // This step could be slow, so report progress CopyMoveResult copyResult = File.Copy(this.From.FullName, tempName, CopyOptions.None, true, CopyProgressCallback, null); if (copyResult.ErrorCode != 0) { throw new Exception(copyResult.ErrorMessage); } } // Copying the temp file into the correct name is very quick, so no progress reporting File.Move(tempName, this.To.FullName, MoveOptions.ReplaceExisting); logger.Info($"{this.Name} completed: {this.From.FullName} to {this.To.FullName } "); this.Done = true; switch (this.Operation) { case Op.Move: stats.FilesMoved++; break; case Op.Rename: stats.FilesRenamed++; break; case Op.Copy: stats.FilesCopied++; break; default: throw new ArgumentOutOfRangeException(); } } catch (Exception e) { this.Done = true; this.Error = true; this.ErrorText = e.Message; } // set NTFS permissions try { if (security != null) { this.To.SetAccessControl(security); } } catch { // ignored } try { if (this.Operation == Op.Move && this.Tidyup != null && this.Tidyup.DeleteEmpty) { logger.Info($"Testing {this.From.Directory.FullName} to see whether it should be tidied up"); DoTidyup(this.From.Directory); } } catch (Exception e) { this.Done = true; this.Error = true; this.ErrorText = e.Message; } return(!this.Error); }
public bool SameSource([NotNull] ActionCopyMoveRename o) => FileHelper.Same(From, o.From);