Skip to content

Commit

Permalink
refactor: Replace all println!() with log statements (#236)
Browse files Browse the repository at this point in the history
* refactor: Replace all println with calls to logger
in `do_install()`

* refactor: Replace all println with calls to logger
in `verify_install_location()`

* refactor: Replace all println with calls to logger
in `get_northstar_release_notes()`

* refactor: Replace all println with calls to logger
in `update_northstar_caller()`

* refactor: Replace all println with calls to logger
in `install_northstar_caller()`

* refactor: Replace all println with calls to logger
in `apply_launcher_pr()`

* refactor: Replace all println with calls to logger
in `apply_mods_pr()`

* refactor: Replace all println with calls to logger
in `find_game_install_location()`

* refactor: Replace all println with calls to logger
in `install_mod_caller()`

* refactor: Replace all println with calls to logger
in `set_mod_enabled_status()`

* refactor: Replace all println with calls to logger
in `parse_installed_mods()`

* refactor: Replace all println with calls to logger
in `origin_install_location_detection()`

* refactor: Replace all println with calls to logger
in `query_thunderstore_packages_api()`

* refactor: Replace all println with calls to logger
in `add_batch_file()`

* refactor: Replace all println with calls to logger
in `extract()`

* refactor: Replace all println with calls to logger
in `check_is_northstar_outdated()`
  • Loading branch information
GeckoEidechse authored Mar 26, 2023
1 parent 91c1dbb commit fe3cb82
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src-tauri/src/github/pull_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn add_batch_file(game_install_path: &str) {

match file.write_all(batch_file_content.as_bytes()) {
Err(why) => panic!("couldn't write to {}: {}", display, why),
Ok(_) => println!("successfully wrote to {}", display),
Ok(_) => log::info!("successfully wrote to {}", display),
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ pub async fn apply_launcher_pr(
}
}

println!("All done with installing launcher PR");
log::info!("All done with installing launcher PR");
Ok(())
}

Expand Down Expand Up @@ -309,9 +309,9 @@ pub async fn apply_mods_pr(
// Delete previously managed folder
if std::fs::remove_dir_all(profile_folder.clone()).is_err() {
if std::path::Path::new(&profile_folder).exists() {
println!("Failed removing previous dir");
log::error!("Failed removing previous dir");
} else {
println!("Failed removing folder that doesn't exist. Probably cause first run");
log::warn!("Failed removing folder that doesn't exist. Probably cause first run");
}
};

Expand All @@ -331,6 +331,6 @@ pub async fn apply_mods_pr(
// Add batch file to launch right profile
add_batch_file(game_install_path);

println!("All done with installing mods PR");
log::info!("All done with installing mods PR");
Ok(())
}
2 changes: 1 addition & 1 deletion src-tauri/src/github/release_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub async fn get_northstar_release_notes() -> Result<Vec<ReleaseInfo>, String> {

let release_info_vector: Vec<ReleaseInfo> =
serde_json::from_str(&res).expect("JSON was not well-formatted");
println!("Done checking GitHub API");
log::info!("Done checking GitHub API");

return Ok(release_info_vector);
}
18 changes: 9 additions & 9 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ pub fn find_game_install_location() -> Result<GameInstall, String> {
};
return Ok(game_install);
}
None => println!("Couldn't locate Titanfall2"),
None => log::info!("Couldn't locate Titanfall2 Steam instal"),
}
}
None => println!("Couldn't locate Steam on this computer!"),
None => log::info!("Couldn't locate Steam on this computer!"),
}

// (On Windows only) try parsing Windows registry for Origin install path
Expand All @@ -119,7 +119,7 @@ pub fn find_game_install_location() -> Result<GameInstall, String> {
return Ok(game_install);
}
Err(err) => {
println!("{}", err);
log::info!("{}", err);
}
};

Expand Down Expand Up @@ -157,7 +157,7 @@ fn extract(zip_file: std::fs::File, target: &std::path::Path) -> Result<()> {
);

if (*f.name()).ends_with('/') {
println!("Create directory {}", f.name());
log::info!("Create directory {}", f.name());
std::fs::create_dir_all(target.join(f.name()))
.context("Unable to create directory")?;
continue;
Expand All @@ -171,7 +171,7 @@ fn extract(zip_file: std::fs::File, target: &std::path::Path) -> Result<()> {
.truncate(true)
.open(&out)?;

println!("Write file {}", out.display());
log::info!("Write file {}", out.display());

std::io::copy(&mut f, &mut outfile).context("Unable to write to file")?;
}
Expand All @@ -191,18 +191,18 @@ async fn do_install(nmod: &thermite::model::ModVersion, game_path: &std::path::P
std::fs::create_dir_all(download_directory.clone())?;

let download_path = format!("{}/{}", download_directory.clone(), filename);
println!("{download_path}");
log::info!("Download path: {download_path}");

let nfile = thermite::core::manage::download_file(&nmod.url, download_path).unwrap();

println!("Extracting Northstar...");
log::info!("Extracting Northstar...");
extract(nfile, game_path)?;

// Delete old copy
println!("Delete temp folder again");
log::info!("Delete temp folder again");
std::fs::remove_dir_all(download_directory).unwrap();

println!("Done!");
log::info!("Done installing Northstar!");

Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async fn check_is_northstar_outdated(
let version_number = match get_northstar_version_number(game_path) {
Ok(version_number) => version_number,
Err(err) => {
println!("{}", err);
log::warn!("{}", err);
// If we fail to get new version just assume we are up-to-date
return Err(err.to_string());
}
Expand Down Expand Up @@ -266,7 +266,7 @@ async fn verify_install_location(game_path: String) -> bool {
match check_is_valid_game_path(&game_path) {
Ok(()) => true,
Err(err) => {
println!("{}", err);
log::warn!("{}", err);
false
}
}
Expand All @@ -284,11 +284,11 @@ async fn install_northstar_caller(
game_path: String,
northstar_package_name: Option<String>,
) -> Result<bool, String> {
println!("Running");
log::info!("Running");
match install_northstar(&game_path, northstar_package_name).await {
Ok(_) => Ok(true),
Err(err) => {
println!("{}", err);
log::error!("{}", err);
Err(err.to_string())
}
}
Expand All @@ -300,13 +300,13 @@ async fn update_northstar_caller(
game_path: String,
northstar_package_name: Option<String>,
) -> Result<bool, String> {
println!("Updating");
log::info!("Updating Northstar");

// Simply re-run install with up-to-date version for upate
match install_northstar(&game_path, northstar_package_name).await {
Ok(_) => Ok(true),
Err(err) => {
println!("{}", err);
log::error!("{}", err);
Err(err.to_string())
}
}
Expand All @@ -331,7 +331,7 @@ async fn install_mod_caller(
match clean_up_download_folder(game_install, false) {
Ok(()) => Ok(()),
Err(err) => {
println!("Failed to delete download folder due to {}", err);
log::info!("Failed to delete download folder due to {}", err);
// Failure to delete download folder is not an error in mod install
// As such ignore. User can still force delete if need be
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/mod_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub fn set_mod_enabled_status(
let mut res: serde_json::Value = match get_enabled_mods(game_install.clone()) {
Ok(res) => res,
Err(err) => {
println!("Couldn't parse `enabledmod.json`: {}", err);
println!("Rebuilding file.");
log::warn!("Couldn't parse `enabledmod.json`: {}", err);
log::warn!("Rebuilding file.");

rebuild_enabled_mods_json(game_install.clone())?;

Expand All @@ -108,7 +108,7 @@ pub fn set_mod_enabled_status(
// Check if key exists
if res.get(mod_name.clone()).is_none() {
// If it doesn't exist, rebuild `enabledmod.json`
println!("Value not found in `enabledmod.json`. Rebuilding file");
log::info!("Value not found in `enabledmod.json`. Rebuilding file");
rebuild_enabled_mods_json(game_install.clone())?;

// Then try again
Expand Down Expand Up @@ -189,7 +189,7 @@ fn parse_installed_mods(game_install: GameInstall) -> Result<Vec<NorthstarMod>,
let parsed_mod_json: ModJson = match json5::from_str(&data) {
Ok(parsed_json) => parsed_json,
Err(err) => {
println!("Failed parsing {} with {}", mod_json_path, err.to_string());
log::warn!("Failed parsing {} with {}", mod_json_path, err.to_string());
continue;
}
};
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/platform_specific/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub fn origin_install_location_detection() -> Result<String, anyhow::Error> {
return Ok(game_path_str.to_string());
}
Err(err) => {
println!("{}", err);
log::warn!("{}", err);
continue; // Not a valid game path
}
}
}
}
Err(err) => {
println!("Couldn't find {origin_id}: {err}")
log::warn!("Couldn't find {origin_id}: {err}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/thunderstore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct ThunderstoreModVersion {
/// Queries Thunderstore packages API
#[tauri::command]
pub async fn query_thunderstore_packages_api() -> Result<Vec<ThunderstoreMod>, String> {
println!("Fetching Thunderstore API");
log::info!("Fetching Thunderstore API");

// Fetches
let url = "https://northstar.thunderstore.io/api/v1/package/";
Expand Down

0 comments on commit fe3cb82

Please sign in to comment.