Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed an issue where the conflicts dialog didn't append numbers when pasting files #15267

Merged
merged 21 commits into from
May 5, 2024
Merged
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
949f0df
Added file number to copy
ashrafmansuri Apr 27, 2024
93256c0
Check for duplicate file names
ashrafmansuri Apr 28, 2024
cbefb48
Suggested changes
ashrafmansuri Apr 28, 2024
405f4b3
File name increment before extension
ashrafmansuri Apr 30, 2024
a1ef60b
Check for source and destination.
ashrafmansuri May 1, 2024
a0d6421
Merge branch 'main' into fix_numberinsteadcopy
ashrafmansuri May 1, 2024
40d4396
Suggested changes
ashrafmansuri May 1, 2024
fb52c42
Merge branch 'fix_numberinsteadcopy' of https://github.com/ashrafmans…
ashrafmansuri May 1, 2024
1780b24
Reverted test
ashrafmansuri May 1, 2024
48e816a
Merge branch 'fix_numberinsteadcopy' of https://github.com/ashrafmans…
ashrafmansuri May 1, 2024
fbda45c
Merge branch 'main' into fix_numberinsteadcopy
ashrafmansuri May 2, 2024
d6af4d4
Suggested changes
ashrafmansuri May 3, 2024
8fdaa40
Fix file name wrongly appends
ashrafmansuri May 4, 2024
da0ee8f
Reverted other changes
ashrafmansuri May 4, 2024
a603a56
Merge branch 'main' into fix_numberinsteadcopy
ashrafmansuri May 4, 2024
9ede293
suggested changes
ashrafmansuri May 5, 2024
f404834
Merge branch 'fix_numberinsteadcopy' of https://github.com/ashrafmans…
ashrafmansuri May 5, 2024
d51034d
Merge branch 'main' into fix_numberinsteadcopy
ashrafmansuri May 5, 2024
cdedef5
Made GetIncrementalName private and removed an extra line break after…
ashrafmansuri May 5, 2024
3b832d2
Merge branch 'fix_numberinsteadcopy' of https://github.com/ashrafmans…
ashrafmansuri May 5, 2024
affecb4
removed extra spaces
ashrafmansuri May 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/Files.App/Utils/Storage/Operations/FileOperationsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public static Task<(bool, ShellOperationResult)> CopyItemAsync(string[] fileToCo
using ShellFolder shd = new(Path.GetDirectoryName(copyDestination[i]));

// Performa copy operation
ashrafmansuri marked this conversation as resolved.
Show resolved Hide resolved
op.QueueCopyOperation(shi, shd, Path.GetFileName(copyDestination[i]));
op.QueueCopyOperation(shi, shd, GetIncrementalName(overwriteOnCopy, copyDestination[i], fileToCopyPath[i]));
}))
{
shellOperationResult.Items.Add(new ShellOperationItemResult()
Expand Down Expand Up @@ -1018,5 +1018,27 @@ protected override void Dispose(bool disposing)
}
}
}

public static string GetIncrementalName(bool overWriteOnCopy, string? filePathToCheck, string? filePathToCopy)
ashrafmansuri marked this conversation as resolved.
Show resolved Hide resolved
{
if (filePathToCheck == null)
return null;

if ((!Path.Exists(filePathToCheck)) || overWriteOnCopy || filePathToCheck == filePathToCopy)
return Path.GetFileName(filePathToCheck);

int i = 2;
ashrafmansuri marked this conversation as resolved.
Show resolved Hide resolved
string filePath = filePathToCheck;
if (Path.HasExtension(filePathToCheck))
filePath = filePathToCheck.Substring(0, filePathToCheck.LastIndexOf("."));

Func<int, string> genFilePath = x => string.Concat([filePath, " (", x.ToString(), ")", Path.GetExtension(filePathToCheck)]);

while (Path.HasExtension(filePathToCheck) ? File.Exists(genFilePath(i)) : Path.Exists(genFilePath(i)))
{
ashrafmansuri marked this conversation as resolved.
Show resolved Hide resolved
i = i+1;
}
return Path.GetFileName(genFilePath(i));
}
}
}
Loading