app/lib/common/conf/binary_conf.dart

48 lines
1.5 KiB
Dart
Raw Normal View History

2024-03-09 19:42:57 +08:00
import 'dart:io';
import 'package:archive/archive.dart';
2024-04-14 19:52:42 +08:00
import 'package:flutter/foundation.dart';
2024-03-09 19:42:57 +08:00
import 'package:flutter/services.dart';
import 'package:starcitizen_doctor/common/utils/log.dart';
class BinaryModuleConf {
static const _modules = {
"aria2c": "0",
2024-05-05 16:47:42 +08:00
"unp4kc": "1",
2024-03-09 19:42:57 +08:00
};
static Future extractModule(List<String> modules, String workingDir) async {
for (var m in _modules.entries) {
if (!modules.contains(m.key)) continue;
final name = m.key;
final version = m.value;
final dir = "$workingDir\\$name";
final versionFile = File("$dir\\version");
2024-04-14 19:52:42 +08:00
if (kReleaseMode &&
await versionFile.exists() &&
2024-03-09 19:42:57 +08:00
(await versionFile.readAsString()).trim() == version) {
dPrint(
"BinaryModuleConf.extractModule skip $name version == $version");
continue;
}
// write model file
final zipBuffer = await rootBundle.load("assets/binary/$name.zip");
final decoder = ZipDecoder().decodeBytes(zipBuffer.buffer.asUint8List());
for (var value in decoder.files) {
final filename = value.name;
if (value.isFile) {
final data = value.content as List<int>;
final file = File('$dir\\$filename');
await file.create(recursive: true);
await file.writeAsBytes(data);
} else {
await Directory('$dir\\$filename').create(recursive: true);
}
}
// write version file
await versionFile.writeAsString(version);
dPrint("BinaryModuleConf.extractModule $name $dir");
}
}
}