ConanServerManager/lib/game.dart

88 lines
2.2 KiB
Dart
Raw Permalink Normal View History

2023-11-01 03:28:33 -07:00
import 'dart:io';
2023-11-04 04:44:47 -07:00
import 'package:crypto/crypto.dart';
import 'package:libac_dart/utils/IOTools.dart';
import 'package:servermanager/structs/mod.dart';
import 'package:servermanager/structs/settings.dart';
2023-11-01 03:28:33 -07:00
Future<void> doDownloadMods(bool jail) async {
Settings settings = Settings();
// Build download command
List<String> manifest = [
"+@sSteamCmdForcePlatformType",
"windows",
"+force_install_dir",
jail ? settings.getModJailPath() : settings.getModPath(),
"+login",
2024-05-23 22:18:59 -07:00
"anonymous",
];
for (Mod M in settings.inst!.mods) {
2024-06-04 21:51:53 -07:00
if (!M.enabled) continue;
manifest.add("+workshop_download_item");
manifest.add("440900");
manifest.add("${M.mod_id}");
}
await settings.createModFolderIfNotExists();
2024-05-23 22:18:59 -07:00
await settings.createModJailFolderIfNotExists();
manifest.add("+quit");
//print(
// "Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}");
2023-11-08 15:20:40 -07:00
var result = await Process.run(settings.getSteamCmd(), manifest);
print(result.stdout);
}
2024-05-25 04:50:28 -07:00
Future<List<Mod>> doScanMods(bool jail) async {
Settings settings = Settings();
List<Mod> ret = [];
for (Mod M in settings.inst!.mods.toList()) {
2024-06-04 21:51:53 -07:00
if (!M.enabled) {
ret.add(M);
continue;
}
var index = settings.inst!.mods.indexOf(M);
// Assemble final path.
2024-05-25 04:50:28 -07:00
String modsPath = PathHelper.builder(
jail ? settings.getModJailPath() : settings.getModPath())
.resolve("steamapps")
.resolve("workshop")
.resolve("content")
.resolve("440900")
.resolve("${M.mod_id}")
.build();
Directory dir = Directory(modsPath);
await for (var entity in dir.list()) {
if (entity is File && entity.path.endsWith("pak")) {
String name = entity.path.split(Platform.pathSeparator).last;
var content = await entity.readAsBytes();
var data = md5.convert(content);
var hash = data.toString();
M.mod_pak = name;
M.mod_hash = hash;
2024-05-23 22:18:59 -07:00
print("Discovered mod file: $name");
print("Hash: $hash");
// Update the mod instance, and retain the original modlist order
ret.add(Mod(
mod_hash: hash,
mod_id: M.mod_id,
mod_pak: name,
mod_name: M.mod_name));
}
}
}
return ret;
}