Print editors and projects

This commit is contained in:
Piotr Siuszko 2022-09-24 17:49:40 +02:00
parent 094cb730e8
commit 20ea5be8d5
6 changed files with 119 additions and 13 deletions

20
rusty_hub/Cargo.lock generated
View File

@ -310,12 +310,26 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "registry"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83e4b158bf49b0d000013487636c92268de4cfd26cdbb629f020a612749f12c4"
dependencies = [
"bitflags",
"log",
"thiserror",
"utfx",
"winapi",
]
[[package]] [[package]]
name = "rusty_hub" name = "rusty_hub"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"confy", "confy",
"exe", "exe",
"registry",
"serde", "serde",
"serde_derive", "serde_derive",
"walkdir", "walkdir",
@ -436,6 +450,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
[[package]]
name = "utfx"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133bf74f01486773317ddfcde8e2e20d2933cc3b68ab797e5d718bef996a81de"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"

View File

@ -18,4 +18,5 @@ confy = "^0.5.0"
serde = "^1.0" serde = "^1.0"
serde_derive = "^1.0" serde_derive = "^1.0"
walkdir = "^2.3.2" walkdir = "^2.3.2"
exe = "^0.5.4" exe = "^0.5.4"
registry = "1.2.2"

View File

@ -1,11 +1,24 @@
use walkdir::{DirEntry, WalkDir}; use walkdir::{DirEntry, WalkDir};
use crate::unity_editor::UnityEditor;
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Configuration { pub struct Configuration {
pub unity_search_paths: Vec<String>, pub unity_search_paths: Vec<String>,
pub editors_configurations: Vec<UnityEditor>,
} }
impl Configuration { impl Configuration {
pub fn rebuild(&mut self) {
self.editors_configurations = Vec::new();
let paths = self.get_unity_paths();
for path in &paths {
let editor = UnityEditor::new(&path);
if editor.is_some() {
self.editors_configurations.push(editor.unwrap());
}
}
}
pub fn get_unity_paths(&self) -> Vec<String> { pub fn get_unity_paths(&self) -> Vec<String> {
let mut paths = Vec::new(); let mut paths = Vec::new();
@ -56,8 +69,12 @@ impl Configuration {
impl Default for Configuration { impl Default for Configuration {
fn default() -> Self { fn default() -> Self {
Self { let mut default = Self {
unity_search_paths: vec!["C:\\Program Files\\Unity\\Hub".to_string()], unity_search_paths: vec!["C:\\Program Files\\Unity\\Hub".to_string()],
} editors_configurations: Vec::new(),
};
default.rebuild();
default
} }
} }

View File

@ -1,5 +1,3 @@
use unity_editor::UnityEditor;
use crate::config::Configuration; use crate::config::Configuration;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
@ -7,14 +5,11 @@ extern crate confy;
mod config; mod config;
mod unity_editor; mod unity_editor;
mod unity_project;
fn main() { fn main() {
let config = Configuration::default(); let config = Configuration::default();
let paths = config.get_unity_paths(); println!("{:#?}", config.editors_configurations);
for path in &paths { let projects = unity_project::UnityProject::get_projects_from_registry();
let editor = UnityEditor::new(&path); println!("{:#?}", projects);
if editor.is_some() {
println!("{:#?}", editor.unwrap());
}
}
} }

View File

@ -80,7 +80,9 @@ impl UnityEditor {
} }
let f = path.unwrap(); let f = path.unwrap();
if let Ok(result_string) = f.file_name().into_string() { if let Ok(result_string) = f.file_name().into_string() {
if let Some(value) = platform_names.get(&result_string.clone().to_lowercase().borrow()) { if let Some(value) =
platform_names.get(&result_string.clone().to_lowercase().borrow())
{
platforms.push(value.to_string()); platforms.push(value.to_string());
} else { } else {
platforms.push(result_string); platforms.push(result_string);

View File

@ -0,0 +1,71 @@
use registry::{Hive, Security};
use std::{path::Path, str};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct UnityProject {
pub path: String,
pub title: String,
pub version: String,
}
impl UnityProject {
pub fn get_projects_from_registry() -> Vec<UnityProject> {
let mut projects = Vec::new();
let key = Hive::CurrentUser
.open(
r"SOFTWARE\Unity Technologies\Unity Editor 5.x",
Security::Read,
)
.unwrap();
println!("{}", key.to_string());
for value in key.values() {
if value.is_err() {
continue;
}
let val = value.unwrap();
let unwraped_name = val.name().to_string().unwrap();
if !unwraped_name.contains("RecentlyUsedProjectPaths-") {
continue;
}
if let registry::value::Data::Binary(data) = &val.data() {
let project_path = str::from_utf8(&data).unwrap().to_string();
if let Some(result) = UnityProject::get_project_at_path(&project_path) {
projects.push(result);
}
println!("\t{}: {}", unwraped_name, project_path);
}
}
projects
}
fn get_project_at_path(path: &str) -> Option<UnityProject> {
let path = path.trim_matches(char::from(0));
let second_path = Path::new(&path.replace("/", "\\")).join("ProjectSettings");
if std::fs::metadata(&second_path).is_err() {
println!(
"DUPA: {:#?}, {:#?}",
second_path.display(),
std::fs::metadata(&second_path).err()
);
return None;
}
let project_version_file = std::fs::read_to_string(second_path.join("ProjectVersion.txt"));
if project_version_file.is_err() {
println!("DUPA2");
return None;
}
let project_version_file = project_version_file.unwrap();
let mut iter = project_version_file.split_whitespace();
iter.next();
let project_version = iter.next().unwrap().to_string();
Some(UnityProject {
path: path.to_string(),
title: path.to_string(),
version: project_version,
})
}
}