Skip to content

Commit

Permalink
refactor Generalise temporary directory structure (#458)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jan200101 authored Aug 1, 2023
1 parent 3563a0b commit fae4de2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/development/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/github/pull_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/mod_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/northstar/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
34 changes: 19 additions & 15 deletions src-tauri/src/repair_and_verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down

0 comments on commit fae4de2

Please sign in to comment.