import 'dart:io'; import 'package:crypto/crypto.dart'; import 'package:libac_dart/utils/IOTools.dart'; import 'package:servermanager/structs/mod.dart'; import 'package:servermanager/structs/settings.dart'; Future doDownloadMods(bool jail) async { Settings settings = Settings(); // Build download command List manifest = [ "+@sSteamCmdForcePlatformType", "windows", "+force_install_dir", jail ? settings.getModJailPath() : settings.getModPath(), "+login", "anonymous", ]; for (Mod M in settings.inst!.mods) { if (!M.enabled) continue; manifest.add("+workshop_download_item"); manifest.add("440900"); manifest.add("${M.mod_id}"); } await settings.createModFolderIfNotExists(); await settings.createModJailFolderIfNotExists(); manifest.add("+quit"); //print( // "Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}"); var result = await Process.run(settings.getSteamCmd(), manifest); print(result.stdout); } Future> doScanMods(bool jail) async { Settings settings = Settings(); List ret = []; for (Mod M in settings.inst!.mods.toList()) { if (!M.enabled) { ret.add(M); continue; } var index = settings.inst!.mods.indexOf(M); // Assemble final path. 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; 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; }