mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 11:12:23 +01:00
Reboot v3
This commit is contained in:
@@ -4,53 +4,40 @@ import 'package:archive/archive_io.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:reboot_launcher/src/model/reboot_download.dart';
|
||||
import 'package:reboot_launcher/src/util/os.dart';
|
||||
|
||||
const String rebootDownloadUrl =
|
||||
"https://nightly.link/Milxnor/Project-Reboot/workflows/msbuild/main/Release.zip";
|
||||
"https://nightly.link/Milxnor/Project-Reboot-3.0/workflows/msbuild/main/Release.zip";
|
||||
final File rebootDllFile = File("${assetsDirectory.path}\\dlls\\reboot.dll");
|
||||
|
||||
Future<RebootDownload> downloadRebootDll(String url, int? lastUpdateMs) async {
|
||||
Directory? outputDir;
|
||||
File? tempZip;
|
||||
try {
|
||||
var now = DateTime.now();
|
||||
var oldRebootDll = await loadBinary("reboot.dll", true);
|
||||
var lastUpdate = await _getLastUpdate(lastUpdateMs);
|
||||
var exists = await oldRebootDll.exists();
|
||||
if (lastUpdate != null &&
|
||||
now.difference(lastUpdate).inHours <= 24 &&
|
||||
await oldRebootDll.exists()) {
|
||||
return RebootDownload(lastUpdateMs!);
|
||||
}
|
||||
|
||||
var response = await http.get(Uri.parse(rebootDownloadUrl));
|
||||
var tempZip = await loadBinary("reboot.zip", true);
|
||||
await tempZip.writeAsBytes(response.bodyBytes);
|
||||
|
||||
var outputDir = await safeBinariesDirectory.createTemp("reboot_out");
|
||||
await extractFileToDisk(tempZip.path, outputDir.path);
|
||||
|
||||
var rebootDll = File(outputDir
|
||||
.listSync()
|
||||
.firstWhere((element) => path.extension(element.path) == ".dll")
|
||||
.path);
|
||||
|
||||
if (!exists ||
|
||||
sha1.convert(await oldRebootDll.readAsBytes()) !=
|
||||
sha1.convert(await rebootDll.readAsBytes())) {
|
||||
await oldRebootDll.writeAsBytes(await rebootDll.readAsBytes());
|
||||
}
|
||||
|
||||
return RebootDownload(now.millisecondsSinceEpoch);
|
||||
} catch (error, stackTrace) {
|
||||
return RebootDownload(-1, error, stackTrace);
|
||||
} finally {
|
||||
Future<int> downloadRebootDll(String url, int? lastUpdateMs) async {
|
||||
Directory? outputDir;
|
||||
try {
|
||||
outputDir?.delete(recursive: true);
|
||||
tempZip?.delete();
|
||||
} catch (_) {}
|
||||
}
|
||||
var now = DateTime.now();
|
||||
var lastUpdate = await _getLastUpdate(lastUpdateMs);
|
||||
var exists = await rebootDllFile.exists();
|
||||
if (lastUpdate != null && now.difference(lastUpdate).inHours <= 24 && exists) {
|
||||
return lastUpdateMs!;
|
||||
}
|
||||
|
||||
var response = await http.get(Uri.parse(rebootDownloadUrl));
|
||||
outputDir = await installationDirectory.createTemp("reboot_out");
|
||||
var tempZip = File("${outputDir.path}\\reboot.zip");
|
||||
await tempZip.writeAsBytes(response.bodyBytes);
|
||||
await extractFileToDisk(tempZip.path, outputDir.path);
|
||||
var rebootDll = File(outputDir.listSync().firstWhere((element) => path.extension(element.path) == ".dll").path);
|
||||
if (!exists || sha1.convert(await rebootDllFile.readAsBytes()) != sha1.convert(await rebootDll.readAsBytes())) {
|
||||
await rebootDllFile.writeAsBytes(await rebootDll.readAsBytes());
|
||||
}
|
||||
|
||||
return now.millisecondsSinceEpoch;
|
||||
}catch(message) {
|
||||
throw Exception("Cannot download reboot.zip, invalid zip: $message");
|
||||
}finally{
|
||||
if(outputDir != null) {
|
||||
delete(outputDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<DateTime?> _getLastUpdate(int? lastUpdateMs) async {
|
||||
|
||||
Reference in New Issue
Block a user