Get things to a semi-stable state
This commit is contained in:
parent
3742a957bb
commit
d8345d08fa
4 changed files with 74 additions and 4 deletions
|
@ -1,7 +1,9 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:servermanager/mod.dart';
|
||||
import 'package:servermanager/pathtools.dart';
|
||||
import 'package:servermanager/settings.dart';
|
||||
|
||||
class GameServerPage extends StatefulWidget {
|
||||
|
@ -109,8 +111,8 @@ class GameServerPageState extends State<GameServerPage> {
|
|||
settings.inst!.steam_creds!.secret
|
||||
]);
|
||||
var code = result.stdout as String;
|
||||
// Build download command
|
||||
|
||||
// Build download command
|
||||
List<String> manifest = [
|
||||
"+@sSteamCmdForcePlatformType",
|
||||
"windows",
|
||||
|
@ -131,8 +133,8 @@ class GameServerPageState extends State<GameServerPage> {
|
|||
|
||||
manifest.add("+quit");
|
||||
|
||||
print(
|
||||
"Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}");
|
||||
//print(
|
||||
// "Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}");
|
||||
|
||||
result =
|
||||
await Process.run(settings.getSteamCmd(), manifest);
|
||||
|
@ -143,6 +145,40 @@ class GameServerPageState extends State<GameServerPage> {
|
|||
setState(() {
|
||||
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(
|
||||
|
@ -266,6 +302,7 @@ class ModPage extends StatelessWidget {
|
|||
bool isNewMod = false;
|
||||
bool willDelete = false;
|
||||
String pak = "Not initialized";
|
||||
String hash = "";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -279,6 +316,7 @@ class ModPage extends StatelessWidget {
|
|||
isNewMod = args.newMod;
|
||||
instance = args.mod_instance_id();
|
||||
pak = args.mod_pak;
|
||||
hash = args.mod_hash;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,6 +379,10 @@ class ModPage extends StatelessWidget {
|
|||
subtitle:
|
||||
Text("Mod pak file name as detected during downloading"),
|
||||
),
|
||||
ListTile(
|
||||
title: Text("Mod Hash"),
|
||||
subtitle: Text("$hash"),
|
||||
),
|
||||
if (!isNewMod)
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
|
|
|
@ -14,6 +14,9 @@ class Mod {
|
|||
@HiveField(2)
|
||||
String mod_pak;
|
||||
|
||||
@HiveField(3)
|
||||
String mod_hash;
|
||||
|
||||
bool newMod = false;
|
||||
String _id = "";
|
||||
String mod_instance_id() {
|
||||
|
@ -28,5 +31,6 @@ class Mod {
|
|||
{this.mod_name = "undef",
|
||||
this.mod_id = 0,
|
||||
this.newMod = false,
|
||||
this.mod_pak = "Not Initialized"});
|
||||
this.mod_pak = "Not Initialized",
|
||||
this.mod_hash = ""});
|
||||
}
|
||||
|
|
23
lib/pathtools.dart
Normal file
23
lib/pathtools.dart
Normal 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;
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@ dependencies:
|
|||
dio:
|
||||
mc_rcon_dart:
|
||||
uuid: ^4.1.0
|
||||
crypto:
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue