-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from bostrot/feature_networksync
Synchronize instances over local network
- Loading branch information
Showing
19 changed files
with
299 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+49 Bytes
(100%)
build/windows/runner/Release/data/flutter_assets/NOTICES.Z
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:shelf/shelf_io.dart' as io; | ||
import 'package:shelf_static/shelf_static.dart'; | ||
import 'package:wsl2distromanager/components/api.dart'; | ||
import 'helpers.dart'; | ||
|
||
class Sync { | ||
late Function(String, {bool loading}) statusMsg; | ||
late String distroName; | ||
late String distroLocation; | ||
static late HttpServer server; | ||
|
||
Sync(); | ||
|
||
/// Constructor | ||
/// @param {String} distroName | ||
/// @param {Function} statusMsg | ||
Sync.instance(this.distroName, this.statusMsg) { | ||
String? distroLocation = prefs.getString('Path_' + distroName); | ||
if (distroLocation == null) { | ||
statusMsg('Distro not found', loading: false); | ||
return; | ||
} | ||
this.distroLocation = distroLocation.replaceAll('/', '\\'); | ||
} | ||
|
||
/// Check if distro has path in settings | ||
/// @param {String} distroName | ||
bool hasPath(String distroName) { | ||
String? distroLocation = prefs.getString('Path_' + distroName); | ||
if (distroLocation == null) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/// Start the server | ||
void startServer() async { | ||
// Get path for distro filesystem | ||
// Serve filesystem file | ||
var handler = createFileHandler(distroLocation + '\\ext4.vhdx', | ||
contentType: "application/octet-stream"); | ||
// Listen on network | ||
try { | ||
server = await io.serve(handler, '0.0.0.0', 59132); | ||
} catch (e) { | ||
// Do nothing | ||
} | ||
} | ||
|
||
/// Stop the server | ||
void stopServer() { | ||
server.close(); | ||
} | ||
|
||
/// Download from sync IP | ||
void download() async { | ||
// Get path for distro filesystem | ||
String? syncIP = prefs.getString('SyncIP'); | ||
if (syncIP == null) { | ||
statusMsg('Sync IP not set. Please set it in the settings.', | ||
loading: false); | ||
return; | ||
} | ||
statusMsg('Shutting down WSL...', loading: true); | ||
// Shutdown WSL | ||
await WSLApi().shutdown(); | ||
statusMsg('Connecting to IP: "$syncIP"...', loading: true); | ||
Dio().download( | ||
'http://$syncIP:59132/ext4.vhdx', distroLocation + '\\ext4.vhdx', | ||
onReceiveProgress: (received, total) { | ||
String rec = (received / 1024 / 1024).toStringAsFixed(2); | ||
String tot = (total / 1024 / 1024).toStringAsFixed(2); | ||
statusMsg('Downloading $distroName, $rec MB / $tot MB', loading: true); | ||
if (received == total) { | ||
statusMsg('Downloaded $distroName'); | ||
} | ||
}).catchError((e) { | ||
statusMsg('Error downloading $distroName', loading: false); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:wsl2distromanager/components/sync.dart'; | ||
import 'package:wsl2distromanager/dialogs/base_dialog.dart'; | ||
import 'package:fluent_ui/fluent_ui.dart'; | ||
import 'package:wsl2distromanager/components/helpers.dart'; | ||
|
||
/// Sync Dialog | ||
/// @param context: context | ||
/// @param item: distro name | ||
/// @param statusMsg: Function(String, {bool loading}) | ||
syncDialog(context, item, Function(String, {bool loading}) statusMsg) { | ||
dialog( | ||
context: context, | ||
item: item, | ||
statusMsg: statusMsg, | ||
title: 'Sync \'${distroLabel(item)}\' from the server', | ||
body: 'Warning: Syncing will shutdown WSL and override the distro ' | ||
'"$item" completely! There is no way to turn back! A backup is advised.' | ||
'\n\nAre you sure you want to continue?', | ||
submitText: 'Yes, sync (override)', | ||
submitInput: false, | ||
submitStyle: ButtonStyle( | ||
backgroundColor: ButtonState.all(Colors.red), | ||
foregroundColor: ButtonState.all(Colors.white), | ||
), | ||
onSubmit: (inputText) { | ||
Sync sync = Sync.instance(item, statusMsg); | ||
sync.download(); | ||
}); | ||
} |
Oops, something went wrong.