This commit is contained in:
Alessandro Autiero
2022-12-16 21:08:57 +01:00
parent ef7f34e0e3
commit 966b4b33fd
91 changed files with 388682 additions and 1005 deletions

View File

@@ -5,51 +5,20 @@ import 'package:html/parser.dart' show parse;
import 'package:http/http.dart' as http;
import 'package:process_run/shell.dart';
import 'package:reboot_launcher/src/model/fortnite_build.dart';
import 'package:reboot_launcher/src/util/time.dart';
import 'package:reboot_launcher/src/util/version.dart' as parser;
import 'package:version/version.dart';
import 'os.dart';
const _userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36";
final _cookieRegex = RegExp("cookie=\"(.*?);");
final _manifestSourceUrl = Uri.parse(
"https://github.com/VastBlast/FortniteManifestArchive/blob/main/README.md");
final _archiveCookieUrl = Uri.parse("http://allinstaller.xyz/rel");
final _archiveSourceUrl = Uri.parse("http://allinstaller.xyz/rel?i=1");
Future<List<FortniteBuild>> fetchBuilds(ignored) async {
var futures = await Future.wait([_fetchArchives(), _fetchManifests()]);
return futures.expand((element) => element)
.toList()
..sort((first, second) => first.version.compareTo(second.version));
}
Future<List<FortniteBuild>> _fetchArchives() async {
var cookieResponse = await http.get(_archiveCookieUrl);
var cookie = _cookieRegex.firstMatch(cookieResponse.body)?.group(1)?.trim();
var response =
await http.get(_archiveSourceUrl, headers: {"Cookie": cookie!});
if (response.statusCode != 200) {
throw Exception("Erroneous status code: ${response.statusCode}");
}
var document = parse(response.body);
var results = <FortniteBuild>[];
for (var build in document.querySelectorAll("a[href^='https']")) {
var version = parser.tryParse(build.text.replaceAll("Build ", ""));
if (version == null) {
continue;
}
results.add(FortniteBuild(
version: version, link: build.attributes["href"]!, hasManifest: false));
}
return results;
}
Future<List<FortniteBuild>> _fetchManifests() async {
var response = await http.get(_manifestSourceUrl);
if (response.statusCode != 200) {
throw Exception("Erroneous status code: ${response.statusCode}");
@@ -68,13 +37,13 @@ Future<List<FortniteBuild>> _fetchManifests() async {
var name = children[0].text;
var minifiedName = name.substring(name.indexOf("-") + 1, name.lastIndexOf("-"));
var version = parser
.tryParse(minifiedName.replaceFirst("-CL", ""));
.tryParse(minifiedName.replaceFirst("", ""));
if (version == null) {
continue;
}
var link = children[2].firstChild!.attributes["href"]!;
results.add(FortniteBuild(version: version, link: link, hasManifest: true));
results.add(FortniteBuild(version: version, link: link));
}
return results;
@@ -93,9 +62,12 @@ Future<Process> downloadManifestBuild(
}
Future<void> downloadArchiveBuild(String archiveUrl, String destination,
Function(double) onProgress, Function() onRar) async {
Function(double, String) onProgress, Function() onDecompress) async {
var uuid = Random.secure().nextInt(1000000);
var extension = archiveUrl.substring(archiveUrl.lastIndexOf("."));
var tempFile = File(
"$destination\\.temp\\FortniteBuild${Random.secure().nextInt(1000000)}.rar");
"$destination\\.temp\\FortniteBuild$uuid$extension"
);
await tempFile.parent.create(recursive: true);
try {
var client = http.Client();
@@ -106,27 +78,38 @@ Future<void> downloadArchiveBuild(String archiveUrl, String destination,
throw Exception("Erroneous status code: ${response.statusCode}");
}
var startTime = DateTime.now();
var lastRemaining = -1;
var length = response.contentLength!;
var received = 0;
var sink = tempFile.openWrite();
await response.stream.map((s) {
received += s.length;
onProgress((received / length) * 100);
return s;
var lastEta = toETA(0);
await response.stream.map((entry) {
received += entry.length;
var percentage = (received / length) * 100;
var elapsed = DateTime.now().difference(startTime).inMilliseconds;
var newRemaining = (elapsed * length / received - elapsed).round();
if(lastRemaining < 0 || lastRemaining - newRemaining <= -10000 || lastRemaining > newRemaining) {
lastEta = toETA(lastRemaining = newRemaining);
}
onProgress(percentage, lastEta);
return entry;
}).pipe(sink);
onRar();
onDecompress();
var output = Directory(destination);
await output.create(recursive: true);
await loadBinary("winrar.exe", true);
var shell = Shell(
commandVerbose: false,
commentVerbose: false,
workingDirectory: internalBinariesDirectory
workingDirectory: safeBinariesDirectory
);
await shell.run("./winrar.exe x ${tempFile.path} *.* \"${output.path}\"");
await shell.run("./winrar.exe x \"${tempFile.path}\" *.* \"${output.path}\"");
} finally {
if (await tempFile.exists()) {
tempFile.delete();
if (await tempFile.parent.exists()) {
tempFile.parent.delete(recursive: true);
}
}
}