You've already forked AstralRinth
forked from didirus/AstralRinth
Misc bugs 4 (#381)
* bug fixes * fixed jres being undetected * cleanup * prettier * fixed folders not displaying windows exporting * fixes, more bugs * missed function * clippy, fmt * prettier
This commit is contained in:
@@ -94,6 +94,19 @@ pub async fn get_by_uuid(
|
||||
Ok(profile)
|
||||
}
|
||||
|
||||
/// Get profile's full path in the filesystem
|
||||
#[tracing::instrument]
|
||||
pub async fn get_full_path(path: &ProfilePathId) -> crate::Result<PathBuf> {
|
||||
let _ = get(path, Some(true)).await?.ok_or_else(|| {
|
||||
crate::ErrorKind::OtherError(format!(
|
||||
"Tried to get the full path of a nonexistent or unloaded profile at path {}!",
|
||||
path
|
||||
))
|
||||
})?;
|
||||
let full_path = io::canonicalize(path.get_full_path().await?)?;
|
||||
Ok(full_path)
|
||||
}
|
||||
|
||||
/// Edit a profile using a given asynchronous closure
|
||||
pub async fn edit<Fut>(
|
||||
path: &ProfilePathId,
|
||||
@@ -373,6 +386,7 @@ pub async fn update_project(
|
||||
profile.projects.insert(path.clone(), project);
|
||||
}
|
||||
}
|
||||
drop(profiles);
|
||||
|
||||
if !skip_send_event.unwrap_or(false) {
|
||||
emit_profile(
|
||||
@@ -409,7 +423,7 @@ pub async fn add_project_from_version(
|
||||
version_id: String,
|
||||
) -> crate::Result<ProjectPathId> {
|
||||
if let Some(profile) = get(profile_path, None).await? {
|
||||
let (path, _) = profile.add_project_version(version_id).await?;
|
||||
let (project_path, _) = profile.add_project_version(version_id).await?;
|
||||
|
||||
emit_profile(
|
||||
profile.uuid,
|
||||
@@ -418,9 +432,7 @@ pub async fn add_project_from_version(
|
||||
ProfilePayloadType::Edited,
|
||||
)
|
||||
.await?;
|
||||
State::sync().await?;
|
||||
|
||||
Ok(path)
|
||||
Ok(project_path)
|
||||
} else {
|
||||
Err(
|
||||
crate::ErrorKind::UnmanagedProfileError(profile_path.to_string())
|
||||
|
||||
@@ -143,6 +143,8 @@ impl Children {
|
||||
mc_exit_status = t;
|
||||
break;
|
||||
}
|
||||
// sleep for 10ms
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -204,6 +206,9 @@ impl Children {
|
||||
mc_exit_status = t;
|
||||
break;
|
||||
}
|
||||
// sleep for 10ms
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(10))
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ pub async fn init_watcher() -> crate::Result<Debouncer<RecommendedWatcher>> {
|
||||
let (mut tx, mut rx) = channel(1);
|
||||
|
||||
let file_watcher = new_debouncer(
|
||||
Duration::from_secs(2),
|
||||
Duration::from_secs_f32(0.25),
|
||||
None,
|
||||
move |res: DebounceEventResult| {
|
||||
futures::executor::block_on(async {
|
||||
|
||||
@@ -107,7 +107,8 @@ impl ProjectPathId {
|
||||
let profiles_dir: PathBuf = io::canonicalize(
|
||||
State::get().await?.directories.profiles_dir().await,
|
||||
)?;
|
||||
path.strip_prefix(profiles_dir)
|
||||
let path = path
|
||||
.strip_prefix(profiles_dir)
|
||||
.ok()
|
||||
.map(|p| p.components().skip(1).collect::<PathBuf>())
|
||||
.ok_or_else(|| {
|
||||
@@ -458,7 +459,6 @@ impl Profile {
|
||||
version_id: String,
|
||||
) -> crate::Result<(ProjectPathId, ModrinthVersion)> {
|
||||
let state = State::get().await?;
|
||||
|
||||
let version = fetch_json::<ModrinthVersion>(
|
||||
Method::GET,
|
||||
&format!("{MODRINTH_API_URL}version/{version_id}"),
|
||||
@@ -467,7 +467,6 @@ impl Profile {
|
||||
&state.fetch_semaphore,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let file = if let Some(file) = version.files.iter().find(|x| x.primary)
|
||||
{
|
||||
file
|
||||
@@ -486,7 +485,6 @@ impl Profile {
|
||||
&state.fetch_semaphore,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let path = self
|
||||
.add_project_bytes(
|
||||
&file.filename,
|
||||
@@ -494,7 +492,6 @@ impl Profile {
|
||||
ProjectType::get_from_loaders(version.loaders.clone()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok((path, version))
|
||||
}
|
||||
|
||||
@@ -569,7 +566,6 @@ impl Profile {
|
||||
}
|
||||
|
||||
/// Toggle a project's disabled state.
|
||||
/// 'path' should be relative to the profile's path.
|
||||
#[tracing::instrument(skip(self))]
|
||||
#[theseus_macros::debug_pin]
|
||||
pub async fn toggle_disable_project(
|
||||
@@ -662,11 +658,11 @@ impl Profile {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(crate::ErrorKind::InputError(format!(
|
||||
"Project path does not exist: {:?}",
|
||||
// If we are removing a project that doesn't exist, allow it to pass through without error, but warn
|
||||
tracing::warn!(
|
||||
"Attempted to remove non-existent project: {:?}",
|
||||
relative_path
|
||||
))
|
||||
.into());
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -272,6 +272,16 @@ pub async fn infer_data_from_files(
|
||||
|
||||
// TODO: Make this concurrent and use progressive hashing to avoid loading each JAR in memory
|
||||
for path in paths {
|
||||
if !path.exists() {
|
||||
continue;
|
||||
}
|
||||
if let Some(ext) = path.extension() {
|
||||
// Ignore txt configuration files
|
||||
if ext == "txt" {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
let mut file = tokio::fs::File::open(path.clone())
|
||||
.await
|
||||
.map_err(|e| IOError::with_path(e, &path))?;
|
||||
@@ -460,9 +470,7 @@ pub async fn infer_data_from_files(
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
if let Ok(pack) =
|
||||
serde_json::from_str::<ForgeModInfo>(&file_str)
|
||||
{
|
||||
if let Ok(pack) = toml::from_str::<ForgeModInfo>(&file_str) {
|
||||
if let Some(pack) = pack.mods.first() {
|
||||
let icon = read_icon_from_file(
|
||||
pack.logo_file.clone(),
|
||||
|
||||
@@ -2,11 +2,9 @@ use super::io;
|
||||
use futures::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::{collections::HashSet, path::Path};
|
||||
use tempfile::NamedTempFile;
|
||||
use tokio::task::JoinError;
|
||||
|
||||
use crate::State;
|
||||
@@ -280,20 +278,17 @@ pub async fn check_java_at_filepath(path: &Path) -> Option<JavaVersion> {
|
||||
return None;
|
||||
};
|
||||
|
||||
let mut file = NamedTempFile::new().ok()?;
|
||||
file.write_all(include_bytes!("../../library/JavaInfo.class"))
|
||||
.ok()?;
|
||||
let bytes = include_bytes!("../../library/JavaInfo.class");
|
||||
let tempdir: PathBuf = tempfile::tempdir().ok()?.into_path();
|
||||
if !tempdir.exists() {
|
||||
return None;
|
||||
}
|
||||
let file_path = tempdir.join("JavaInfo.class");
|
||||
io::write(&file_path, bytes).await.ok()?;
|
||||
|
||||
let original_path = file.path().to_path_buf();
|
||||
let mut new_path = original_path.clone();
|
||||
new_path.set_file_name("JavaInfo");
|
||||
new_path.set_extension("class");
|
||||
tokio::fs::rename(&original_path, &new_path).await.ok()?;
|
||||
|
||||
// Run java checker on java binary
|
||||
let output = Command::new(&java)
|
||||
.arg("-cp")
|
||||
.arg(file.path().parent().unwrap())
|
||||
.arg(file_path.parent().unwrap())
|
||||
.arg("JavaInfo")
|
||||
.output()
|
||||
.ok()?;
|
||||
|
||||
Reference in New Issue
Block a user