Fixed some UI things and nightly

This commit is contained in:
Alessandro Autiero
2022-09-22 21:53:47 +02:00
parent c3a2456e5c
commit 2355b5eecd
20 changed files with 234 additions and 173 deletions

View File

@@ -1,47 +1,47 @@
import 'dart:io';
import 'package:archive/archive_io.dart';
import 'package:get_storage/get_storage.dart';
import 'package:get/get.dart';
import 'package:reboot_launcher/src/util/binary.dart';
import 'package:http/http.dart' as http;
import 'package:crypto/crypto.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:path/path.dart' as path;
const _rebootUrl =
"https://nightly.link/Milxnor/Universal-Walking-Simulator/workflows/msbuild/master/Release.zip";
final GetStorage _storage = GetStorage("update");
Future<DateTime?> _getLastUpdate() async {
int? timeInMillis = _storage.read("last_update");
return timeInMillis != null ? DateTime.fromMillisecondsSinceEpoch(timeInMillis) : null;
Future<DateTime?> _getLastUpdate(int? lastUpdateMs) async {
return lastUpdateMs != null ? DateTime.fromMillisecondsSinceEpoch(lastUpdateMs) : null;
}
Future<File> downloadRebootDll() async {
Future<int> downloadRebootDll(int? lastUpdateMs) async {
var now = DateTime.now();
var oldRebootDll = await loadBinary("reboot.dll", true);
var lastUpdate = await _getLastUpdate();
var lastUpdate = await _getLastUpdate(lastUpdateMs);
var exists = await oldRebootDll.exists();
if(lastUpdate != null && now.difference(lastUpdate).inHours <= 24 && exists){
return oldRebootDll;
if(lastUpdate != null && now.difference(lastUpdate).inHours <= 24 && await oldRebootDll.exists()){
return lastUpdateMs!;
}
var response = await http.get(Uri.parse(_rebootUrl));
var tempZip = File("${Platform.environment["Temp"]}/reboot.zip");
var tempZip = File("${tempDirectory.path}/reboot.zip");
await tempZip.writeAsBytes(response.bodyBytes);
await extractFileToDisk(tempZip.path, safeBinariesDirectory);
var pdb = await loadBinary("Project Reboot.pdb", true);
pdb.delete();
var rebootDll = await loadBinary("Project Reboot.dll", true);
if (!(await rebootDll.exists())) {
var outputDir = await tempDirectory.createTemp("reboot");
await extractFileToDisk(tempZip.path, outputDir.path);
var rebootDll = outputDir.listSync()
.firstWhereOrNull((element) => path.extension(element.path) == ".dll");
if(rebootDll == null){
throw Exception("Missing reboot dll");
}
_storage.write("last_update", now.millisecondsSinceEpoch);
if (exists && sha1.convert(await oldRebootDll.readAsBytes()) == sha1.convert(await rebootDll.readAsBytes())) {
rebootDll.delete();
return oldRebootDll;
if (exists && sha1.convert(await oldRebootDll.readAsBytes()) == sha1.convert(await File(rebootDll.path).readAsBytes())) {
outputDir.delete();
return lastUpdateMs!;
}
await rebootDll.rename(oldRebootDll.path);
return oldRebootDll;
outputDir.delete();
return now.millisecondsSinceEpoch;
}