fix: actually respect the auto-update configuration

This commit is contained in:
beerpiss 2024-06-27 00:49:00 +07:00
parent 8a0507f03c
commit 2abbd7b79d
2 changed files with 18 additions and 17 deletions

View File

@ -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:#}");
}
});

View File

@ -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<String> = OnceLock::new();
static CONFIG: OnceLock<SaekawaConfig> = 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);
}