diff --git a/lib/game.dart b/lib/game.dart index 0fdc67a..eb28a58 100644 --- a/lib/game.dart +++ b/lib/game.dart @@ -92,6 +92,46 @@ class GameServerPageState extends State { Navigator.pushNamed(context, "/server/mods"); }, ), + ListTile( + title: Text("Download Mods"), + subtitle: Text("Downloads the mods"), + leading: Icon(Icons.download_sharp), + onTap: () async { + // Triggers the download status + setState(() { + downloading = true; + }); + + // Now, invoke SteamCmd to download the workshop mods. This is an authenticated action, and does require Scmd2fa + var result = await Process.run(settings.getSteamCmd2FA(), + ["--raw", "--secret", settings.steam_creds!.secret]); + var code = result.stdout; + // Build download command + + List manifest = [ + "+@sSteamCmdForcePlatformType", + "windows", + "+force_install_dir", + settings.getModPath(), + "+login", + settings.steam_creds!.username, + settings.steam_creds!.password, + code + ]; + for (Mod M in settings.mods) { + manifest.add("+workshop_download_item"); + manifest.add("${M.mod_id}"); + } + + result = + await Process.run(settings.getSteamCmd(), manifest); + + // Unset downloading + setState(() { + downloading = false; + }); + }, + ), ListTile( title: Text("Status:"), subtitle: Text("Not Running"), @@ -211,6 +251,7 @@ class ModPage extends StatelessWidget { String instance = ""; bool isNewMod = false; bool willDelete = false; + String pak = "Not initialized"; @override Widget build(BuildContext context) { @@ -223,6 +264,7 @@ class ModPage extends StatelessWidget { name.text = args.mod_name; isNewMod = args.newMod; instance = args.mod_instance_id(); + pak = args.mod_pak; } } @@ -280,6 +322,11 @@ class ModPage extends StatelessWidget { title: Text("Mod Instance ID"), subtitle: Text(instance), ), + ListTile( + title: Text("Mod Pak File: $pak"), + subtitle: + Text("Mod pak file name as detected during downloading"), + ), if (!isNewMod) ElevatedButton( onPressed: () { diff --git a/lib/mod.dart b/lib/mod.dart index 05d6f2f..d2bda1e 100644 --- a/lib/mod.dart +++ b/lib/mod.dart @@ -11,6 +11,9 @@ class Mod { @HiveField(1) int mod_id; + @HiveField(2) + String mod_pak; + bool newMod = false; String _id = ""; String mod_instance_id() { @@ -21,5 +24,9 @@ class Mod { return _id; } - Mod({this.mod_name = "undef", this.mod_id = 0, this.newMod = false}); + Mod( + {this.mod_name = "undef", + this.mod_id = 0, + this.newMod = false, + this.mod_pak = "Not Initialized"}); } diff --git a/lib/settings.dart b/lib/settings.dart index 896671f..b95ea62 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -77,6 +77,24 @@ class Settings { (Platform.isWindows ? ".exe" : ".sh"); } + String getSteamCmd2FA() { + return steamcmd_path + + Platform.pathSeparator + + "steamcmd-2fa" + + (Platform.isWindows ? ".exe" : ""); + } + + String getModPath() { + return game_path + Platform.pathSeparator + "mods"; + } + + void assertModsFolderExists() { + if (Directory(getModPath()).existsSync()) + return; + else + Directory(getModPath()).createSync(recursive: true); + } + bool serverInstalled() { return File( getServerPath() + Platform.pathSeparator + "ConanSandboxServer.exe")