Cleanup, project template class

This commit is contained in:
Piotr Siuszko 2022-09-26 21:47:25 +02:00
parent 365c724252
commit 4c3916e2d1
23 changed files with 78 additions and 42 deletions

View File

@ -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
path: rusty_hub_egui/target/release/rusty_hub_egui

View File

@ -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
path: rusty_hub_egui/target/release/*exe

View File

@ -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
```

View File

@ -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"

View File

@ -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"

View File

@ -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();

View File

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 190 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -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",

View File

@ -1,6 +1,6 @@
[package]
name = "rusty_hub"
version = "0.1.0"
name = "unity_hub_lib"
version = "0.2.0"
edition = "2021"
[profile.release]

View File

@ -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<String> {
let path_exists = std::fs::metadata(path).is_ok();
if !path_exists {
println!("PATH NOT EXIST {}", &path);
return Vec::new();
}

View File

@ -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";

View File

@ -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;

View File

@ -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<ProjectTemplate> {
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()
}
}

View File

@ -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<String>,
pub templates: Vec<ProjectTemplate>,
}
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),
})
}