From 2abbd7b79d2d4f9ad4b06722f16e303213b47c8c Mon Sep 17 00:00:00 2001 From: beerpiss Date: Thu, 27 Jun 2024 00:49:00 +0700 Subject: [PATCH] fix: actually respect the auto-update configuration --- src/lib.rs | 15 +-------------- src/saekawa.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9633957..dc116e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,6 @@ use crate::{ helpers::winapi_ext::LibraryHandle, logging::init_logger, saekawa::{hook_init, hook_release}, - updater::self_update, }; #[no_mangle] @@ -45,19 +44,7 @@ extern "system" fn DllMain(dll_module: HINSTANCE, call_reason: DWORD, reserved: env!("VERGEN_GIT_BRANCH"), ); - match self_update(&library_handle) { - Ok(should_reboot) => { - if should_reboot { - info!("Self-update successful. Reloading into new hook..."); - library_handle.free_and_exit_thread(1); - } - } - Err(e) => { - error!("Self-update failed: {e:#}"); - } - } - - if let Err(e) = hook_init() { + if let Err(e) = hook_init(library_handle) { error!("Failed to initialize hook: {e:#}"); } }); diff --git a/src/saekawa.rs b/src/saekawa.rs index 4b30301..4c31038 100644 --- a/src/saekawa.rs +++ b/src/saekawa.rs @@ -25,11 +25,11 @@ use crate::{ config::{ConfigLoadError, SaekawaConfig}, helpers::{ chuni_encoding::{decrypt_aes256_cbc, hash_endpoint, maybe_decompress_buffer}, - winapi_ext::{winhttp_query_option, ReadStringFnError}, + winapi_ext::{winhttp_query_option, LibraryHandle, ReadStringFnError}, }, score_import::execute_score_import, sigscan::{self, CryptoKeys}, - types::{chuni::UpsertUserAllRequest, ToBatchManual}, + types::{chuni::UpsertUserAllRequest, ToBatchManual}, updater::self_update, }; #[derive(Debug, Snafu)] @@ -96,10 +96,24 @@ static UPSERT_USER_ALL_API: OnceLock = OnceLock::new(); static CONFIG: OnceLock = OnceLock::new(); -pub fn hook_init() -> Result<(), HookError> { +pub fn hook_init(library_handle: LibraryHandle) -> Result<(), HookError> { debug!("Reading hook configuration"); let config = SaekawaConfig::load().context(ConfigSnafu)?; + if config.general.auto_update { + match self_update(&library_handle) { + Ok(should_reboot) => { + if should_reboot { + info!("Self-update successful. Reloading into new hook..."); + library_handle.free_and_exit_thread(1); + } + } + Err(e) => { + error!("Self-update failed: {e:#}"); + } + } + } + if config.cards.is_empty() { return Err(HookError::NoCardsError); }