aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan <sentrycraft123@gmail.com>2023-08-01 12:28:20 +0200
committerGitHub <noreply@github.com>2023-08-01 12:28:20 +0200
commitfae4de2fba580e4a1a92b853c479b61e856a3a42 (patch)
treefa819d77932fe56f3cfe5e2019a6a8e3c10ab336
parent3563a0bc4748b7c14cbff2240af401fab9d4dc5d (diff)
downloadFlightCore-fae4de2fba580e4a1a92b853c479b61e856a3a42.tar.gz
FlightCore-fae4de2fba580e4a1a92b853c479b61e856a3a42.zip
refactor Generalise temporary directory structure (#458)
The temp folder we create could be reused for a lot more things, like extracting Northstar before moving files into the correct place. As such adjust the naming and structure to accommodate this.
-rw-r--r--src-tauri/src/development/mod.rs2
-rw-r--r--src-tauri/src/github/pull_requests.rs2
-rw-r--r--src-tauri/src/mod_management/mod.rs4
-rw-r--r--src-tauri/src/northstar/install.rs2
-rw-r--r--src-tauri/src/repair_and_verify/mod.rs34
5 files changed, 24 insertions, 20 deletions
diff --git a/src-tauri/src/development/mod.rs b/src-tauri/src/development/mod.rs
index be02966d..7184904c 100644
--- a/src-tauri/src/development/mod.rs
+++ b/src-tauri/src/development/mod.rs
@@ -25,7 +25,7 @@ pub async fn install_git_main(game_install_path: &str) -> Result<String, String>
};
let extract_directory = format!(
- "{}/___flightcore-temp-download-dir/launcher-pr-{}",
+ "{}/___flightcore-temp/download-dir/launcher-pr-{}",
game_install_path, latest_commit_sha
);
match std::fs::create_dir_all(extract_directory.clone()) {
diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs
index 44b41638..c3079cfd 100644
--- a/src-tauri/src/github/pull_requests.rs
+++ b/src-tauri/src/github/pull_requests.rs
@@ -253,7 +253,7 @@ pub async fn apply_launcher_pr(
};
let extract_directory = format!(
- "{}/___flightcore-temp-download-dir/launcher-pr-{}",
+ "{}/___flightcore-temp/download-dir/launcher-pr-{}",
game_install_path, pull_request.number
);
match std::fs::create_dir_all(extract_directory.clone()) {
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
index a5f928bd..ff3a09ed 100644
--- a/src-tauri/src/mod_management/mod.rs
+++ b/src-tauri/src/mod_management/mod.rs
@@ -537,7 +537,7 @@ pub async fn fc_download_mod_and_install(
log::info!("Attempting to install \"{thunderstore_mod_string}\" to {game_install:?}");
// Get mods and download directories
let download_directory = format!(
- "{}/___flightcore-temp-download-dir/",
+ "{}/___flightcore-temp/download-dir/",
game_install.game_path
);
@@ -584,7 +584,7 @@ pub async fn fc_download_mod_and_install(
};
let path = format!(
- "{}/___flightcore-temp-download-dir/{thunderstore_mod_string}.zip",
+ "{}/___flightcore-temp/download-dir/{thunderstore_mod_string}.zip",
game_install.game_path
);
diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs
index 002548c1..eef6c148 100644
--- a/src-tauri/src/northstar/install.rs
+++ b/src-tauri/src/northstar/install.rs
@@ -37,7 +37,7 @@ async fn do_install(
) -> Result<()> {
let filename = format!("northstar-{}.zip", nmod.version);
let download_directory = format!(
- "{}/___flightcore-temp-download-dir/",
+ "{}/___flightcore-temp/download-dir/",
game_install.game_path
);
diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs
index 17c71992..29cc9613 100644
--- a/src-tauri/src/repair_and_verify/mod.rs
+++ b/src-tauri/src/repair_and_verify/mod.rs
@@ -40,26 +40,30 @@ 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
- );
+ const TEMPORARY_DIRECTORIES: [&str; 3] = [
+ "___flightcore-temp-download-dir",
+ "___flightcore-temp/download-dir",
+ "___flightcore-temp",
+ ];
- // Check if files in folder
- let download_dir_contents = std::fs::read_dir(download_directory.clone())?;
- // dbg!(download_dir_contents);
+ for directory in TEMPORARY_DIRECTORIES {
+ // Get download directory
+ let download_directory = format!("{}/{}/", game_install.game_path, directory);
- let mut count = 0;
- download_dir_contents.for_each(|_| count += 1);
+ // Check if files in folder
+ let download_dir_contents = std::fs::read_dir(download_directory.clone())?;
+ // dbg!(download_dir_contents);
- if count > 0 && !force {
- return Err(anyhow!("Folder not empty, not deleting"));
- }
+ let mut count = 0;
+ download_dir_contents.for_each(|_| count += 1);
- // Delete folder
- std::fs::remove_dir_all(download_directory)?;
+ if count > 0 && !force {
+ return Err(anyhow!("Folder not empty, not deleting"));
+ }
+ // Delete folder
+ std::fs::remove_dir_all(download_directory)?;
+ }
Ok(())
}