Skip to content

Commit 1ae49de

Browse files
refactor: Move functions to dedicated file (#41)
Only a single function for now as a sort of proof-of-concept.
1 parent 1674b0b commit 1ae49de

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

src-tauri/src/lib.rs

-29
Original file line numberDiff line numberDiff line change
@@ -449,35 +449,6 @@ pub fn get_enabled_mods(game_install: GameInstall) -> Result<serde_json::value::
449449
Ok(res)
450450
}
451451

452-
/// Set the status of a passed mod to enabled/disabled
453-
pub fn set_mod_enabled_status(
454-
game_install: GameInstall,
455-
mod_name: String,
456-
is_enabled: bool,
457-
) -> Result<(), String> {
458-
let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path);
459-
460-
// Parse JSON
461-
let mut res: serde_json::Value = get_enabled_mods(game_install)?;
462-
463-
// Check if key exists
464-
if res.get(mod_name.clone()).is_none() {
465-
return Err("Value not found in enabledmod.json".to_string());
466-
}
467-
468-
// Update value
469-
res[mod_name] = serde_json::Value::Bool(is_enabled);
470-
471-
// Save the JSON structure into the output file
472-
std::fs::write(
473-
enabledmods_json_path,
474-
serde_json::to_string_pretty(&res).unwrap(),
475-
)
476-
.unwrap();
477-
478-
Ok(())
479-
}
480-
481452
/// Gets list of installed mods and their properties
482453
/// - name
483454
/// - is enabled?

src-tauri/src/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ use app::{
1313
check_is_flightcore_outdated, check_is_valid_game_path, check_northstar_running,
1414
check_origin_running, convert_release_candidate_number, find_game_install_location,
1515
get_enabled_mods, get_host_os, get_installed_mods_and_properties, get_log_list, get_northstar_version_number,
16-
install_northstar, launch_northstar, linux_checks_librs, set_mod_enabled_status, GameInstall, NorthstarMod,
16+
install_northstar, launch_northstar, linux_checks_librs, GameInstall, NorthstarMod,
1717
};
1818

1919
mod repair_and_verify;
2020
use repair_and_verify::{verify_game_files, disable_all_but_core};
2121

22+
mod mod_management;
23+
use mod_management::set_mod_enabled_status;
24+
2225
use tauri::Manager;
2326
use tauri_plugin_store::PluginBuilder;
2427
use tokio::time::sleep;

src-tauri/src/mod_management/mod.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This file contains various mod management functions
2+
3+
use app::GameInstall;
4+
use app::get_enabled_mods;
5+
6+
/// Set the status of a passed mod to enabled/disabled
7+
pub fn set_mod_enabled_status(
8+
game_install: GameInstall,
9+
mod_name: String,
10+
is_enabled: bool,
11+
) -> Result<(), String> {
12+
let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path);
13+
14+
// Parse JSON
15+
let mut res: serde_json::Value = get_enabled_mods(game_install)?;
16+
17+
// Check if key exists
18+
if res.get(mod_name.clone()).is_none() {
19+
return Err("Value not found in enabledmod.json".to_string());
20+
}
21+
22+
// Update value
23+
res[mod_name] = serde_json::Value::Bool(is_enabled);
24+
25+
// Save the JSON structure into the output file
26+
std::fs::write(
27+
enabledmods_json_path,
28+
serde_json::to_string_pretty(&res).unwrap(),
29+
)
30+
.unwrap();
31+
32+
Ok(())
33+
}

src-tauri/src/repair_and_verify/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Contains various functions to repair common issues and verifying installation
22
3-
use app::{get_enabled_mods, set_mod_enabled_status, GameInstall};
3+
use app::{get_enabled_mods, GameInstall};
4+
use crate::mod_management::set_mod_enabled_status;
45

56
/// Verifies Titanfall2 game files
67
pub fn verify_game_files(game_install: GameInstall) -> Result<String, String> {

0 commit comments

Comments
 (0)