diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e6e342a..03c1aae 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -46,8 +46,8 @@ jobs: cache-on-failure: "" - uses: actions/checkout@v2 - name: Build - run: cd egui_client && cargo build --verbose + run: cd rusty_hub_egui && cargo build --verbose - uses: actions/upload-artifact@v3 with: name: upload executable - path: egui_client/target/release/rusty_hub_egui \ No newline at end of file + path: rusty_hub_egui/target/release/rusty_hub_egui \ No newline at end of file diff --git a/.github/workflows/windows_rust.yml b/.github/workflows/windows_rust.yml index 75939aa..c47486e 100644 --- a/.github/workflows/windows_rust.yml +++ b/.github/workflows/windows_rust.yml @@ -14,8 +14,8 @@ jobs: - uses: Swatinem/rust-cache@v2 - uses: actions/checkout@v2 - name: Build - run: cd egui_client && cargo build --release --verbose + run: cd rusty_hub_egui && cargo build --release --verbose - uses: actions/upload-artifact@v3 with: name: build-exe - path: egui_client/target/release/*exe \ No newline at end of file + path: rusty_hub_egui/target/release/*exe \ No newline at end of file diff --git a/README.md b/README.md index 684e03d..0edabd5 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ There is ready to download Windows version. Go to [Releases](https://github.com/ [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) is required in order to build it. -Building is pretty simple, just copy repo, open `egui_client` subdirectory in `CLI` client and run these commands: +Building is pretty simple, just copy repo, open `rusty_hub_egui` subdirectory in `CLI` client and run these commands: ```sh git clone git@github.com:Leinnan/rusty_hub.git -cd rusty_hub/egui_client +cd rusty_hub/rusty_hub_egui cargo build --release cargo run --release ``` diff --git a/egui_client/Cargo.lock b/rusty_hub_egui/Cargo.lock similarity index 99% rename from egui_client/Cargo.lock rename to rusty_hub_egui/Cargo.lock index 4804cf1..af0b293 100644 --- a/egui_client/Cargo.lock +++ b/rusty_hub_egui/Cargo.lock @@ -1700,18 +1700,6 @@ dependencies = [ "windows", ] -[[package]] -name = "rusty_hub" -version = "0.1.0" -dependencies = [ - "dpc-pariter", - "exe", - "registry", - "serde", - "serde_derive", - "walkdir", -] - [[package]] name = "rusty_hub_egui" version = "0.2.0" @@ -1721,7 +1709,7 @@ dependencies = [ "egui_extras", "image", "rfd", - "rusty_hub", + "unity_hub_lib", "winres", ] @@ -2054,6 +2042,18 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unity_hub_lib" +version = "0.2.0" +dependencies = [ + "dpc-pariter", + "exe", + "registry", + "serde", + "serde_derive", + "walkdir", +] + [[package]] name = "url" version = "2.3.1" diff --git a/egui_client/Cargo.toml b/rusty_hub_egui/Cargo.toml similarity index 90% rename from egui_client/Cargo.toml rename to rusty_hub_egui/Cargo.toml index 1a631c1..5900c8c 100644 --- a/egui_client/Cargo.toml +++ b/rusty_hub_egui/Cargo.toml @@ -19,7 +19,7 @@ opt-level = 2 confy = "^0.5.0" eframe = "0.19.0" egui_extras = "0.19.0" -rusty_hub = { path="../rusty_hub" } +unity_hub_lib = { path="../unity_hub_lib" } image = { version = "0.24.0", default-features = false, features = ["png"] } rfd = "0.10.0" diff --git a/egui_client/build.rs b/rusty_hub_egui/build.rs similarity index 100% rename from egui_client/build.rs rename to rusty_hub_egui/build.rs diff --git a/egui_client/icon.png b/rusty_hub_egui/icon.png similarity index 100% rename from egui_client/icon.png rename to rusty_hub_egui/icon.png diff --git a/egui_client/src/config.rs b/rusty_hub_egui/src/config.rs similarity index 100% rename from egui_client/src/config.rs rename to rusty_hub_egui/src/config.rs diff --git a/egui_client/src/consts.rs b/rusty_hub_egui/src/consts.rs similarity index 100% rename from egui_client/src/consts.rs rename to rusty_hub_egui/src/consts.rs diff --git a/egui_client/src/hub_client.rs b/rusty_hub_egui/src/hub_client.rs similarity index 98% rename from egui_client/src/hub_client.rs rename to rusty_hub_egui/src/hub_client.rs index 858e90a..fae855d 100644 --- a/egui_client/src/hub_client.rs +++ b/rusty_hub_egui/src/hub_client.rs @@ -9,7 +9,7 @@ use eframe::{ }; use egui_extras::{Size, TableBuilder}; use rfd::FileDialog; -use rusty_hub::hub::Hub; +use unity_hub_lib::{consts::FILE_MANAGER, hub::Hub}; pub struct HubClient { hub: Hub, @@ -18,7 +18,7 @@ pub struct HubClient { impl HubClient { pub fn new(_cc: &eframe::CreationContext<'_>) -> Self { - let hub_option = confy::load("lwa_unity_hub", "config"); + let hub_option = confy::load("rusty_hub_egui", "config"); let hub = if hub_option.is_ok() { let mut h: Hub = hub_option.unwrap(); @@ -27,6 +27,7 @@ impl HubClient { } else { Hub::default() }; + let client = Self { hub, current_tab: WindowTab::Projects, @@ -39,7 +40,7 @@ impl HubClient { if rebuild { self.hub.update_data(); } - let _ = confy::store("lwa_unity_hub", "config", &self.hub); + let _ = confy::store("rusty_hub_egui", "config", &self.hub); } pub fn draw_central_panel(&mut self, ctx: &egui::Context) { @@ -269,7 +270,7 @@ impl HubClient { path_response.context_menu(|ui| { if ui.button("Open directory").clicked() { use std::process::Command; - Command::new(rusty_hub::consts::FILE_MANAGER) + Command::new(FILE_MANAGER) .arg(&project.path) .spawn() .unwrap(); diff --git a/egui_client/src/main.rs b/rusty_hub_egui/src/main.rs similarity index 100% rename from egui_client/src/main.rs rename to rusty_hub_egui/src/main.rs diff --git a/egui_client/src/window_tab.rs b/rusty_hub_egui/src/window_tab.rs similarity index 100% rename from egui_client/src/window_tab.rs rename to rusty_hub_egui/src/window_tab.rs diff --git a/egui_client/static/hub.ico b/rusty_hub_egui/static/hub.ico similarity index 100% rename from egui_client/static/hub.ico rename to rusty_hub_egui/static/hub.ico diff --git a/egui_client/static/hub.png b/rusty_hub_egui/static/hub.png similarity index 100% rename from egui_client/static/hub.png rename to rusty_hub_egui/static/hub.png diff --git a/rusty_hub/Cargo.lock b/unity_hub_lib/Cargo.lock similarity index 99% rename from rusty_hub/Cargo.lock rename to unity_hub_lib/Cargo.lock index 2d54fd6..c2551c8 100644 --- a/rusty_hub/Cargo.lock +++ b/unity_hub_lib/Cargo.lock @@ -371,8 +371,8 @@ dependencies = [ ] [[package]] -name = "rusty_hub" -version = "0.1.0" +name = "rusty_hub_lib" +version = "0.2.0" dependencies = [ "dpc-pariter", "exe", diff --git a/rusty_hub/Cargo.toml b/unity_hub_lib/Cargo.toml similarity index 89% rename from rusty_hub/Cargo.toml rename to unity_hub_lib/Cargo.toml index 4a756b8..22a4d14 100644 --- a/rusty_hub/Cargo.toml +++ b/unity_hub_lib/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "rusty_hub" -version = "0.1.0" +name = "unity_hub_lib" +version = "0.2.0" edition = "2021" [profile.release] diff --git a/rusty_hub/src/config.rs b/unity_hub_lib/src/config.rs similarity index 91% rename from rusty_hub/src/config.rs rename to unity_hub_lib/src/config.rs index 01b69b0..bbb7b71 100644 --- a/rusty_hub/src/config.rs +++ b/unity_hub_lib/src/config.rs @@ -12,7 +12,6 @@ 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)) @@ -36,19 +35,12 @@ 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 } 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/unity_hub_lib/src/consts.rs similarity index 61% rename from rusty_hub/src/consts.rs rename to unity_hub_lib/src/consts.rs index 69b4d41..921d5d6 100644 --- a/rusty_hub/src/consts.rs +++ b/unity_hub_lib/src/consts.rs @@ -15,3 +15,10 @@ pub const FILE_MANAGER: &str = "explorer"; pub const FILE_MANAGER: &str = "open"; #[cfg(target_os = "linux")] pub const FILE_MANAGER: &str = "xdg-open"; + +#[cfg(windows)] +pub const TEMPLATES_DIR: &str = "Data\\Resources\\PackageManager\\ProjectTemplates"; +#[cfg(target_os = "macos")] +pub const TEMPLATES_DIR: &str = "Contents/Resources/PackageManager/ProjectTemplates"; +#[cfg(target_os = "linux")] +pub const TEMPLATES_DIR: &str = "Data/Resources/PackageManager/ProjectTemplates"; diff --git a/rusty_hub/src/hub.rs b/unity_hub_lib/src/hub.rs similarity index 100% rename from rusty_hub/src/hub.rs rename to unity_hub_lib/src/hub.rs diff --git a/rusty_hub/src/lib.rs b/unity_hub_lib/src/lib.rs similarity index 83% rename from rusty_hub/src/lib.rs rename to unity_hub_lib/src/lib.rs index a1833c3..fc59fb2 100644 --- a/rusty_hub/src/lib.rs +++ b/unity_hub_lib/src/lib.rs @@ -4,5 +4,6 @@ extern crate serde_derive; pub mod config; pub mod consts; pub mod hub; +pub mod project_template; pub mod unity_editor; pub mod unity_project; diff --git a/unity_hub_lib/src/project_template.rs b/unity_hub_lib/src/project_template.rs new file mode 100644 index 0000000..ab41928 --- /dev/null +++ b/unity_hub_lib/src/project_template.rs @@ -0,0 +1,35 @@ +use dpc_pariter::IteratorExt; +use std::path::Path; + +#[derive(Debug, Serialize, Deserialize, Clone, Eq, Hash)] +pub struct ProjectTemplate { + pub path: String, + pub title: String, +} + +impl PartialEq for ProjectTemplate { + fn eq(&self, other: &Self) -> bool { + self.path == other.path + } +} + +impl ProjectTemplate { + pub fn find_templates(path: &str) -> Vec { + let dir = std::fs::read_dir(Path::new(&path).join(crate::consts::TEMPLATES_DIR)); + + if dir.is_err() { + return Vec::new(); + } + + dir.unwrap() + .into_iter() + .parallel_filter(|path| path.is_ok()) + .parallel_map(|path| path.unwrap()) + .parallel_filter(|path| path.file_name().into_string().unwrap().contains(".tgz")) + .parallel_map(|path| Self { + path: path.path().to_str().unwrap().to_string(), + title: path.file_name().into_string().unwrap().replace(".tgz", ""), + }) + .collect() + } +} diff --git a/rusty_hub/src/unity_editor.rs b/unity_hub_lib/src/unity_editor.rs similarity index 94% rename from rusty_hub/src/unity_editor.rs rename to unity_hub_lib/src/unity_editor.rs index bc00b21..254723b 100644 --- a/rusty_hub/src/unity_editor.rs +++ b/unity_hub_lib/src/unity_editor.rs @@ -1,15 +1,16 @@ +use crate::consts; +use crate::project_template::ProjectTemplate; use std::borrow::Borrow; use std::collections::HashMap; use std::path::Path; -use crate::consts; - #[derive(Debug, Serialize, Deserialize, Clone, Eq, Hash)] pub struct UnityEditor { pub version: String, pub exe_path: String, pub base_path: String, pub platforms: Vec, + pub templates: Vec, } impl PartialEq for UnityEditor { @@ -35,9 +36,7 @@ impl UnityEditor { use exe::VSVersionInfo; let image = VecPE::from_disk_file(&exe_path).unwrap(); let vs_version_check = VSVersionInfo::parse(&image); - if vs_version_check.is_err() { - return 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") { @@ -65,7 +64,8 @@ impl UnityEditor { version: version.unwrap().clone(), exe_path: exe_path.into_os_string().into_string().unwrap(), base_path: String::from(path), - platforms: UnityEditor::get_platforms(path), + platforms: UnityEditor::get_platforms(&path), + templates: ProjectTemplate::find_templates(&path), }) } diff --git a/rusty_hub/src/unity_project.rs b/unity_hub_lib/src/unity_project.rs similarity index 100% rename from rusty_hub/src/unity_project.rs rename to unity_hub_lib/src/unity_project.rs