From 462fca139e76fd2d39c3d0700f7d140db21885ae Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 4 Nov 2023 18:43:11 -0700 Subject: [PATCH] Start to add the start/stop logic --- lib/game.dart | 37 ++++++++++++++++++++++++++++++++++--- lib/settings.dart | 21 +++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/lib/game.dart b/lib/game.dart index 9dbd360..f6db48b 100644 --- a/lib/game.dart +++ b/lib/game.dart @@ -100,6 +100,7 @@ class GameServerPageState extends State { Settings settings; GameServerPageState({required this.settings}); var downloading = false; + var running = false; late Stream> download_stream; TextEditingController ValueControl = TextEditingController(); @@ -224,9 +225,39 @@ class GameServerPageState extends State { ), ListTile( title: Text("Status:"), - subtitle: Text("Not Running"), - leading: Icon(Icons.error), - ) + subtitle: Text(running ? "Active" : "Not Running"), + leading: Icon(running ? Icons.play_arrow : Icons.error), + onTap: () async { + // Toggle state + setState(() { + running = !running; + }); + + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text(running + ? "Server is now starting..." + : "Stopping the server"))); + + if (!running) { + // Send message indicating the server is stopping, then wait for 30 seconds and then stop the server + } else { + await settings.RunUpdate(); + await doDownloadMods(settings.getModPath()); + setState(() async { + settings.inst!.mods = + await doScanMods(settings.getModPath()); + }); + + // Generate the actual mod list now + await settings.createServerModFolderIfNotExists(); + if (Platform.isWindows) { + // Save the paths exactly + } else { + // Save the paths relative to the Z: drive + } + } + }, + ), ], )), ), diff --git a/lib/settings.dart b/lib/settings.dart index e334dd3..4017955 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:hive/hive.dart'; +import 'package:servermanager/pathtools.dart'; import 'package:servermanager/settingsEntry.dart'; class Settings { @@ -123,4 +124,24 @@ class Settings { "+quit" ]); } + + Future createServerModFolderIfNotExists() async { + Directory dir = Directory(PathHelper(pth: getServerPath()) + .resolve("ConanSandbox") + .resolve("Mods") + .build()); + + if (await dir.exists()) { + return; + } else + await dir.create(recursive: true); + } + + File getModListFile() { + return File(PathHelper(pth: getServerPath()) + .resolve("ConanSandbox") + .resolve("Mods") + .resolve("modlist.txt") + .build()); + } }