From 317df007d418afcad444cf0e44ca4dac83eded08 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 4 Jan 2025 17:50:10 -0700 Subject: [PATCH] Refactor: Fix slow initial server start Moved hashing to first update check --- MASTER_FILE | 2 +- bin/server.dart | 2 +- lib/consts.dart | 2 +- lib/game.dart | 19 +++++++++++-------- lib/statemachine.dart | 14 +++++++++++++- lib/structs/SessionData.dart | 2 ++ pubspec.yaml | 2 +- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/MASTER_FILE b/MASTER_FILE index d0e309b..18e9e5f 100644 --- a/MASTER_FILE +++ b/MASTER_FILE @@ -1 +1 @@ -1.1.010425.1723 \ No newline at end of file +1.1.010425.1748 \ No newline at end of file diff --git a/bin/server.dart b/bin/server.dart index c9606f8..1bb5724 100644 --- a/bin/server.dart +++ b/bin/server.dart @@ -83,7 +83,7 @@ void main() async { await doDownloadMods(false); print("Scanning mods..."); - settings.inst!.mods = await doScanMods(false); + settings.inst!.mods = await doScanMods(false, computeHashes: false); settings.Write(); print("Starting scheduler..."); diff --git a/lib/consts.dart b/lib/consts.dart index acfb12e..5feff6b 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -1,5 +1,5 @@ class Consts { - static const VERSION = "1.1.010425.1723"; + static const VERSION = "1.1.010425.1748"; static const MF_VER_URL = "https://git.zontreck.com/AriasCreations/ConanServerManager/raw/branch/master/MASTER_FILE"; } diff --git a/lib/game.dart b/lib/game.dart index 171da88..e299a61 100644 --- a/lib/game.dart +++ b/lib/game.dart @@ -42,7 +42,7 @@ Future doDownloadMods(bool jail) async { settings.isDownloadingMods = false; } -Future> doScanMods(bool jail) async { +Future> doScanMods(bool jail, {bool computeHashes = false}) async { Settings settings = Settings(); List ret = []; @@ -68,16 +68,19 @@ Future> doScanMods(bool jail) async { await for (var entity in dir.list()) { if (entity is File && entity.path.endsWith("pak")) { String name = entity.path.split(Platform.pathSeparator).last; + String hash = ""; - var content = await entity.readAsBytes(); - var data = md5.convert(content); - var hash = data.toString(); + if (jail || computeHashes) { + var content = await entity.readAsBytes(); + var data = md5.convert(content); + hash = data.toString(); - //M.mod_pak = name; - //M.mod_hash = hash; + //M.mod_pak = name; + //M.mod_hash = hash; - print("Discovered mod file: $name"); - print("Hash: $hash"); + print("Discovered mod file: $name"); + print("Hash: $hash"); + } // Update the mod instance, and retain the original modlist order ret.add(Mod( diff --git a/lib/statemachine.dart b/lib/statemachine.dart index 359e284..60107d1 100644 --- a/lib/statemachine.dart +++ b/lib/statemachine.dart @@ -350,7 +350,19 @@ class StateMachine { timer.cancel(); await doDownloadMods(true); - List currentMods = await doScanMods(true); + if (SessionData.IS_FIRST_MOD_CHECK) { + List 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 currentMods = + await doScanMods(true, computeHashes: true); List updatedMods = []; for (int i = 0; i < currentMods.length; i++) { Mod currentMod = settings.inst!.mods[i]; diff --git a/lib/structs/SessionData.dart b/lib/structs/SessionData.dart index 1f55719..2bd829f 100644 --- a/lib/structs/SessionData.dart +++ b/lib/structs/SessionData.dart @@ -45,4 +45,6 @@ class SessionData { /// /// Use the [Settings.getWorldSnapshotFiles] function instead static List IE_SNAPSHOTS = []; + + static bool IS_FIRST_MOD_CHECK = true; } diff --git a/pubspec.yaml b/pubspec.yaml index c8723c4..cfd4db1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 # 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. -version: 1.1.010425+1723 +version: 1.1.010425+1748 environment: sdk: ">=3.1.4 <4.0.0"