Skip to content

Commit

Permalink
Merge branch 'main' into misaka0508/main
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Sep 23, 2024
2 parents 8987f23 + b0138f7 commit 5a33247
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions SubRenamer/Services/RenameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public void UpdateRenameTaskList(IReadOnlyList<MatchItem> matchList, Collection<

public void ExecuteRename(IReadOnlyList<RenameTask> taskList)
{
var backupEnabled = Config.Get().Backup;

// Record files that have been backed up,
// avoid duplicate backups when mapping is one-to-many (video-subtitle)
var filesHadBackup = new Dictionary<string, bool>();

foreach (var task in taskList)
{
if (task.Status == "已修改") continue;
Expand All @@ -68,11 +74,14 @@ public void ExecuteRename(IReadOnlyList<RenameTask> taskList)
// Whether the origin and alter files are in the same folder
// If they are, rename in-place; otherwise, copy the file
var isSameFolder = Path.GetDirectoryName(task.Origin) == Path.GetDirectoryName(task.Alter);

if (isSameFolder)
{
// Backup (only rename in-place)
if (backupEnabled && filesHadBackup.TryAdd(task.Origin, true))
FileHelper.BackupFile(task.Origin);

// Rename in-place (like mv in linux)
if (Config.Get().Backup) FileHelper.BackupFile(task.Origin);
FileHelper.RenameFile(task.Origin, task.Alter);
}
else
Expand Down

0 comments on commit 5a33247

Please sign in to comment.