mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-24 02:23:41 +08:00
46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
|
import 'dart:io';
|
||
|
|
||
|
import 'package:archive/archive.dart';
|
||
|
import 'package:flutter/services.dart';
|
||
|
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||
|
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||
|
|
||
|
class BinaryModuleConf {
|
||
|
static const _modules = {
|
||
|
"aria2c": "0",
|
||
|
};
|
||
|
|
||
|
static Future extractModel() async {
|
||
|
final workingDir = "${AppConf.applicationSupportDir}\\modules";
|
||
|
for (var m in _modules.entries) {
|
||
|
final name = m.key;
|
||
|
final version = m.value;
|
||
|
final dir = "$workingDir\\$name";
|
||
|
final versionFile = File("$dir\\version");
|
||
|
if (await versionFile.exists() &&
|
||
|
(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");
|
||
|
}
|
||
|
}
|
||
|
}
|