Get things to a semi-stable state

This commit is contained in:
zontreck 2023-11-04 04:44:47 -07:00
parent 3742a957bb
commit d8345d08fa
4 changed files with 74 additions and 4 deletions

View file

@ -1,7 +1,9 @@
import 'dart:io'; import 'dart:io';
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:servermanager/mod.dart'; import 'package:servermanager/mod.dart';
import 'package:servermanager/pathtools.dart';
import 'package:servermanager/settings.dart'; import 'package:servermanager/settings.dart';
class GameServerPage extends StatefulWidget { class GameServerPage extends StatefulWidget {
@ -109,8 +111,8 @@ class GameServerPageState extends State<GameServerPage> {
settings.inst!.steam_creds!.secret settings.inst!.steam_creds!.secret
]); ]);
var code = result.stdout as String; var code = result.stdout as String;
// Build download command
// Build download command
List<String> manifest = [ List<String> manifest = [
"+@sSteamCmdForcePlatformType", "+@sSteamCmdForcePlatformType",
"windows", "windows",
@ -131,8 +133,8 @@ class GameServerPageState extends State<GameServerPage> {
manifest.add("+quit"); manifest.add("+quit");
print( //print(
"Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}"); // "Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}");
result = result =
await Process.run(settings.getSteamCmd(), manifest); await Process.run(settings.getSteamCmd(), manifest);
@ -143,6 +145,40 @@ class GameServerPageState extends State<GameServerPage> {
setState(() { setState(() {
downloading = false; downloading = false;
}); });
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Scanning mods...")));
for (Mod M in settings.inst!.mods) {
// Assemble final path.
String modsPath = PathHelper.builder(settings.game_path)
.resolve("mods")
.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;
}
}
}
setState(() {
settings.Write();
});
}, },
), ),
ListTile( ListTile(
@ -266,6 +302,7 @@ class ModPage extends StatelessWidget {
bool isNewMod = false; bool isNewMod = false;
bool willDelete = false; bool willDelete = false;
String pak = "Not initialized"; String pak = "Not initialized";
String hash = "";
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -279,6 +316,7 @@ class ModPage extends StatelessWidget {
isNewMod = args.newMod; isNewMod = args.newMod;
instance = args.mod_instance_id(); instance = args.mod_instance_id();
pak = args.mod_pak; pak = args.mod_pak;
hash = args.mod_hash;
} }
} }
@ -341,6 +379,10 @@ class ModPage extends StatelessWidget {
subtitle: subtitle:
Text("Mod pak file name as detected during downloading"), Text("Mod pak file name as detected during downloading"),
), ),
ListTile(
title: Text("Mod Hash"),
subtitle: Text("$hash"),
),
if (!isNewMod) if (!isNewMod)
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {

View file

@ -14,6 +14,9 @@ class Mod {
@HiveField(2) @HiveField(2)
String mod_pak; String mod_pak;
@HiveField(3)
String mod_hash;
bool newMod = false; bool newMod = false;
String _id = ""; String _id = "";
String mod_instance_id() { String mod_instance_id() {
@ -28,5 +31,6 @@ class Mod {
{this.mod_name = "undef", {this.mod_name = "undef",
this.mod_id = 0, this.mod_id = 0,
this.newMod = false, this.newMod = false,
this.mod_pak = "Not Initialized"}); this.mod_pak = "Not Initialized",
this.mod_hash = ""});
} }

23
lib/pathtools.dart Normal file
View file

@ -0,0 +1,23 @@
import 'dart:io';
class PathHelper {
String pth = "";
PathHelper({required this.pth});
static String combine(String path1, String path2) {
return path1 + Platform.pathSeparator + path2;
}
static PathHelper builder(String startPath) {
return PathHelper(pth: startPath);
}
PathHelper resolve(String path2) {
pth += Platform.pathSeparator + path2;
return this;
}
String build() {
return pth;
}
}

View file

@ -42,6 +42,7 @@ dependencies:
dio: dio:
mc_rcon_dart: mc_rcon_dart:
uuid: ^4.1.0 uuid: ^4.1.0
crypto:
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: