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; } }
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 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 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); }