mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 19:22:22 +01:00
Final version
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:reboot_common/common.dart';
|
||||
import 'package:reboot_launcher/src/util/translations.dart';
|
||||
|
||||
String? checkVersion(String? text, List<FortniteVersion> versions) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return 'Empty version name';
|
||||
return translations.emptyVersionName;
|
||||
}
|
||||
|
||||
if (versions.any((element) => element.name == text)) {
|
||||
return 'This version already exists';
|
||||
return translations.versionAlreadyExists;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -16,7 +17,7 @@ String? checkVersion(String? text, List<FortniteVersion> versions) {
|
||||
|
||||
String? checkChangeVersion(String? text) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return 'Empty version name';
|
||||
return translations.emptyVersionName;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -24,16 +25,16 @@ String? checkChangeVersion(String? text) {
|
||||
|
||||
String? checkGameFolder(text) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return 'Empty game path';
|
||||
return translations.emptyGamePath;
|
||||
}
|
||||
|
||||
var directory = Directory(text);
|
||||
if (!directory.existsSync()) {
|
||||
return "Directory doesn't exist";
|
||||
return translations.directoryDoesNotExist;
|
||||
}
|
||||
|
||||
if (FortniteVersionExtension.findExecutable(directory, "FortniteClient-Win64-Shipping.exe") == null) {
|
||||
return "Invalid game path";
|
||||
return translations.missingShippingExe;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -41,7 +42,7 @@ String? checkGameFolder(text) {
|
||||
|
||||
String? checkDownloadDestination(text) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return 'Invalid download path';
|
||||
return translations.invalidDownloadPath;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -49,15 +50,15 @@ String? checkDownloadDestination(text) {
|
||||
|
||||
String? checkDll(String? text) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return "Empty dll path";
|
||||
return translations.invalidDllPath;
|
||||
}
|
||||
|
||||
if (!File(text).existsSync()) {
|
||||
return "This dll doesn't exist";
|
||||
return translations.dllDoesNotExist;
|
||||
}
|
||||
|
||||
if (!text.endsWith(".dll")) {
|
||||
return "This file is not a dll";
|
||||
return translations.invalidDllExtension;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -65,12 +66,12 @@ String? checkDll(String? text) {
|
||||
|
||||
String? checkMatchmaking(String? text) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return "Empty hostname";
|
||||
return translations.emptyHostname;
|
||||
}
|
||||
|
||||
var ipParts = text.split(":");
|
||||
if(ipParts.length > 2){
|
||||
return "Wrong format, expected ip:port";
|
||||
return translations.hostnameFormat;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -78,7 +79,7 @@ String? checkMatchmaking(String? text) {
|
||||
|
||||
String? checkUpdateUrl(String? text) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return "Empty URL";
|
||||
return translations.emptyURL;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:reboot_common/common.dart';
|
||||
|
||||
final File _script = File("${assetsDirectory.path}\\misc\\udp.ps1");
|
||||
const Duration _timeout = Duration(seconds: 2);
|
||||
|
||||
Future<bool> _pingGameServer(String hostname, int port) async {
|
||||
var socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
|
||||
var dataToSend = utf8.encode(DateTime.now().toIso8601String());
|
||||
socket.send(dataToSend, InternetAddress(hostname), port);
|
||||
await for (var event in socket) {
|
||||
switch(event) {
|
||||
case RawSocketEvent.read:
|
||||
return true;
|
||||
case RawSocketEvent.readClosed:
|
||||
case RawSocketEvent.closed:
|
||||
return false;
|
||||
case RawSocketEvent.write:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool> get _timeoutFuture => Future.delayed(_timeout).then((value) => false);
|
||||
|
||||
Future<bool> pingGameServer(String address, {Duration? timeout}) async {
|
||||
var start = DateTime.now();
|
||||
@@ -10,23 +32,20 @@ Future<bool> pingGameServer(String address, {Duration? timeout}) async {
|
||||
while (firstTime || (timeout != null && DateTime.now().millisecondsSinceEpoch - start.millisecondsSinceEpoch < timeout.inMilliseconds)) {
|
||||
var split = address.split(":");
|
||||
var hostname = split[0];
|
||||
var port = split.length > 1 ? split[1] : kDefaultGameServerPort;
|
||||
var result = await Process.run(
|
||||
"powershell",
|
||||
[
|
||||
_script.path,
|
||||
hostname,
|
||||
port
|
||||
]
|
||||
);
|
||||
if (result.exitCode == 0) {
|
||||
if(isLocalHost(hostname)) {
|
||||
hostname = "127.0.0.1";
|
||||
}
|
||||
|
||||
var port = int.parse(split.length > 1 ? split[1] : kDefaultGameServerPort);
|
||||
var result = await Future.any([_timeoutFuture, _pingGameServer(hostname, port)]);
|
||||
if(result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
}else {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
await Future.delayed(_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
gui/lib/src/util/translations.dart
Normal file
18
gui/lib/src/util/translations.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter_gen/gen_l10n/reboot_localizations.dart';
|
||||
|
||||
AppLocalizations? _translations;
|
||||
bool _init = false;
|
||||
|
||||
AppLocalizations get translations {
|
||||
if(!_init) {
|
||||
throw StateError("Translations haven't been loaded");
|
||||
}
|
||||
|
||||
return _translations!;
|
||||
}
|
||||
|
||||
void loadTranslations(BuildContext context) {
|
||||
_translations = AppLocalizations.of(context)!;
|
||||
_init = true;
|
||||
}
|
||||
Reference in New Issue
Block a user