diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2022-11-19 10:04:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-19 10:04:43 +0100 |
commit | 38e12489a517662157d85ec6efec00f225cccc9c (patch) | |
tree | 16d8218fffaba26f8e44d6dff56ef4e3e1f29233 /src-tauri/src/repair_and_verify | |
parent | d3c190bd4d3461fc4c310f64eb74a8e2425baaad (diff) | |
download | FlightCore-38e12489a517662157d85ec6efec00f225cccc9c.tar.gz FlightCore-38e12489a517662157d85ec6efec00f225cccc9c.zip |
feat: Initial support for installing mods from TS (#32)
* feat: Initial support for installing mods from TS
This is the basic code needed to install a mod from Thunderstore
* refactor: Remove console log, show msg in notif
Instead of console logging result message, show it in notification
instead.
* refactor: Rename function to indicate behaviour
Function not only installs but also downloads mod first.
Although it does remove downloaded zip post installation.
* refactor: Move install logic to dedicated module
`mod_management` module didn't exist when this PR was created
* chore: Trim single leftover newline
* fix: Update code for newer `libthermite` version
* feat: Allow installing older versions of mods
Installs the given version number instead of only allowing latest.
* fix: Explicit error msg for installing NS as mod
While it would fail during install anyway, having explicit error message
is nicer
* feat: Write TS mod string to mod.json
Write Thunderstore mod string of installed mod to its `mod.json`
This way we can later check whether a mod is outdated based on the
Thunderstore mod string
* fix: Early return on empty string
Prevent trying to install the first mod that matches an early string. We
should never pass an empty string in the first place but better safe
then sorry.
* build: Add dependency for recursive async
Needed for recursive mod dependency install
* feat: Recursively install mod dependencies
* fix: Early catch installing R2modman as mod
Just in case to prevent someone trying to install R2modman as a mod.
* refactor: Remove debug prints
* fix: Allow installing mods having NS as dependency
They would previously error out as Northstar cannot be installed as
dependency. We now catch that specific error and return Ok(())
* fix: Delete download folder after mod install
Deletes download folder after mod install if non-empty.
* fix: Do not early leave when dependency is NS
Logic error, instead of skipping installing Northstar as dependency it
would previously just return early with success.
* chore: Remove leftover commented out code
Diffstat (limited to 'src-tauri/src/repair_and_verify')
-rw-r--r-- | src-tauri/src/repair_and_verify/mod.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 8f8fe633..188d3821 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -2,6 +2,7 @@ use app::{get_enabled_mods, GameInstall}; use crate::mod_management::set_mod_enabled_status; +use anyhow::anyhow; /// Verifies Titanfall2 game files pub fn verify_game_files(game_install: GameInstall) -> Result<String, String> { @@ -34,3 +35,33 @@ pub fn disable_all_but_core(game_install: GameInstall) -> Result<(), String> { Ok(()) } + +/// Deletes download folder +/// If `force` is FALSE, bails on non-empty folder +/// If `force` is TRUE, deletes folder even if non-empty +pub fn clean_up_download_folder( + game_install: GameInstall, + force: bool, +) -> Result<(), anyhow::Error> { + // Get download directory + let download_directory = format!( + "{}/___flightcore-temp-download-dir/", + game_install.game_path + ); + + // Check if files in folder + let download_dir_contents = std::fs::read_dir(download_directory.clone())?; + // dbg!(download_dir_contents); + + let mut count = 0; + download_dir_contents.inspect(|_| count += 1).for_each(drop); + + if count > 0 && !force { + return Err(anyhow!("Folder not empty, not deleting")); + } + + // Delete folder + std::fs::remove_dir_all(download_directory)?; + + Ok(()) +} |