Reboot v3

This commit is contained in:
Alessandro Autiero
2023-05-24 23:19:36 +02:00
parent 760e336bc0
commit eb6381912c
129 changed files with 396379 additions and 1380 deletions

View File

@@ -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 {