Got more stuff connected up and working
This commit is contained in:
parent
7cddfd2de6
commit
a1141cd2b8
7 changed files with 111 additions and 97 deletions
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||
import 'package:archive/archive.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:libac_flutter/nbt/NbtIo.dart';
|
||||
import 'package:libac_flutter/nbt/NbtUtils.dart';
|
||||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_flutter/packets/packets.dart';
|
||||
import 'package:libac_flutter/utils/IOTools.dart';
|
||||
|
@ -21,11 +22,17 @@ class Settings {
|
|||
final String Base2FAPath =
|
||||
"https://github.com/zontreck/steamcmd-2fa/releases/download/0.2.0/steamcmd-2fa";
|
||||
|
||||
final String PROTON_URL =
|
||||
"https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton9-5/GE-Proton9-5.tar.gz";
|
||||
|
||||
Settings._();
|
||||
static final Settings Instance = Settings._();
|
||||
|
||||
String steamcmd_path = "";
|
||||
String game_path = "";
|
||||
String proton_path = "";
|
||||
String base_path = "";
|
||||
bool FTS = true;
|
||||
Credentials serverLoginCreds = Credentials(
|
||||
username: "admin", password: "changeMe123", secret: "", has_2fa: false);
|
||||
UUID remoteLoginToken = UUID.ZERO;
|
||||
|
@ -47,42 +54,44 @@ class Settings {
|
|||
inst = SettingsEntry.deserialize(tag.get("entry") as CompoundTag);
|
||||
serverLoginCreds = Credentials.deserialize(
|
||||
tag.get(Credentials.TAG_NAME)!.asCompoundTag());
|
||||
FTS = NbtUtils.readBoolean(tag, "fts");
|
||||
} catch (E) {
|
||||
print("No existing settings file found, initializing default settings");
|
||||
inst = SettingsEntry();
|
||||
inst!.steam_creds =
|
||||
Credentials(username: "", password: "", secret: "", has_2fa: false);
|
||||
|
||||
serverLoginCreds = Credentials(
|
||||
username: "admin",
|
||||
password: "changeMe123",
|
||||
secret: "",
|
||||
has_2fa: false);
|
||||
FTS = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Write() {
|
||||
if (!isValid()) return;
|
||||
if (inst == null) return;
|
||||
CompoundTag tag = CompoundTag();
|
||||
tag.put("entry", inst!.serialize());
|
||||
tag.put(Credentials.TAG_NAME, serverLoginCreds.save());
|
||||
NbtUtils.writeBoolean(tag, "fts", FTS);
|
||||
|
||||
NbtIo.write("settings.dat", tag);
|
||||
}
|
||||
|
||||
bool isValid() {
|
||||
if (inst == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> Open() async {
|
||||
Close();
|
||||
Instance.Read();
|
||||
}
|
||||
|
||||
static void Close() async {
|
||||
if (Instance.isValid()) {
|
||||
Instance.Write();
|
||||
Instance.inst = null;
|
||||
}
|
||||
Instance.Write();
|
||||
Instance.inst = null;
|
||||
}
|
||||
|
||||
String getServerPath() {
|
||||
return "$game_path${Platform.pathSeparator}server";
|
||||
return game_path;
|
||||
}
|
||||
|
||||
bool checkInitDone() {
|
||||
|
@ -97,16 +106,32 @@ class Settings {
|
|||
return "$steamcmd_path${Platform.pathSeparator}steamcmd${Platform.isWindows ? ".exe" : ".sh"}";
|
||||
}
|
||||
|
||||
String getSteamCmdPath() {
|
||||
return steamcmd_path;
|
||||
}
|
||||
|
||||
String getSteamCmd2FA() {
|
||||
return "$steamcmd_path${Platform.pathSeparator}steamcmd-2fa${Platform.isWindows ? ".exe" : ""}";
|
||||
}
|
||||
|
||||
String getModPath() {
|
||||
return "$game_path${Platform.pathSeparator}mods";
|
||||
return PathHelper(pth: base_path).resolve("mods").build();
|
||||
}
|
||||
|
||||
String getModJailPath() {
|
||||
return "$game_path${Platform.pathSeparator}mods.jail";
|
||||
return PathHelper(pth: base_path).resolve("mods.jail").build();
|
||||
}
|
||||
|
||||
String getProtonPath() {
|
||||
return PathHelper(pth: base_path).resolve("proton").build();
|
||||
}
|
||||
|
||||
String getProtonExecutablePath() {
|
||||
return PathHelper(pth: base_path)
|
||||
.resolve("proton")
|
||||
.resolve("GE-Proton9-5")
|
||||
.resolve("proton")
|
||||
.build();
|
||||
}
|
||||
|
||||
Future<void> createModFolderIfNotExists() async {
|
||||
|
@ -195,7 +220,28 @@ class Settings {
|
|||
flush: true, mode: FileMode.writeOnly);
|
||||
}
|
||||
|
||||
Future<void> initializeProton() async {
|
||||
Dio dio = Dio();
|
||||
print("Downloading proton...");
|
||||
final path = PathHelper(pth: getProtonPath()).resolve("proton.tar.gz");
|
||||
await dio.download(PROTON_URL, path.build());
|
||||
|
||||
String oldWD = Directory.current.path;
|
||||
Directory.current = getProtonPath();
|
||||
Process.runSync("tar", ["-xvf", "proton.tar.gz"]);
|
||||
Process.runSync("rm", ["-f", "proton.tar.gz"]);
|
||||
|
||||
Directory.current = oldWD; // Restore the old working directory
|
||||
print("Finished!");
|
||||
}
|
||||
|
||||
Future<void> initializeSteamCmd() async {
|
||||
if (File(PathHelper(pth: getSteamCmdPath()).resolve("cxinit").build())
|
||||
.existsSync()) {
|
||||
print(
|
||||
"Skipping SteamCmd and Proton initialization, already marked as ready");
|
||||
return;
|
||||
}
|
||||
// Yes, Proceed
|
||||
var x = Directory(steamcmd_path);
|
||||
try {
|
||||
|
@ -217,6 +263,8 @@ class Settings {
|
|||
final bytes = File(path).readAsBytesSync();
|
||||
final arc = ZipDecoder().decodeBytes(bytes);
|
||||
|
||||
print("SteamCmd downloaded. Performing initial update");
|
||||
|
||||
for (final file in arc) {
|
||||
final name = file.name;
|
||||
if (file.isFile) {
|
||||
|
@ -232,6 +280,7 @@ class Settings {
|
|||
Process.runSync("echo", ["X", ">", "cxinit"]);
|
||||
|
||||
proc = await Process.start("steamcmd.exe", ["+quit"]);
|
||||
print("Completed.");
|
||||
} else {
|
||||
// Download tgz file
|
||||
final path = "${steamcmd_path}${Platform.pathSeparator}linux.tgz";
|
||||
|
@ -241,6 +290,8 @@ class Settings {
|
|||
final arc = GZipDecoder().decodeBytes(bytes);
|
||||
final arc2 = TarDecoder().decodeBytes(arc);
|
||||
|
||||
print("SteamCmd downloaded. Performing initial update");
|
||||
|
||||
for (final file in arc2) {
|
||||
final name = file.name;
|
||||
if (file.isFile) {
|
||||
|
@ -256,7 +307,10 @@ class Settings {
|
|||
Process.runSync("chmod", ["+x", "linux32/steamcmd"]);
|
||||
Process.runSync("touch", ["cxinit"]);
|
||||
|
||||
proc = await Process.start("./steamcmd.sh", ["+quit"]);
|
||||
Process.runSync("./steamcmd.sh", ["+quit"]);
|
||||
|
||||
print("Completed. Initializing Proton");
|
||||
await initializeProton();
|
||||
}
|
||||
|
||||
Directory.current = Directory(game_path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue