|
@@ -17,21 +17,22 @@ Future downloadLatestClashCore() async {
|
|
|
final version = "v1.16.0";
|
|
|
final String clashCoreName = 'clash.meta-${ClashName.platform}-${ClashName.arch}-cgo-$version';
|
|
|
print(clashCoreName);
|
|
|
- final info = await dio.get('https://api.github.com/repos/MetaCubeX/Clash.Meta/releases');
|
|
|
- final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(clashCoreName));
|
|
|
-
|
|
|
- final String name = latest['name'];
|
|
|
+ // final info = await dio.get('https://api.github.com/repos/MetaCubeX/Clash.Meta/releases');
|
|
|
+ // final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(clashCoreName));
|
|
|
+ //
|
|
|
+ final String newName = 'clash-${ClashName.platform}-${ClashName.arch}';
|
|
|
+ final String name = "$clashCoreName.gz";
|
|
|
final tempFile = File(path.join(binDir.path, '$name.temp'));
|
|
|
-
|
|
|
+//https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/clash.meta-linux-amd64-cgo-v1.16.0.gz
|
|
|
print('Downloading $name');
|
|
|
- await dio.download(latest['browser_download_url'], tempFile.path);
|
|
|
+ await dio.download("https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/$name", tempFile.path);
|
|
|
print('Download Success');
|
|
|
|
|
|
print('Unarchiving $name');
|
|
|
final tempBetys = await tempFile.readAsBytes();
|
|
|
if (name.contains('.gz')) {
|
|
|
final bytes = GZipDecoder().decodeBytes(tempBetys);
|
|
|
- final String filePath = path.join(binDir.path, clashCoreName);
|
|
|
+ final String filePath = path.join(binDir.path, newName);
|
|
|
await File(filePath).writeAsBytes(bytes);
|
|
|
await Process.run('chmod', ['+x', filePath]);
|
|
|
} else {
|
|
@@ -41,31 +42,80 @@ Future downloadLatestClashCore() async {
|
|
|
await tempFile.delete();
|
|
|
print('Unarchiv Success');
|
|
|
}
|
|
|
-
|
|
|
-Future downloadLatestClashService() async {
|
|
|
- final String serviceName = 'clash-for-flutter-service-${ClashName.platform}-${ClashName.arch}';
|
|
|
- final info = await dio.get('https://api.github.com/repos/csj8520/clash-for-flutter-service/releases/latest');
|
|
|
- final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(serviceName));
|
|
|
-
|
|
|
- final String name = latest['name'];
|
|
|
- final tempFile = File(path.join(binDir.path, '$name.temp'));
|
|
|
-
|
|
|
- print('Downloading $name');
|
|
|
- await dio.download(latest['browser_download_url'], tempFile.path);
|
|
|
+Future<void> downloadAndUnarchiveService() async {
|
|
|
+ // const String token = "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"; // 请确保不在公共代码中硬编码这个token
|
|
|
+
|
|
|
+ final serviceName = 'ccore-service-${ClashName.platform}-${ClashName.arch}';
|
|
|
+ // "name" -> "ccore-service-darwin-amd64-v1.0.0.gz"
|
|
|
+ //final newSericeName = "$serviceName-v1.0.0.gz";
|
|
|
+ // 获取GitHub release信息
|
|
|
+ // dio.options.headers["Authorization"] = "token $token";
|
|
|
+ final response = await dio.get('https://api.github.com/repos/alroyso/core-service/releases/latest');
|
|
|
+ final Map<String, dynamic> latest = (response.data['assets'] as List<dynamic>)
|
|
|
+ .firstWhere((it) => (it['name'] as String).contains(serviceName));
|
|
|
+
|
|
|
+ final downloadUrl = latest['browser_download_url'];
|
|
|
+
|
|
|
+ print('Downloading $downloadUrl');
|
|
|
+
|
|
|
+ final tempFile = File(path.join(binDir.path, '${latest['name']}.temp'));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ print(dio.options.headers);
|
|
|
+ await dio.download(downloadUrl, tempFile.path);
|
|
|
+ } catch (e){
|
|
|
+ print(e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
print('Download Success');
|
|
|
+ print('Unarchiving ${latest['name']}');
|
|
|
|
|
|
- print('Unarchiving $name');
|
|
|
- final tempBetys = await tempFile.readAsBytes();
|
|
|
- if (name.contains('.gz')) {
|
|
|
- final bytes = GZipDecoder().decodeBytes(tempBetys);
|
|
|
- final String filePath = path.join(binDir.path, serviceName);
|
|
|
- await File(filePath).writeAsBytes(bytes);
|
|
|
- await Process.run('chmod', ['+x', filePath]);
|
|
|
+ final tempBytes = await tempFile.readAsBytes();
|
|
|
+
|
|
|
+ if (latest['name'].contains('.gz')) {
|
|
|
+ final bytes = GZipDecoder().decodeBytes(tempBytes);
|
|
|
+ await File(path.join(binDir.path, serviceName)).writeAsBytes(bytes);
|
|
|
} else {
|
|
|
- final file = ZipDecoder().decodeBytes(tempBetys).first;
|
|
|
+ final file = ZipDecoder().decodeBytes(tempBytes).first;
|
|
|
await File(path.join(binDir.path, file.name)).writeAsBytes(file.content);
|
|
|
}
|
|
|
+
|
|
|
+ final filePath = path.join(binDir.path, serviceName);
|
|
|
+ await Process.run('chmod', ['+x', filePath]);
|
|
|
+
|
|
|
await tempFile.delete();
|
|
|
+
|
|
|
+ print('Unarchive Success');
|
|
|
+}
|
|
|
+
|
|
|
+Future downloadLatestClashService() async {
|
|
|
+ final String serviceName = 'ccore-service-${ClashName.platform}-${ClashName.arch}';
|
|
|
+ // // final info = await dio.get('https://api.github.com/repos/alroyso/clash-for-flutter-service/releases/latest');
|
|
|
+ // // final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(serviceName));
|
|
|
+ // //https://github.com/alroyso/clash-for-flutter-service/releases/download/untagged-8273cca760b55d0725ab/naiyou-service-darwin-arm64-v1.0.1.gz
|
|
|
+ // var verion = 'v1.0.1';
|
|
|
+ // final String name = 'naiyou-service-${ClashName.platform}-${ClashName.arch}-$verion.gz';
|
|
|
+ // final tempFile = File(path.join(binDir.path, '$name.temp'));
|
|
|
+ // var url = "https://github.com/alroyso/clash-for-flutter-service/releases/tag/untagged-8273cca760b55d0725ab";
|
|
|
+ // print('Downloading $url/$name');
|
|
|
+ // dio.options.headers["Authorization"] = "token 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";
|
|
|
+ // await dio.download('$url/$name', tempFile.path);
|
|
|
+ // print('Download Success');
|
|
|
+ //
|
|
|
+ // print('Unarchiving $name');
|
|
|
+ // final tempBetys = await tempFile.readAsBytes();
|
|
|
+ // if (name.contains('.gz')) {
|
|
|
+ // final bytes = GZipDecoder().decodeBytes(tempBetys);
|
|
|
+ // final String filePath = path.join(binDir.path, serviceName);
|
|
|
+ // await File(filePath).writeAsBytes(bytes);
|
|
|
+ // await Process.run('chmod', ['+x', filePath]);
|
|
|
+ // } else {
|
|
|
+ // final file = ZipDecoder().decodeBytes(tempBetys).first;
|
|
|
+ // await File(path.join(binDir.path, file.name)).writeAsBytes(file.content);
|
|
|
+ // }
|
|
|
+ final String filePath = path.join(binDir.path, serviceName);
|
|
|
+ await Process.run('chmod', ['+x', filePath]);
|
|
|
+ //await tempFile.delete();
|
|
|
print('Unarchiv Success');
|
|
|
}
|
|
|
|
|
@@ -94,7 +144,7 @@ void main() async {
|
|
|
if (!(await depDir.exists())) await depDir.create();
|
|
|
|
|
|
await downloadLatestClashCore();
|
|
|
- // await downloadLatestClashService();
|
|
|
+ await downloadAndUnarchiveService();
|
|
|
|
|
|
await downloadCountryMmdb();
|
|
|
if (Platform.isWindows) await downloadWintun();
|