Refactor: Fix slow initial server start

Moved hashing to first update check
This commit is contained in:
zontreck 2025-01-04 17:50:10 -07:00
parent 48ffb70544
commit 317df007d4
7 changed files with 30 additions and 13 deletions

View file

@ -1 +1 @@
1.1.010425.1723 1.1.010425.1748

View file

@ -83,7 +83,7 @@ void main() async {
await doDownloadMods(false); await doDownloadMods(false);
print("Scanning mods..."); print("Scanning mods...");
settings.inst!.mods = await doScanMods(false); settings.inst!.mods = await doScanMods(false, computeHashes: false);
settings.Write(); settings.Write();
print("Starting scheduler..."); print("Starting scheduler...");

View file

@ -1,5 +1,5 @@
class Consts { class Consts {
static const VERSION = "1.1.010425.1723"; static const VERSION = "1.1.010425.1748";
static const MF_VER_URL = static const MF_VER_URL =
"https://git.zontreck.com/AriasCreations/ConanServerManager/raw/branch/master/MASTER_FILE"; "https://git.zontreck.com/AriasCreations/ConanServerManager/raw/branch/master/MASTER_FILE";
} }

View file

@ -42,7 +42,7 @@ Future<void> doDownloadMods(bool jail) async {
settings.isDownloadingMods = false; settings.isDownloadingMods = false;
} }
Future<List<Mod>> doScanMods(bool jail) async { Future<List<Mod>> doScanMods(bool jail, {bool computeHashes = false}) async {
Settings settings = Settings(); Settings settings = Settings();
List<Mod> ret = []; List<Mod> ret = [];
@ -68,16 +68,19 @@ Future<List<Mod>> doScanMods(bool jail) async {
await for (var entity in dir.list()) { await for (var entity in dir.list()) {
if (entity is File && entity.path.endsWith("pak")) { if (entity is File && entity.path.endsWith("pak")) {
String name = entity.path.split(Platform.pathSeparator).last; String name = entity.path.split(Platform.pathSeparator).last;
String hash = "";
if (jail || computeHashes) {
var content = await entity.readAsBytes(); var content = await entity.readAsBytes();
var data = md5.convert(content); var data = md5.convert(content);
var hash = data.toString(); hash = data.toString();
//M.mod_pak = name; //M.mod_pak = name;
//M.mod_hash = hash; //M.mod_hash = hash;
print("Discovered mod file: $name"); print("Discovered mod file: $name");
print("Hash: $hash"); print("Hash: $hash");
}
// Update the mod instance, and retain the original modlist order // Update the mod instance, and retain the original modlist order
ret.add(Mod( ret.add(Mod(

View file

@ -350,7 +350,19 @@ class StateMachine {
timer.cancel(); timer.cancel();
await doDownloadMods(true); await doDownloadMods(true);
List<Mod> currentMods = await doScanMods(true); if (SessionData.IS_FIRST_MOD_CHECK) {
List<Mod> actualMods =
await doScanMods(false, computeHashes: true);
settings.inst!.mods = actualMods;
settings
.Write(); // Write the settings file to disk after this scan has completed.
SessionData.IS_FIRST_MOD_CHECK = false;
}
List<Mod> currentMods =
await doScanMods(true, computeHashes: true);
List<String> updatedMods = []; List<String> updatedMods = [];
for (int i = 0; i < currentMods.length; i++) { for (int i = 0; i < currentMods.length; i++) {
Mod currentMod = settings.inst!.mods[i]; Mod currentMod = settings.inst!.mods[i];

View file

@ -45,4 +45,6 @@ class SessionData {
/// ///
/// Use the [Settings.getWorldSnapshotFiles] function instead /// Use the [Settings.getWorldSnapshotFiles] function instead
static List<String> IE_SNAPSHOTS = []; static List<String> IE_SNAPSHOTS = [];
static bool IS_FIRST_MOD_CHECK = true;
} }

View file

@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 1.1.010425+1723 version: 1.1.010425+1748
environment: environment:
sdk: ">=3.1.4 <4.0.0" sdk: ">=3.1.4 <4.0.0"