aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/util.rs
diff options
context:
space:
mode:
authorJan <sentrycraft123@gmail.com>2023-08-02 12:24:57 +0200
committerGitHub <noreply@github.com>2023-08-02 12:24:57 +0200
commit08d066c7c6c7b99076efb5217474cc5b72df015f (patch)
tree5bb5e2e16c81e6ac01782a6c10d06622dcec8c13 /src-tauri/src/util.rs
parentfae4de2fba580e4a1a92b853c479b61e856a3a42 (diff)
downloadFlightCore-08d066c7c6c7b99076efb5217474cc5b72df015f.tar.gz
FlightCore-08d066c7c6c7b99076efb5217474cc5b72df015f.zip
Extract Northstar into temporary location before installing (#456)
This is done in order to enable future changes
Diffstat (limited to 'src-tauri/src/util.rs')
-rw-r--r--src-tauri/src/util.rs39
1 files changed, 39 insertions, 0 deletions
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(())
+}