@@ -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 ) ) ;
0 commit comments