104 lines
2.1 KiB
Dart
104 lines
2.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:hive/hive.dart';
|
|
import 'package:servermanager/settingsEntry.dart';
|
|
|
|
class Settings {
|
|
Settings._();
|
|
static final Settings Instance = Settings._();
|
|
|
|
String steamcmd_path = "";
|
|
String game_path = "";
|
|
|
|
factory Settings() {
|
|
return Instance;
|
|
}
|
|
|
|
SettingsEntry? inst;
|
|
|
|
void Read() {
|
|
if (!isValid()) return;
|
|
var box = Hive.box("settings");
|
|
|
|
inst = box.get("entry", defaultValue: SettingsEntry()) as SettingsEntry;
|
|
}
|
|
|
|
void Write() {
|
|
if (!isValid()) return;
|
|
var box = Hive.box("settings");
|
|
box.put("entry", inst);
|
|
}
|
|
|
|
bool isValid() {
|
|
if (!Hive.isBoxOpen("settings")) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
Future<Box<E>> Open<E>() {
|
|
Close();
|
|
return Hive.openBox("settings", path: game_path);
|
|
}
|
|
|
|
static void Close() {
|
|
if (Hive.isBoxOpen("settings")) {
|
|
Hive.box("settings").close();
|
|
}
|
|
}
|
|
|
|
String getServerPath() {
|
|
return "$game_path${Platform.pathSeparator}server";
|
|
}
|
|
|
|
bool checkInitDone() {
|
|
if (File("$steamcmd_path${Platform.pathSeparator}cxinit").existsSync()) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
String getSteamCmd() {
|
|
return "$steamcmd_path${Platform.pathSeparator}steamcmd${Platform.isWindows ? ".exe" : ".sh"}";
|
|
}
|
|
|
|
String getSteamCmd2FA() {
|
|
return "$steamcmd_path${Platform.pathSeparator}steamcmd-2fa${Platform.isWindows ? ".exe" : ""}";
|
|
}
|
|
|
|
String getModPath() {
|
|
return "$game_path${Platform.pathSeparator}mods";
|
|
}
|
|
|
|
Future<void> createModFolderIfNotExists() async {
|
|
if (Directory(getModPath()).existsSync()) {
|
|
return;
|
|
} else {
|
|
await Directory(getModPath()).create(recursive: true);
|
|
}
|
|
}
|
|
|
|
bool serverInstalled() {
|
|
return File(
|
|
"${getServerPath()}${Platform.pathSeparator}ConanSandboxServer.exe")
|
|
.existsSync();
|
|
}
|
|
|
|
Future<ProcessResult> RunUpdate() {
|
|
return Process.run(getSteamCmd(), [
|
|
"+@sSteamCmdForcePlatformType",
|
|
"windows",
|
|
"+force_install_dir",
|
|
getServerPath(),
|
|
"+login",
|
|
"anonymous",
|
|
"+app_update",
|
|
"443030",
|
|
"public",
|
|
"validate",
|
|
"+quit"
|
|
]);
|
|
}
|
|
}
|