Skip to content

Commit d6739b9

Browse files
authored
Merge pull request LykosAI#1188 from RTHilton/batch-move
Batch move
2 parents abadd65 + bf4c8f3 commit d6739b9

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,70 @@ public async Task ImportFilesAsync(IEnumerable<string> files, DirectoryPath dest
841841
.FirstOrDefault(x => x.Path == destinationFolder.FullPath);
842842
}
843843

844+
public async Task MoveBetweenFolders(List<CheckpointFileViewModel>? sourceFiles, DirectoryPath destinationFolder)
845+
{
846+
if (sourceFiles != null && sourceFiles.Count() > 0)
847+
{
848+
var sourceDirectory = Path.GetDirectoryName(sourceFiles[0].CheckpointFile.GetFullPath(settingsManager.ModelsDirectory));
849+
foreach (CheckpointFileViewModel sourceFile in sourceFiles)
850+
{
851+
if (
852+
destinationFolder.FullPath == settingsManager.ModelsDirectory
853+
|| (sourceDirectory != null && sourceDirectory == destinationFolder.FullPath)
854+
)
855+
{
856+
notificationService.Show(
857+
"Invalid Folder",
858+
"Please select a different folder to import the files into.",
859+
NotificationType.Error
860+
);
861+
return;
862+
}
863+
864+
try
865+
{
866+
var sourcePath = new FilePath(sourceFile.CheckpointFile.GetFullPath(settingsManager.ModelsDirectory));
867+
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(sourcePath);
868+
var sourceCmInfoPath = Path.Combine(sourcePath.Directory!, $"{fileNameWithoutExt}.cm-info.json");
869+
var sourcePreviewPath = Path.Combine(sourcePath.Directory!, $"{fileNameWithoutExt}.preview.jpeg");
870+
var destinationFilePath = Path.Combine(destinationFolder, sourcePath.Name);
871+
var destinationCmInfoPath = Path.Combine(destinationFolder, $"{fileNameWithoutExt}.cm-info.json");
872+
var destinationPreviewPath = Path.Combine(destinationFolder, $"{fileNameWithoutExt}.preview.jpeg");
873+
874+
// Move files
875+
if (File.Exists(sourcePath))
876+
await FileTransfers.MoveFileAsync(sourcePath, destinationFilePath);
877+
878+
if (File.Exists(sourceCmInfoPath))
879+
await FileTransfers.MoveFileAsync(sourceCmInfoPath, destinationCmInfoPath);
880+
881+
if (File.Exists(sourcePreviewPath))
882+
await FileTransfers.MoveFileAsync(sourcePreviewPath, destinationPreviewPath);
883+
884+
notificationService.Show(
885+
"Model moved successfully",
886+
$"Moved '{sourcePath.Name}' to '{Path.GetFileName(destinationFolder)}'"
887+
);
888+
}
889+
catch (FileTransferExistsException)
890+
{
891+
notificationService.Show(
892+
"Failed to move file",
893+
"Destination file exists",
894+
NotificationType.Error
895+
);
896+
}
897+
}
898+
899+
SelectedCategory = Categories
900+
.SelectMany(c => c.Flatten())
901+
.FirstOrDefault(x => x.Path == sourceDirectory);
902+
903+
await modelIndexService.RefreshIndex();
904+
DelayedClearProgress(TimeSpan.FromSeconds(1.5));
905+
}
906+
}
907+
844908
public async Task MoveBetweenFolders(LocalModelFile sourceFile, DirectoryPath destinationFolder)
845909
{
846910
var sourceDirectory = Path.GetDirectoryName(sourceFile.GetFullPath(settingsManager.ModelsDirectory));

StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,7 @@ private async void OnDrop(object? sender, DragEventArgs e)
204204
{
205205
allSelectedCheckpoints.Add(vm);
206206
}
207-
208-
foreach (var checkpoint in allSelectedCheckpoints)
209-
{
210-
await checkpointsVm.MoveBetweenFolders(checkpoint.CheckpointFile, category.Path);
211-
}
207+
await checkpointsVm.MoveBetweenFolders(allSelectedCheckpoints, category.Path);
212208
}
213209
else
214210
{

0 commit comments

Comments
 (0)