From bc1b73fd58a18ac733f3f7dbdca7c506d228230e Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 12 Feb 2023 12:36:34 +0100 Subject: [PATCH] Fixed copy bug --- lib/api/wsl.dart | 19 ++++++++++++++++--- lib/dialogs/copy_dialog.dart | 13 +++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/api/wsl.dart b/lib/api/wsl.dart index 3680baa..6333128 100644 --- a/lib/api/wsl.dart +++ b/lib/api/wsl.dart @@ -353,10 +353,23 @@ class WSLApi { // Try to create directory mkRootDir(path: location); - // Copy - String importRes = - await import(newName, location + newName, vhdPath, isVhd: true); + // Copy path to new location + File file = File(vhdPath); + if (file.existsSync()) { + file.copySync('$vhdPath.copy.vhdx'); + } else { + return 'File not found'; + } + + String importRes = await import( + newName, location + newName, '$vhdPath.copy.vhdx', + isVhd: true); + // Cleanup, delete file + File file2 = File('$vhdPath.copy.vhdx'); + if (file2.existsSync()) { + file2.deleteSync(); + } return importRes; } diff --git a/lib/dialogs/copy_dialog.dart b/lib/dialogs/copy_dialog.dart index cf4a32c..c73866b 100644 --- a/lib/dialogs/copy_dialog.dart +++ b/lib/dialogs/copy_dialog.dart @@ -29,9 +29,12 @@ copyDialog(context, item, Function(String, {bool loading}) statusMsg) { // Only allow A-Z, a-z, 0-9, and _ in distro names inputText = inputText.replaceAll(RegExp(r'[^a-zA-Z0-9_-]'), ''); String results; + // Check if old distro has path String? oldDistroPath = prefs.getString('Path_$item'); if (oldDistroPath != null && oldDistroPath.isNotEmpty) { + // Stop distro + await api.stop(item); // Copy vhd results = await api.copyVhd('$oldDistroPath\\ext4.vhdx', inputText, location: path); @@ -41,18 +44,20 @@ copyDialog(context, item, Function(String, {bool loading}) statusMsg) { } // Error catching - if (results != ' ') { + if (results.contains('Error')) { statusMsg(results, loading: false); + return; } // Copy settings String? startPath = prefs.getString('StartPath_$item') ?? ''; String? startName = prefs.getString('StartUser_$item') ?? ''; - prefs.setString('DistroName_$item', inputText); + prefs.setString('DistroName_$inputText', inputText); prefs.setString('StartPath_$inputText', startPath); prefs.setString('StartUser_$inputText', startName); // Save distro path - prefs.setString('Path_$inputText', defaultPath + inputText); - statusMsg('donecopyinginstance-text'.i18n([item, inputText]), + prefs.setString('Path_$inputText', '$path\\$inputText'); + statusMsg( + 'donecopyinginstance-text'.i18n([distroLabel(item), inputText]), loading: false); } else { statusMsg('errorentername-text'.i18n(), loading: false);