-
-
Notifications
You must be signed in to change notification settings - Fork 542
Batch move #1188
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
Batch move #1188
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -841,6 +841,70 @@ public async Task ImportFilesAsync(IEnumerable<string> files, DirectoryPath dest | |
| .FirstOrDefault(x => x.Path == destinationFolder.FullPath); | ||
| } | ||
|
|
||
| public async Task MoveBetweenFolders(List<CheckpointFileViewModel>? sourceFiles, DirectoryPath destinationFolder) | ||
| { | ||
| if (sourceFiles != null && sourceFiles.Count() > 0) | ||
| { | ||
| var sourceDirectory = Path.GetDirectoryName(sourceFiles[0].CheckpointFile.GetFullPath(settingsManager.ModelsDirectory)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a null check for the result of var sourceDirectory = sourceFiles[0].CheckpointFile != null ? Path.GetDirectoryName(sourceFiles[0].CheckpointFile.GetFullPath(settingsManager.ModelsDirectory)) : null; |
||
| foreach (CheckpointFileViewModel sourceFile in sourceFiles) | ||
| { | ||
| if ( | ||
| destinationFolder.FullPath == settingsManager.ModelsDirectory | ||
| || (sourceDirectory != null && sourceDirectory == destinationFolder.FullPath) | ||
|
Comment on lines
+851
to
+853
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition checks if the destination folder is the same as the models directory or the source directory. The check Also, it would be good to add a null check for if (
sourceDirectory == null || destinationFolder.FullPath == sourceDirectory
) |
||
| ) | ||
| { | ||
| notificationService.Show( | ||
| "Invalid Folder", | ||
| "Please select a different folder to import the files into.", | ||
| NotificationType.Error | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var sourcePath = new FilePath(sourceFile.CheckpointFile.GetFullPath(settingsManager.ModelsDirectory)); | ||
| var fileNameWithoutExt = Path.GetFileNameWithoutExtension(sourcePath); | ||
| var sourceCmInfoPath = Path.Combine(sourcePath.Directory!, $"{fileNameWithoutExt}.cm-info.json"); | ||
| var sourcePreviewPath = Path.Combine(sourcePath.Directory!, $"{fileNameWithoutExt}.preview.jpeg"); | ||
| var destinationFilePath = Path.Combine(destinationFolder, sourcePath.Name); | ||
| var destinationCmInfoPath = Path.Combine(destinationFolder, $"{fileNameWithoutExt}.cm-info.json"); | ||
| var destinationPreviewPath = Path.Combine(destinationFolder, $"{fileNameWithoutExt}.preview.jpeg"); | ||
|
|
||
| // Move files | ||
| if (File.Exists(sourcePath)) | ||
| await FileTransfers.MoveFileAsync(sourcePath, destinationFilePath); | ||
|
|
||
| if (File.Exists(sourceCmInfoPath)) | ||
| await FileTransfers.MoveFileAsync(sourceCmInfoPath, destinationCmInfoPath); | ||
|
|
||
| if (File.Exists(sourcePreviewPath)) | ||
| await FileTransfers.MoveFileAsync(sourcePreviewPath, destinationPreviewPath); | ||
|
|
||
| notificationService.Show( | ||
| "Model moved successfully", | ||
| $"Moved '{sourcePath.Name}' to '{Path.GetFileName(destinationFolder)}'" | ||
| ); | ||
| } | ||
| catch (FileTransferExistsException) | ||
| { | ||
| notificationService.Show( | ||
| "Failed to move file", | ||
| "Destination file exists", | ||
| NotificationType.Error | ||
| ); | ||
|
Comment on lines
+890
to
+895
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The notification message in the catch block is generic. Consider including the file name in the notification to provide more context to the user about which file failed to move. notificationService.Show(
"Failed to move file",
$"Failed to move '{sourcePath.Name}': Destination file exists",
NotificationType.Error
); |
||
| } | ||
| } | ||
|
|
||
| SelectedCategory = Categories | ||
| .SelectMany(c => c.Flatten()) | ||
| .FirstOrDefault(x => x.Path == sourceDirectory); | ||
|
|
||
| await modelIndexService.RefreshIndex(); | ||
| DelayedClearProgress(TimeSpan.FromSeconds(1.5)); | ||
| } | ||
| } | ||
|
|
||
| public async Task MoveBetweenFolders(LocalModelFile sourceFile, DirectoryPath destinationFolder) | ||
| { | ||
| var sourceDirectory = Path.GetDirectoryName(sourceFile.GetFullPath(settingsManager.ModelsDirectory)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a List you can use something like
if (sourceFiles is { Count: > 0 })instead of the LINQ count, but not a huge deal.