diff --git a/egui_client/src/hub_client.rs b/egui_client/src/hub_client.rs index 3688e1b..858e90a 100644 --- a/egui_client/src/hub_client.rs +++ b/egui_client/src/hub_client.rs @@ -269,7 +269,7 @@ impl HubClient { path_response.context_menu(|ui| { if ui.button("Open directory").clicked() { use std::process::Command; - Command::new("explorer") + Command::new(rusty_hub::consts::FILE_MANAGER) .arg(&project.path) .spawn() .unwrap(); diff --git a/rusty_hub/src/config.rs b/rusty_hub/src/config.rs index 64cde5c..6de7a61 100644 --- a/rusty_hub/src/config.rs +++ b/rusty_hub/src/config.rs @@ -12,6 +12,7 @@ pub struct Configuration { impl Configuration { pub fn rebuild(&mut self) { let paths = self.get_unity_paths(); + println!("{}",paths.len()); self.editors_configurations = paths .into_iter() .parallel_map(|path| UnityEditor::new(&path)) @@ -35,6 +36,7 @@ impl Configuration { #[cfg(unix)] let uninstall_exists = true; // just check that on windows only let unity_exe_exists = entry.path().clone().join(consts::UNITY_EXE_NAME).exists(); + println!("PATH {} {:?}", unity_exe_exists, &entry.path().clone().join(consts::UNITY_EXE_NAME)); uninstall_exists && unity_exe_exists } @@ -42,6 +44,7 @@ impl Configuration { fn search_for_editor(path: &str) -> Vec { let path_exists = std::fs::metadata(path).is_ok(); if !path_exists { + println!("PATH NOT EXIST {}", &path); return Vec::new(); } diff --git a/rusty_hub/src/consts.rs b/rusty_hub/src/consts.rs index 142a860..5052303 100644 --- a/rusty_hub/src/consts.rs +++ b/rusty_hub/src/consts.rs @@ -4,3 +4,14 @@ pub const UNITY_EXE_NAME: &str = "Unity.exe"; pub const UNITY_EXE_NAME: &str = "Unity.app/Contents/MacOS/Unity"; #[cfg(target_os = "linux")] pub const UNITY_EXE_NAME: &str = "Unity"; + +#[cfg(windows)] +pub const SLASH : &str = "\\"; +#[cfg(unix)] +pub const SLASH : &str = "/"; +#[cfg(windows)] +pub const FILE_MANAGER : &str = "explorer"; +#[cfg(target_os = "macos")] +pub const FILE_MANAGER : &str = "open"; +#[cfg(target_os = "linux")] +pub const FILE_MANAGER : &str = "xdg-open"; \ No newline at end of file diff --git a/rusty_hub/src/unity_editor.rs b/rusty_hub/src/unity_editor.rs index ca42a46..041e04f 100644 --- a/rusty_hub/src/unity_editor.rs +++ b/rusty_hub/src/unity_editor.rs @@ -1,5 +1,4 @@ -use exe::pe::VecPE; -use exe::VSVersionInfo; + use std::borrow::Borrow; use std::collections::HashMap; use std::path::Path; @@ -24,16 +23,22 @@ impl UnityEditor { pub fn new(path: &str) -> Option { let base_path = Path::new(path); let exe_path = base_path.join(consts::UNITY_EXE_NAME); - if !std::fs::metadata(&exe_path).is_ok() { + let meta = std::fs::metadata(&exe_path); + if !meta.is_ok() || !meta.unwrap().is_file() { return None; } + let mut version :Option = None; + + #[cfg(windows)] + { + use exe::pe::VecPE; + use exe::VSVersionInfo; let image = VecPE::from_disk_file(&exe_path).unwrap(); - let vs_version_check = VSVersionInfo::parse(&image); + let vs_version_check = VSVersionInfo::parse(&image); if vs_version_check.is_err() { return None; } - let mut version = None; if let Some(string_file_info) = vs_version_check.unwrap().string_file_info { let hashmap = string_file_info.children[0].string_map(); if let Some(result_version) = hashmap.get("ProductVersion") { @@ -42,18 +47,22 @@ impl UnityEditor { version = Some(short.to_string()); } } + }} + if version.is_none() { + let folder = base_path.to_str().expect("Fail").split(consts::SLASH).last().unwrap(); + version = Some(folder.to_string()); } if version.is_none() { - None - } else { - Some(Self { - version: version.unwrap().clone(), - exe_path: exe_path.into_os_string().into_string().unwrap(), - base_path: String::from(path), - platforms: UnityEditor::get_platforms(path), - }) + return None; } + Some(Self { + version: version.unwrap().clone(), + exe_path: exe_path.into_os_string().into_string().unwrap(), + base_path: String::from(path), + platforms: UnityEditor::get_platforms(path), + }) + } fn get_platforms(unity_folder: &str) -> Vec { diff --git a/rusty_hub/src/unity_project.rs b/rusty_hub/src/unity_project.rs index 5f678e4..a8267ac 100644 --- a/rusty_hub/src/unity_project.rs +++ b/rusty_hub/src/unity_project.rs @@ -1,5 +1,7 @@ use std::{ops::Sub, path::Path, str}; +use crate::consts; + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct UnityProject { pub path: String, @@ -61,7 +63,10 @@ impl UnityProject { } pub fn try_get_project_at_path(path: &str) -> Option { + #[cfg(windows)] let path = path.trim_matches(char::from(0)).replace("/", "\\"); + #[cfg(unix)] + let path = path.trim_matches(char::from(0)); if !UnityProject::is_project_at_path(&path) { return None; } @@ -77,7 +82,7 @@ impl UnityProject { let mut project = UnityProject { path: path.to_string(), - title: path.split("\\").last().unwrap().to_string(), + title: path.split(consts::SLASH).last().unwrap().to_string(), version: project_version, branch: String::new(), is_valid: true,