Skip to content

Commit

Permalink
fix small bugs, add better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr1Furious committed Oct 13, 2024
1 parent ce5d17a commit b1ca0a0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
2 changes: 1 addition & 1 deletion launcher/src/app/auth_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
57 changes: 51 additions & 6 deletions launcher/src/config/runtime_config.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions launcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 4 additions & 3 deletions launcher/src/version/merged_version_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions launcher/src/version/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit b1ca0a0

Please sign in to comment.