Skip to content

Commit

Permalink
Update file duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jul 31, 2023
1 parent 35b0dd7 commit 649c921
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/PicView/FileHandling/CopyPaste.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,46 @@ public static void DuplicateFile()
DuplicateFile(Pics[FolderIndex]);
}

public static void DuplicateFile(string filePath)
private static void DuplicateFile(string currentFile)
{
_ = Task.Run(async () =>
{
try
{
int i = 1;
var filename = filePath;
var dir = Path.GetDirectoryName(filename);
var file = Path.GetFileNameWithoutExtension(filename) + "{0}";
var extension = Path.GetExtension(filename);
var newFile = currentFile;
var dir = Path.GetDirectoryName(newFile);
var file = Path.GetFileNameWithoutExtension(newFile) + "{0}";
var extension = Path.GetExtension(newFile);

while (File.Exists(filename))
filename = Path.Combine(dir, string.Format(file, "(" + i++ + ")") + extension);
while (File.Exists(newFile))
newFile = Path.Combine(dir, string.Format(file, "(" + i++ + ")") + extension);

File.Copy(filePath, filename);
var fileInfo = PreLoader.Get(FolderIndex).FileInfo ?? new FileInfo(filePath);

if (UC.GetPicGallery is not null)
File.Copy(currentFile, newFile);
if (Pics.Count < 200)
{
await GalleryFunctions.SortGalleryAsync(fileInfo).ConfigureAwait(false);
await ErrorHandling.ReloadAsync().ConfigureAwait(false);
await LoadPic.LoadPiFromFileAsync(newFile).ConfigureAwait(false);
}
else
{
Pics = await Task.FromResult(FileLists.FileList(fileInfo)).ConfigureAwait(false);
var fileInfo = new FileInfo(newFile);
if (UC.GetPicGallery is not null)
{
await GalleryFunctions.SortGalleryAsync(fileInfo).ConfigureAwait(false);
}
else
{
Pics = await Task.FromResult(FileLists.FileList(fileInfo)).ConfigureAwait(false);
}
FolderIndex = Pics.IndexOf(newFile);
await LoadPic.LoadPicAtIndexAsync(FolderIndex).ConfigureAwait(false);
}
}
catch (Exception exception)
{
#if DEBUG
Trace.WriteLine($"{nameof(DuplicateFile)} {filePath} exception, \n{exception.Message}");
Trace.WriteLine($"{nameof(DuplicateFile)} {currentFile} exception, \n{exception.Message}");
#endif
ShowTooltipMessage(exception.Message);
}
Expand Down

0 comments on commit 649c921

Please sign in to comment.