aboutsummaryrefslogtreecommitdiff
path: root/src-tauri
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/src/northstar/install.rs44
-rw-r--r--src-tauri/src/util.rs39
2 files changed, 70 insertions, 13 deletions
diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs
index eef6c148..80425c56 100644
--- a/src-tauri/src/northstar/install.rs
+++ b/src-tauri/src/northstar/install.rs
@@ -5,7 +5,10 @@ use std::{cell::RefCell, time::Instant};
use ts_rs::TS;
use crate::constants::TITANFALL2_STEAM_ID;
-use crate::{util::extract, GameInstall, InstallType};
+use crate::{
+ util::{extract, move_dir_all},
+ GameInstall, InstallType,
+};
#[cfg(target_os = "windows")]
use crate::platform_specific::windows;
@@ -36,16 +39,13 @@ async fn do_install(
game_install: GameInstall,
) -> Result<()> {
let filename = format!("northstar-{}.zip", nmod.version);
- let download_directory = format!(
- "{}/___flightcore-temp/download-dir/",
- game_install.game_path
- );
-
- log::info!(
- "Attempting to create temporary directory {}",
- download_directory
- );
+ let temp_dir = format!("{}/___flightcore-temp", game_install.game_path);
+ let download_directory = format!("{}/download-dir", temp_dir);
+ let extract_directory = format!("{}/extract-dir", temp_dir);
+
+ log::info!("Attempting to create temporary directory {}", temp_dir);
std::fs::create_dir_all(download_directory.clone())?;
+ std::fs::create_dir_all(extract_directory.clone())?;
let download_path = format!("{}/{}", download_directory, filename);
log::info!("Download path: {download_path}");
@@ -94,11 +94,29 @@ async fn do_install(
.unwrap();
log::info!("Extracting Northstar...");
- extract(nfile, std::path::Path::new(&game_install.game_path))?;
+ extract(nfile, std::path::Path::new(&extract_directory))?;
+
+ log::info!("Installing Northstar...");
+
+ for entry in std::fs::read_dir(extract_directory).unwrap() {
+ let entry = entry.unwrap();
+ let destination = format!(
+ "{}/{}",
+ game_install.game_path,
+ entry.path().file_name().unwrap().to_str().unwrap()
+ );
+
+ log::info!("Installing {}", entry.path().display());
+ if !entry.file_type().unwrap().is_dir() {
+ std::fs::rename(entry.path(), destination)?;
+ } else {
+ move_dir_all(entry.path(), destination)?;
+ }
+ }
// Delete old copy
- log::info!("Delete temp folder again");
- std::fs::remove_dir_all(download_directory).unwrap();
+ log::info!("Delete temporary directory");
+ std::fs::remove_dir_all(temp_dir).unwrap();
log::info!("Done installing Northstar!");
window
diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs
index f1ba6b8a..b21b2208 100644
--- a/src-tauri/src/util.rs
+++ b/src-tauri/src/util.rs
@@ -143,3 +143,42 @@ pub fn check_northstar_running() -> bool {
|| s.processes_by_name("Titanfall2.exe").next().is_some();
x
}
+
+/// Copies a folder and all its contents to a new location
+#[allow(dead_code)]
+pub fn copy_dir_all(
+ src: impl AsRef<std::path::Path>,
+ dst: impl AsRef<std::path::Path>,
+) -> std::io::Result<()> {
+ std::fs::create_dir_all(&dst)?;
+ for entry in std::fs::read_dir(src)? {
+ let entry = entry?;
+ let ty = entry.file_type()?;
+ if ty.is_dir() {
+ copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
+ } else {
+ std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
+ }
+ }
+ Ok(())
+}
+
+/// Moves a folders file structure to a new location
+/// Old folders are not removed
+pub fn move_dir_all(
+ src: impl AsRef<std::path::Path>,
+ dst: impl AsRef<std::path::Path>,
+) -> std::io::Result<()> {
+ std::fs::create_dir_all(&dst)?;
+ for entry in std::fs::read_dir(src)? {
+ let entry = entry?;
+ let ty = entry.file_type()?;
+ if ty.is_dir() {
+ move_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
+ std::fs::remove_dir(entry.path())?;
+ } else {
+ std::fs::rename(entry.path(), dst.as_ref().join(entry.file_name()))?;
+ }
+ }
+ Ok(())
+}