Skip to content

Commit

Permalink
Fixed copy bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrot committed Feb 12, 2023
1 parent 9d9750d commit bc1b73f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 16 additions & 3 deletions lib/api/wsl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 9 additions & 4 deletions lib/dialogs/copy_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit bc1b73f

Please # to comment.