Skip to content

Commit

Permalink
refactor: Move install_mod_wrapper (#627)
Browse files Browse the repository at this point in the history
Move `install_mod_wrapper` to `mod_management` module to clean up `main.rs`.
  • Loading branch information
GeckoEidechse authored Oct 13, 2023
1 parent b58d8d1 commit fbaa5d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
27 changes: 1 addition & 26 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn main() {
github::release_notes::get_northstar_release_notes,
platform_specific::linux_checks,
mod_management::get_installed_mods_and_properties,
install_mod_wrapper,
mod_management::install_mod_wrapper,
clean_up_download_folder_wrapper,
github::release_notes::get_newest_flightcore_version,
mod_management::delete_northstar_mod,
Expand Down Expand Up @@ -202,31 +202,6 @@ pub fn convert_release_candidate_number(version_number: String) -> String {
version_number.replace("-rc", "0").replace("00", "")
}

/// Installs the specified mod
#[tauri::command]
async fn install_mod_wrapper(
game_install: GameInstall,
thunderstore_mod_string: String,
) -> Result<(), String> {
match mod_management::fc_download_mod_and_install(&game_install, &thunderstore_mod_string).await
{
Ok(()) => (),
Err(err) => {
log::warn!("{err}");
return Err(err);
}
};
match repair_and_verify::clean_up_download_folder(&game_install, false) {
Ok(()) => Ok(()),
Err(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(())
}
}
}

/// Installs the specified mod
#[tauri::command]
async fn clean_up_download_folder_wrapper(
Expand Down
24 changes: 24 additions & 0 deletions src-tauri/src/mod_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ impl std::ops::Deref for TempFile {
}
}

/// Installs the specified mod
#[tauri::command]
pub async fn install_mod_wrapper(
game_install: GameInstall,
thunderstore_mod_string: String,
) -> Result<(), String> {
match fc_download_mod_and_install(&game_install, &thunderstore_mod_string).await {
Ok(()) => (),
Err(err) => {
log::warn!("{err}");
return Err(err);
}
};
match crate::repair_and_verify::clean_up_download_folder(&game_install, false) {
Ok(()) => Ok(()),
Err(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(())
}
}
}

/// Returns a serde json object of the parsed `enabledmods.json` file
pub fn get_enabled_mods(game_install: &GameInstall) -> Result<serde_json::value::Value, String> {
let enabledmods_json_path = format!(
Expand Down

0 comments on commit fbaa5d7

Please sign in to comment.