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