2023-11-01 03:28:33 -07:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-11-04 04:44:47 -07:00
|
|
|
import 'package:crypto/crypto.dart';
|
2024-05-24 14:52:01 -07:00
|
|
|
import 'package:libac_dart/utils/IOTools.dart';
|
2024-05-23 00:11:14 -07:00
|
|
|
import 'package:servermanager/structs/mod.dart';
|
|
|
|
import 'package:servermanager/structs/settings.dart';
|
2023-11-01 03:28:33 -07:00
|
|
|
|
2024-05-23 04:12:45 -07:00
|
|
|
Future<void> doDownloadMods(bool jail) async {
|
2023-11-08 15:08:26 -07:00
|
|
|
Settings settings = Settings();
|
|
|
|
|
|
|
|
// Build download command
|
|
|
|
List<String> manifest = [
|
|
|
|
"+@sSteamCmdForcePlatformType",
|
|
|
|
"windows",
|
|
|
|
"+force_install_dir",
|
2024-05-23 04:12:45 -07:00
|
|
|
jail ? settings.getModJailPath() : settings.getModPath(),
|
2023-11-08 15:08:26 -07:00
|
|
|
"+login",
|
2024-05-23 22:18:59 -07:00
|
|
|
"anonymous",
|
2023-11-08 15:08:26 -07:00
|
|
|
];
|
|
|
|
for (Mod M in settings.inst!.mods) {
|
2024-06-04 21:51:53 -07:00
|
|
|
if (!M.enabled) continue;
|
2023-11-08 15:08:26 -07:00
|
|
|
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();
|
2023-11-08 15:08:26 -07:00
|
|
|
|
|
|
|
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);
|
2023-11-08 15:08:26 -07:00
|
|
|
|
|
|
|
print(result.stdout);
|
|
|
|
}
|
|
|
|
|
2024-05-25 04:50:28 -07:00
|
|
|
Future<List<Mod>> doScanMods(bool jail) async {
|
2023-11-04 16:55:13 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-11-04 16:55:13 -07:00
|
|
|
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())
|
2023-11-04 16:55:13 -07:00
|
|
|
.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");
|
2023-11-04 16:55:13 -07:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|