Working importing projects
This commit is contained in:
parent
034f05eeba
commit
d812491883
|
|
@ -275,15 +275,37 @@ impl HubClient {
|
||||||
body.rows(text_height, 1, |_, mut row| {
|
body.rows(text_height, 1, |_, mut row| {
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
add_header(ui);
|
add_header(ui);
|
||||||
});row.col(|_ui| {});
|
});
|
||||||
|
row.col(|_ui| {});
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
ui.vertical_centered_justified(|ui| {
|
ui.vertical_centered_justified(|ui| {
|
||||||
ui.add_space(VERTICAL_SPACING);
|
ui.add_space(VERTICAL_SPACING);
|
||||||
if ui
|
if ui.button("Import").clicked() {
|
||||||
.button("Import")
|
let directory = FileDialog::new().pick_folder();
|
||||||
.on_hover_text("Not implemented yet")
|
|
||||||
.clicked()
|
if let Some(dir) = directory {
|
||||||
{}
|
let amount = self.hub.search_for_projects_at_path(&dir);
|
||||||
|
let mut message =
|
||||||
|
rfd::MessageDialog::new().set_title("Search ended");
|
||||||
|
|
||||||
|
match amount {
|
||||||
|
0 => {
|
||||||
|
message = message
|
||||||
|
.set_description("No new projects found.")
|
||||||
|
.set_level(rfd::MessageLevel::Warning)
|
||||||
|
}
|
||||||
|
1 => message = message.set_description("Project founded!"),
|
||||||
|
_ => {
|
||||||
|
message = message.set_description(&format!(
|
||||||
|
"Founded {} projects.",
|
||||||
|
amount
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message.show();
|
||||||
|
self.save_config(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use std::process::Command;
|
use std::{path::PathBuf, process::Command};
|
||||||
|
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use crate::{config::Configuration, unity_editor::UnityEditor, unity_project::UnityProject};
|
use crate::{config::Configuration, unity_editor::UnityEditor, unity_project::UnityProject};
|
||||||
|
|
||||||
|
|
@ -40,6 +42,34 @@ impl Hub {
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("Failed to run project");
|
.expect("Failed to run project");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn search_for_projects_at_path(&mut self, path: &PathBuf) -> usize {
|
||||||
|
let path_exists = std::fs::metadata(path).is_ok();
|
||||||
|
let mut result = 0;
|
||||||
|
if !path_exists {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
for entry in WalkDir::new(path)
|
||||||
|
.max_depth(3)
|
||||||
|
.into_iter()
|
||||||
|
.filter_entry(|_| true)
|
||||||
|
{
|
||||||
|
let projects = self.projects.clone();
|
||||||
|
if entry.is_err() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let entry_unwraped = entry.unwrap();
|
||||||
|
let path_string = entry_unwraped.path().as_os_str().to_str();
|
||||||
|
if let Some(project) = UnityProject::try_get_project_at_path(&path_string.unwrap()) {
|
||||||
|
if !projects.contains(&project) {
|
||||||
|
self.projects.push(project);
|
||||||
|
result = result + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl Default for Hub {
|
impl Default for Hub {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,12 @@ pub struct UnityProject {
|
||||||
pub version: String,
|
pub version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for UnityProject {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.path == other.path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl UnityProject {
|
impl UnityProject {
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub fn get_projects_from_registry() -> Vec<UnityProject> {
|
pub fn get_projects_from_registry() -> Vec<UnityProject> {
|
||||||
|
|
@ -37,7 +43,7 @@ impl UnityProject {
|
||||||
|
|
||||||
if let registry::value::Data::Binary(data) = &val.data() {
|
if let registry::value::Data::Binary(data) = &val.data() {
|
||||||
let project_path = str::from_utf8(&data).unwrap().to_string();
|
let project_path = str::from_utf8(&data).unwrap().to_string();
|
||||||
if let Some(result) = UnityProject::get_project_at_path(&project_path) {
|
if let Some(result) = UnityProject::try_get_project_at_path(&project_path) {
|
||||||
projects.push(result);
|
projects.push(result);
|
||||||
}
|
}
|
||||||
println!("\t{}: {}", unwraped_name, project_path);
|
println!("\t{}: {}", unwraped_name, project_path);
|
||||||
|
|
@ -46,7 +52,7 @@ impl UnityProject {
|
||||||
projects
|
projects
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_project_at_path(path: &str) -> Option<UnityProject> {
|
pub fn try_get_project_at_path(path: &str) -> Option<UnityProject> {
|
||||||
let path = path.trim_matches(char::from(0)).replace("/", "\\");
|
let path = path.trim_matches(char::from(0)).replace("/", "\\");
|
||||||
let second_path = Path::new(&path).join("ProjectSettings");
|
let second_path = Path::new(&path).join("ProjectSettings");
|
||||||
if std::fs::metadata(&second_path).is_err() {
|
if std::fs::metadata(&second_path).is_err() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue