Adds current code
This commit is contained in:
commit
fac61e008f
138 changed files with 5658 additions and 0 deletions
94
lib/settings.dart
Normal file
94
lib/settings.dart
Normal file
|
@ -0,0 +1,94 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:servermanager/credentials.dart';
|
||||
import 'package:servermanager/mod.dart';
|
||||
import 'package:servermanager/steamcmd.dart';
|
||||
|
||||
class Settings {
|
||||
void Read() {
|
||||
if (!isValid()) return;
|
||||
var box = Hive.box("settings");
|
||||
|
||||
var ml = box.get("modlist", defaultValue: []);
|
||||
for (final item in ml) {
|
||||
try {
|
||||
Mod X = item as Mod;
|
||||
mods.add(X);
|
||||
} catch (E) {}
|
||||
}
|
||||
|
||||
steam_creds = box.get("creds");
|
||||
}
|
||||
|
||||
void Write() {
|
||||
if (!isValid()) return;
|
||||
var box = Hive.box("settings");
|
||||
box.put("modlist", mods);
|
||||
|
||||
if (steam_creds != null) box.put("creds", steam_creds);
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
List<Mod> mods = [];
|
||||
String steamcmd_path = "";
|
||||
String game_path = "";
|
||||
Credentials? steam_creds;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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"
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue