You've already forked AstralRinth
forked from didirus/AstralRinth
Folder names (#318)
This commit is contained in:
@@ -8,6 +8,7 @@ use crate::util::fetch::{
|
||||
use crate::util::io::IOError;
|
||||
use async_zip::tokio::read::fs::ZipFileReader;
|
||||
use chrono::{DateTime, Utc};
|
||||
use futures::StreamExt;
|
||||
use reqwest::Method;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
@@ -16,6 +17,8 @@ use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
use super::ProjectPathId;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ProjectType {
|
||||
@@ -253,6 +256,9 @@ async fn read_icon_from_file(
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
// Creates Project data from the existing files in the file system, for a given Profile
|
||||
// Paths must be the full paths to the files in the FS, and not the relative paths
|
||||
// eg: with get_profile_full_project_paths
|
||||
#[tracing::instrument(skip(paths, profile, io_semaphore, fetch_semaphore))]
|
||||
#[theseus_macros::debug_pin]
|
||||
pub async fn infer_data_from_files(
|
||||
@@ -261,7 +267,7 @@ pub async fn infer_data_from_files(
|
||||
cache_dir: PathBuf,
|
||||
io_semaphore: &IoSemaphore,
|
||||
fetch_semaphore: &FetchSemaphore,
|
||||
) -> crate::Result<HashMap<PathBuf, Project>> {
|
||||
) -> crate::Result<HashMap<ProjectPathId, Project>> {
|
||||
let mut file_path_hashes = HashMap::new();
|
||||
|
||||
// TODO: Make this concurrent and use progressive hashing to avoid loading each JAR in memory
|
||||
@@ -342,7 +348,7 @@ pub async fn infer_data_from_files(
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
let mut return_projects = HashMap::new();
|
||||
let mut return_projects: Vec<(PathBuf, Project)> = Vec::new();
|
||||
let mut further_analyze_projects: Vec<(String, PathBuf)> = Vec::new();
|
||||
|
||||
for (hash, path) in file_path_hashes {
|
||||
@@ -356,7 +362,7 @@ pub async fn infer_data_from_files(
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path,
|
||||
Project {
|
||||
disabled: file_name.ends_with(".disabled"),
|
||||
@@ -392,7 +398,7 @@ pub async fn infer_data_from_files(
|
||||
sha512: hash,
|
||||
file_name,
|
||||
},
|
||||
);
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -412,7 +418,7 @@ pub async fn infer_data_from_files(
|
||||
{
|
||||
zip_file_reader
|
||||
} else {
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path.clone(),
|
||||
Project {
|
||||
sha512: hash,
|
||||
@@ -420,7 +426,7 @@ pub async fn infer_data_from_files(
|
||||
metadata: ProjectMetadata::Unknown,
|
||||
file_name,
|
||||
},
|
||||
);
|
||||
));
|
||||
continue;
|
||||
};
|
||||
let zip_index_option = zip_file_reader
|
||||
@@ -466,7 +472,7 @@ pub async fn infer_data_from_files(
|
||||
)
|
||||
.await?;
|
||||
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path.clone(),
|
||||
Project {
|
||||
sha512: hash,
|
||||
@@ -491,7 +497,7 @@ pub async fn infer_data_from_files(
|
||||
project_type: Some("mod".to_string()),
|
||||
},
|
||||
},
|
||||
);
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -533,7 +539,7 @@ pub async fn infer_data_from_files(
|
||||
)
|
||||
.await?;
|
||||
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path.clone(),
|
||||
Project {
|
||||
sha512: hash,
|
||||
@@ -552,7 +558,7 @@ pub async fn infer_data_from_files(
|
||||
project_type: Some("mod".to_string()),
|
||||
},
|
||||
},
|
||||
);
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -599,7 +605,7 @@ pub async fn infer_data_from_files(
|
||||
)
|
||||
.await?;
|
||||
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path.clone(),
|
||||
Project {
|
||||
sha512: hash,
|
||||
@@ -621,7 +627,7 @@ pub async fn infer_data_from_files(
|
||||
project_type: Some("mod".to_string()),
|
||||
},
|
||||
},
|
||||
);
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -665,7 +671,7 @@ pub async fn infer_data_from_files(
|
||||
)
|
||||
.await?;
|
||||
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path.clone(),
|
||||
Project {
|
||||
sha512: hash,
|
||||
@@ -697,7 +703,7 @@ pub async fn infer_data_from_files(
|
||||
project_type: Some("mod".to_string()),
|
||||
},
|
||||
},
|
||||
);
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -731,7 +737,7 @@ pub async fn infer_data_from_files(
|
||||
io_semaphore,
|
||||
)
|
||||
.await?;
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path.clone(),
|
||||
Project {
|
||||
sha512: hash,
|
||||
@@ -746,13 +752,13 @@ pub async fn infer_data_from_files(
|
||||
project_type: None,
|
||||
},
|
||||
},
|
||||
);
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return_projects.insert(
|
||||
return_projects.push((
|
||||
path.clone(),
|
||||
Project {
|
||||
sha512: hash,
|
||||
@@ -760,8 +766,17 @@ pub async fn infer_data_from_files(
|
||||
file_name,
|
||||
metadata: ProjectMetadata::Unknown,
|
||||
},
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
Ok(return_projects)
|
||||
// Project paths should be relative
|
||||
let _profile_base_path = profile.get_profile_full_path().await?;
|
||||
let mut corrected_hashmap = HashMap::new();
|
||||
let mut stream = tokio_stream::iter(return_projects);
|
||||
while let Some((h, v)) = stream.next().await {
|
||||
let h = ProjectPathId::from_fs_path(h).await?;
|
||||
corrected_hashmap.insert(h, v);
|
||||
}
|
||||
|
||||
Ok(corrected_hashmap)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user