Start to add the start/stop logic

This commit is contained in:
zontreck 2023-11-04 18:43:11 -07:00
parent a33ebe3ffd
commit 462fca139e
2 changed files with 55 additions and 3 deletions

View file

@ -100,6 +100,7 @@ class GameServerPageState extends State<GameServerPage> {
Settings settings;
GameServerPageState({required this.settings});
var downloading = false;
var running = false;
late Stream<List<int>> download_stream;
TextEditingController ValueControl = TextEditingController();
@ -224,9 +225,39 @@ class GameServerPageState extends State<GameServerPage> {
),
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
}
}
},
),
],
)),
),

View file

@ -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<void> 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());
}
}