diff --git a/launcher/src/app/auth_state.rs b/launcher/src/app/auth_state.rs index cc6bc73..2fb3031 100644 --- a/launcher/src/app/auth_state.rs +++ b/launcher/src/app/auth_state.rs @@ -227,7 +227,7 @@ impl AuthState { } pub fn reset_auth_if_needed(&mut self, new_auth_data: &AuthData) { - if self.runtime_auth.contains_key(&new_auth_data.get_id()) { + if !self.runtime_auth.contains_key(&new_auth_data.get_id()) { self.auth_status = AuthStatus::NotAuthorized; self.auth_task = None; } diff --git a/launcher/src/config/runtime_config.rs b/launcher/src/config/runtime_config.rs index eebd198..10eed29 100644 --- a/launcher/src/config/runtime_config.rs +++ b/launcher/src/config/runtime_config.rs @@ -1,7 +1,11 @@ +use env_logger::Builder; +use log::LevelFilter; use serde::{Deserialize, Serialize}; -use shared::version::extra_version_metadata::AuthData; -use std::collections::HashMap; +use shared::{paths::get_logs_dir, version::extra_version_metadata::AuthData}; +use std::io::Write; use std::path::PathBuf; +use std::sync::Mutex; +use std::{collections::HashMap, fs::OpenOptions}; use super::build_config; use crate::{auth::base::UserInfo, constants, lang::Lang}; @@ -44,11 +48,52 @@ pub fn get_launcher_dir(config: &Config) -> PathBuf { data_dir } -fn get_config_path() -> PathBuf { - let data_dir = dirs::data_dir().expect("Failed to get data directory"); +fn get_data_dir() -> PathBuf { + let data_dir = dirs::data_dir() + .expect("Failed to get data directory") + .join(build_config::get_data_launcher_name()); + if !data_dir.exists() { + std::fs::create_dir_all(&data_dir).expect("Failed to create data directory"); + } data_dir - .join(build_config::get_data_launcher_name()) - .join("config.json") +} + +const CONFIG_FILENAME: &str = "config.json"; + +fn get_config_path() -> PathBuf { + get_data_dir().join(CONFIG_FILENAME) +} + +const LOGS_FILENAME: &str = "launcher.log"; + +fn get_logs_path() -> PathBuf { + let logs_dir = get_logs_dir(&get_data_dir()); + if !logs_dir.exists() { + std::fs::create_dir_all(&logs_dir).expect("Failed to create logs directory"); + } + logs_dir.join(LOGS_FILENAME) +} + +pub fn setup_logger() { + let log_file = OpenOptions::new() + .create(true) + .write(true) + .append(true) + .open(get_logs_path()) + .unwrap(); + + let log_file = Mutex::new(log_file); + + let mut builder = Builder::new(); + builder.filter(None, LevelFilter::Info); + + builder.format(move |buf, record| { + let mut log_file = log_file.lock().unwrap(); + writeln!(log_file, "{} - {}", record.level(), record.args()).unwrap(); + writeln!(buf, "{} - {}", record.level(), record.args()) + }); + + builder.init(); } pub fn get_assets_dir(config: &Config) -> PathBuf { diff --git a/launcher/src/main.rs b/launcher/src/main.rs index e640294..4af1b5b 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -11,16 +11,14 @@ mod update_app; mod utils; mod version; -use config::runtime_config; +use config::runtime_config::{self, setup_logger}; +use utils::set_sigint_handler; fn main() { - env_logger::init(); - - utils::set_sigint_handler(); + set_sigint_handler(); + setup_logger(); let config = runtime_config::load_config(); - update_app::app::run_gui(&config); - app::app::run_gui(config); } diff --git a/launcher/src/version/merged_version_metadata.rs b/launcher/src/version/merged_version_metadata.rs index 01f9929..366b3df 100644 --- a/launcher/src/version/merged_version_metadata.rs +++ b/launcher/src/version/merged_version_metadata.rs @@ -66,9 +66,10 @@ fn merge_two_metadata( parent_metadata.arguments.game = arguments.game; } - let parent_id = parent_metadata.id.clone(); - parent_metadata.hierarchy_ids.push(parent_id); - parent_metadata.id = child_metadata.id.clone(); + parent_metadata + .hierarchy_ids + .push(child_metadata.id.clone()); + parent_metadata.id = child_metadata.id; if let Some(java_version) = child_metadata.java_version { parent_metadata.java_version = java_version; diff --git a/launcher/src/version/sync.rs b/launcher/src/version/sync.rs index 902013a..cdf60da 100644 --- a/launcher/src/version/sync.rs +++ b/launcher/src/version/sync.rs @@ -275,10 +275,16 @@ pub async fn sync_modpack( .get_check_downloads(&assets_dir, version_metadata.get_resources_url_base())?, ); + info!( + "Got {} check download entries", + check_download_entries.len() + ); progress_bar.set_message(LangMessage::CheckingFiles); let download_entries = files::get_download_entries(check_download_entries, progress_bar.clone()).await?; + info!("Got {} download entries", download_entries.len()); + let libraries_changed = download_entries .iter() .any(|entry| entry.path.starts_with(&libraries_dir));