Skip to content

Commit

Permalink
refactor: Move repair/verify related funcs to mod (#622)
Browse files Browse the repository at this point in the history
Moves functions related to game install path verification checks to dedicated module in an effort to clean up `main.rs`
  • Loading branch information
GeckoEidechse authored Oct 13, 2023
1 parent 04c5ada commit 97d4773
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/github/pull_requests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::github::release_notes::fetch_github_releases_api;

use crate::check_is_valid_game_path;
use crate::constants::{APP_USER_AGENT, PULLS_API_ENDPOINT_LAUNCHER, PULLS_API_ENDPOINT_MODS};
use crate::repair_and_verify::check_is_valid_game_path;
use crate::GameInstall;
use anyhow::anyhow;
use serde::{Deserialize, Serialize};
Expand Down
27 changes: 1 addition & 26 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn main() {
get_flightcore_version_number,
northstar::get_northstar_version_number,
check_is_northstar_outdated,
verify_install_location,
repair_and_verify::verify_install_location,
platform_specific::get_host_os,
northstar::install::install_northstar_wrapper,
northstar::install::update_northstar,
Expand Down Expand Up @@ -266,18 +266,6 @@ async fn check_is_northstar_outdated(
}
}

/// Checks if is valid Titanfall2 install based on certain conditions
#[tauri::command]
async fn verify_install_location(game_path: String) -> bool {
match check_is_valid_game_path(&game_path) {
Ok(()) => true,
Err(err) => {
log::warn!("{}", err);
false
}
}
}

/// Installs the specified mod
#[tauri::command]
async fn install_mod_wrapper(
Expand Down Expand Up @@ -418,16 +406,3 @@ pub struct NorthstarMod {
pub enabled: bool,
pub directory: String,
}

/// Checks whether the provided path is a valid Titanfall2 gamepath by checking against a certain set of criteria
pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> {
let path_to_titanfall2_exe = format!("{game_install_path}/Titanfall2.exe");
let is_correct_game_path = std::path::Path::new(&path_to_titanfall2_exe).exists();
log::info!("Titanfall2.exe exists in path? {}", is_correct_game_path);

// Exit early if wrong game path
if !is_correct_game_path {
return Err(format!("Incorrect game path \"{game_install_path}\"")); // Return error cause wrong game path
}
Ok(())
}
2 changes: 1 addition & 1 deletion src-tauri/src/platform_specific/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{anyhow, Result};
#[cfg(target_os = "windows")]
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};

use crate::check_is_valid_game_path;
use crate::repair_and_verify::check_is_valid_game_path;

/// Gets Titanfall2 install location on Origin
pub fn origin_install_location_detection() -> Result<String, anyhow::Error> {
Expand Down
25 changes: 25 additions & 0 deletions src-tauri/src/repair_and_verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ use crate::mod_management::{get_enabled_mods, rebuild_enabled_mods_json, set_mod
/// Contains various functions to repair common issues and verifying installation
use crate::{constants::CORE_MODS, GameInstall};

/// Checks if is valid Titanfall2 install based on certain conditions
#[tauri::command]
pub async fn verify_install_location(game_path: String) -> bool {
match check_is_valid_game_path(&game_path) {
Ok(()) => true,
Err(err) => {
log::warn!("{}", err);
false
}
}
}

/// Checks whether the provided path is a valid Titanfall2 gamepath by checking against a certain set of criteria
pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> {
let path_to_titanfall2_exe = format!("{game_install_path}/Titanfall2.exe");
let is_correct_game_path = std::path::Path::new(&path_to_titanfall2_exe).exists();
log::info!("Titanfall2.exe exists in path? {}", is_correct_game_path);

// Exit early if wrong game path
if !is_correct_game_path {
return Err(format!("Incorrect game path \"{game_install_path}\"")); // Return error cause wrong game path
}
Ok(())
}

/// Verifies Titanfall2 game files
#[tauri::command]
pub fn verify_game_files(game_install: GameInstall) -> Result<String, String> {
Expand Down

0 comments on commit 97d4773

Please sign in to comment.