Initial bug fixes (#127)

* Initial bug fixes

* fix compile error on non-mac

* Fix even more bugs

* Fix more

* fix more

* fix build

* fix build

* address review comments
This commit is contained in:
Geometrically
2023-06-02 07:09:46 -07:00
committed by GitHub
parent 9ea548cfe3
commit ee61951698
57 changed files with 3823 additions and 2813 deletions

View File

@@ -3,6 +3,7 @@ use crate::{launcher::auth as inner, State};
use futures::prelude::*;
use tokio::sync::oneshot;
use crate::state::AuthTask;
pub use inner::Credentials;
/// Authenticate a user with Hydra - part 1
@@ -11,8 +12,7 @@ pub use inner::Credentials;
/// to call authenticate and call the flow from the frontend.
/// Visit the URL in a browser, then call and await 'authenticate_await_complete_flow'.
pub async fn authenticate_begin_flow() -> crate::Result<url::Url> {
let st = State::get().await?.clone();
let url = st.auth_flow.write().await.begin_auth().await?;
let url = AuthTask::begin_auth().await?;
Ok(url)
}
@@ -21,12 +21,15 @@ pub async fn authenticate_begin_flow() -> crate::Result<url::Url> {
/// This can be used in conjunction with 'authenticate_begin_flow'
/// to call authenticate and call the flow from the frontend.
pub async fn authenticate_await_complete_flow() -> crate::Result<Credentials> {
let st = State::get().await?.clone();
let credentials =
st.auth_flow.write().await.await_auth_completion().await?;
let credentials = AuthTask::await_auth_completion().await?;
Ok(credentials)
}
/// Cancels the active authentication flow
pub async fn cancel_flow() -> crate::Result<()> {
AuthTask::cancel().await
}
/// Authenticate a user with Hydra
/// To run this, you need to first spawn this function as a task, then
/// open a browser to the given URL and finally wait on the spawned future
@@ -38,7 +41,6 @@ pub async fn authenticate(
) -> crate::Result<Credentials> {
let mut flow = inner::HydraAuthFlow::new().await?;
let state = State::get().await?;
let mut users = state.users.write().await;
let url = flow.prepare_login_url().await?;
browser_url.send(url).map_err(|url| {
@@ -48,7 +50,10 @@ pub async fn authenticate(
})?;
let credentials = flow.extract_credentials(&state.fetch_semaphore).await?;
users.insert(&credentials).await?;
{
let mut users = state.users.write().await;
users.insert(&credentials).await?;
}
if state.settings.read().await.default_user.is_none() {
let mut settings = state.settings.write().await;
@@ -69,7 +74,7 @@ pub async fn refresh(user: uuid::Uuid) -> crate::Result<Credentials> {
let fetch_semaphore = &state.fetch_semaphore;
futures::future::ready(users.get(user).ok_or_else(|| {
crate::ErrorKind::OtherError(format!(
"Tried to refresh nonexistent user with ID {user}"
"You are not logged in with a Minecraft account!"
))
.as_error()
}))

View File

@@ -79,6 +79,7 @@ enum PackDependency {
#[tracing::instrument]
#[theseus_macros::debug_pin]
pub async fn install_pack_from_version_id(
project_id: String,
version_id: String,
title: String,
icon_url: Option<String>,
@@ -91,7 +92,10 @@ pub async fn install_pack_from_version_id(
None,
None,
icon_url.clone(),
None,
Some(LinkedData {
project_id: Some(project_id),
version_id: Some(version_id.clone()),
}),
Some(true),
)
.await?;
@@ -240,261 +244,277 @@ async fn install_pack(
) -> crate::Result<PathBuf> {
let state = &State::get().await?;
let reader: Cursor<&bytes::Bytes> = Cursor::new(&file);
let result = async {
let reader: Cursor<&bytes::Bytes> = Cursor::new(&file);
// Create zip reader around file
let mut zip_reader = ZipFileReader::new(reader).await.map_err(|_| {
crate::Error::from(crate::ErrorKind::InputError(
"Failed to read input modpack zip".to_string(),
))
})?;
// Create zip reader around file
let mut zip_reader =
ZipFileReader::new(reader).await.map_err(|_| {
crate::Error::from(crate::ErrorKind::InputError(
"Failed to read input modpack zip".to_string(),
))
})?;
// Extract index of modrinth.index.json
let zip_index_option = zip_reader
.file()
.entries()
.iter()
.position(|f| f.entry().filename() == "modrinth.index.json");
if let Some(zip_index) = zip_index_option {
let mut manifest = String::new();
let entry = zip_reader
// Extract index of modrinth.index.json
let zip_index_option = zip_reader
.file()
.entries()
.get(zip_index)
.unwrap()
.entry()
.clone();
let mut reader = zip_reader.entry(zip_index).await?;
reader.read_to_string_checked(&mut manifest, &entry).await?;
.iter()
.position(|f| f.entry().filename() == "modrinth.index.json");
if let Some(zip_index) = zip_index_option {
let mut manifest = String::new();
let entry = zip_reader
.file()
.entries()
.get(zip_index)
.unwrap()
.entry()
.clone();
let mut reader = zip_reader.entry(zip_index).await?;
reader.read_to_string_checked(&mut manifest, &entry).await?;
let pack: PackFormat = serde_json::from_str(&manifest)?;
let pack: PackFormat = serde_json::from_str(&manifest)?;
if &*pack.game != "minecraft" {
return Err(crate::ErrorKind::InputError(
"Pack does not support Minecraft".to_string(),
)
.into());
}
let mut game_version = None;
let mut mod_loader = None;
let mut loader_version = None;
for (key, value) in &pack.dependencies {
match key {
PackDependency::Forge => {
mod_loader = Some(ModLoader::Forge);
loader_version = Some(value);
}
PackDependency::FabricLoader => {
mod_loader = Some(ModLoader::Fabric);
loader_version = Some(value);
}
PackDependency::QuiltLoader => {
mod_loader = Some(ModLoader::Quilt);
loader_version = Some(value);
}
PackDependency::Minecraft => game_version = Some(value),
if &*pack.game != "minecraft" {
return Err(crate::ErrorKind::InputError(
"Pack does not support Minecraft".to_string(),
)
.into());
}
}
let game_version = if let Some(game_version) = game_version {
game_version
} else {
return Err(crate::ErrorKind::InputError(
"Pack did not specify Minecraft version".to_string(),
)
.into());
};
let loader_version =
crate::profile_create::get_loader_version_from_loader(
game_version.clone(),
mod_loader.unwrap_or(ModLoader::Vanilla),
loader_version.cloned(),
)
.await?;
crate::api::profile::edit(&profile, |prof| {
prof.metadata.name =
override_title.clone().unwrap_or_else(|| pack.name.clone());
prof.install_stage = ProfileInstallStage::PackInstalling;
prof.metadata.linked_data = Some(LinkedData {
project_id: project_id.clone(),
version_id: version_id.clone(),
});
prof.metadata.icon = icon.clone();
prof.metadata.game_version = game_version.clone();
prof.metadata.loader_version = loader_version.clone();
prof.metadata.loader = mod_loader.unwrap_or(ModLoader::Vanilla);
async { Ok(()) }
})
.await?;
State::sync().await?;
let profile = profile.clone();
let result = async {
let loading_bar = init_or_edit_loading(
existing_loading_bar,
LoadingBarType::PackDownload {
profile_path: profile.clone(),
pack_name: pack.name.clone(),
icon,
pack_id: project_id,
pack_version: version_id,
},
100.0,
"Downloading modpack",
)
.await?;
let num_files = pack.files.len();
use futures::StreamExt;
loading_try_for_each_concurrent(
futures::stream::iter(pack.files.into_iter())
.map(Ok::<PackFile, crate::Error>),
None,
Some(&loading_bar),
70.0,
num_files,
None,
|project| {
let profile = profile.clone();
async move {
//TODO: Future update: prompt user for optional files in a modpack
if let Some(env) = project.env {
if env
.get(&EnvType::Client)
.map(|x| x == &SideType::Unsupported)
.unwrap_or(false)
{
return Ok(());
}
}
let file = fetch_mirrors(
&project
.downloads
.iter()
.map(|x| &**x)
.collect::<Vec<&str>>(),
project
.hashes
.get(&PackFileHash::Sha1)
.map(|x| &**x),
&state.fetch_semaphore,
)
.await?;
let path = std::path::Path::new(&project.path)
.components()
.next();
if let Some(path) = path {
match path {
Component::CurDir | Component::Normal(_) => {
let path = profile.join(project.path);
write(&path, &file, &state.io_semaphore)
.await?;
}
_ => {}
};
}
Ok(())
let mut game_version = None;
let mut mod_loader = None;
let mut loader_version = None;
for (key, value) in &pack.dependencies {
match key {
PackDependency::Forge => {
mod_loader = Some(ModLoader::Forge);
loader_version = Some(value);
}
},
)
.await?;
PackDependency::FabricLoader => {
mod_loader = Some(ModLoader::Fabric);
loader_version = Some(value);
}
PackDependency::QuiltLoader => {
mod_loader = Some(ModLoader::Quilt);
loader_version = Some(value);
}
PackDependency::Minecraft => game_version = Some(value),
}
}
emit_loading(&loading_bar, 0.0, Some("Extracting overrides"))
let game_version = if let Some(game_version) = game_version {
game_version
} else {
return Err(crate::ErrorKind::InputError(
"Pack did not specify Minecraft version".to_string(),
)
.into());
};
let loader_version =
crate::profile_create::get_loader_version_from_loader(
game_version.clone(),
mod_loader.unwrap_or(ModLoader::Vanilla),
loader_version.cloned(),
)
.await?;
crate::api::profile::edit(&profile, |prof| {
prof.metadata.name =
override_title.clone().unwrap_or_else(|| pack.name.clone());
prof.install_stage = ProfileInstallStage::PackInstalling;
prof.metadata.linked_data = Some(LinkedData {
project_id: project_id.clone(),
version_id: version_id.clone(),
});
prof.metadata.icon = icon.clone();
prof.metadata.game_version = game_version.clone();
prof.metadata.loader_version = loader_version.clone();
prof.metadata.loader = mod_loader.unwrap_or(ModLoader::Vanilla);
async { Ok(()) }
})
.await?;
State::sync().await?;
let profile = profile.clone();
let result = async {
let loading_bar = init_or_edit_loading(
existing_loading_bar,
LoadingBarType::PackDownload {
profile_path: profile.clone(),
pack_name: pack.name.clone(),
icon,
pack_id: project_id,
pack_version: version_id,
},
100.0,
"Downloading modpack",
)
.await?;
let mut total_len = 0;
let num_files = pack.files.len();
use futures::StreamExt;
loading_try_for_each_concurrent(
futures::stream::iter(pack.files.into_iter())
.map(Ok::<PackFile, crate::Error>),
None,
Some(&loading_bar),
70.0,
num_files,
None,
|project| {
let profile = profile.clone();
async move {
//TODO: Future update: prompt user for optional files in a modpack
if let Some(env) = project.env {
if env
.get(&EnvType::Client)
.map(|x| x == &SideType::Unsupported)
.unwrap_or(false)
{
return Ok(());
}
}
for index in 0..zip_reader.file().entries().len() {
let file =
zip_reader.file().entries().get(index).unwrap().entry();
let file = fetch_mirrors(
&project
.downloads
.iter()
.map(|x| &**x)
.collect::<Vec<&str>>(),
project
.hashes
.get(&PackFileHash::Sha1)
.map(|x| &**x),
&state.fetch_semaphore,
)
.await?;
if (file.filename().starts_with("overrides")
|| file.filename().starts_with("client_overrides"))
&& !file.filename().ends_with('/')
{
total_len += 1;
}
}
let path = std::path::Path::new(&project.path)
.components()
.next();
if let Some(path) = path {
match path {
Component::CurDir
| Component::Normal(_) => {
let path = profile.join(project.path);
write(
&path,
&file,
&state.io_semaphore,
)
.await?;
}
_ => {}
};
}
Ok(())
}
},
)
.await?;
for index in 0..zip_reader.file().entries().len() {
let file = zip_reader
.file()
.entries()
.get(index)
.unwrap()
.entry()
.clone();
emit_loading(&loading_bar, 0.0, Some("Extracting overrides"))
.await?;
let file_path = PathBuf::from(file.filename());
if (file.filename().starts_with("overrides")
|| file.filename().starts_with("client_overrides"))
&& !file.filename().ends_with('/')
{
// Reads the file into the 'content' variable
let mut content = Vec::new();
let mut reader = zip_reader.entry(index).await?;
reader.read_to_end_checked(&mut content, &file).await?;
let mut total_len = 0;
let mut new_path = PathBuf::new();
let components = file_path.components().skip(1);
for index in 0..zip_reader.file().entries().len() {
let file =
zip_reader.file().entries().get(index).unwrap().entry();
for component in components {
new_path.push(component);
if (file.filename().starts_with("overrides")
|| file.filename().starts_with("client_overrides"))
&& !file.filename().ends_with('/')
{
total_len += 1;
}
}
if new_path.file_name().is_some() {
write(
&profile.join(new_path),
&content,
&state.io_semaphore,
for index in 0..zip_reader.file().entries().len() {
let file = zip_reader
.file()
.entries()
.get(index)
.unwrap()
.entry()
.clone();
let file_path = PathBuf::from(file.filename());
if (file.filename().starts_with("overrides")
|| file.filename().starts_with("client_overrides"))
&& !file.filename().ends_with('/')
{
// Reads the file into the 'content' variable
let mut content = Vec::new();
let mut reader = zip_reader.entry(index).await?;
reader.read_to_end_checked(&mut content, &file).await?;
let mut new_path = PathBuf::new();
let components = file_path.components().skip(1);
for component in components {
new_path.push(component);
}
if new_path.file_name().is_some() {
write(
&profile.join(new_path),
&content,
&state.io_semaphore,
)
.await?;
}
emit_loading(
&loading_bar,
30.0 / total_len as f64,
Some(&format!(
"Extracting override {}/{}",
index, total_len
)),
)
.await?;
}
}
emit_loading(
&loading_bar,
30.0 / total_len as f64,
Some(&format!(
"Extracting override {}/{}",
index, total_len
)),
if let Some(profile_val) =
crate::api::profile::get(&profile, None).await?
{
crate::launcher::install_minecraft(
&profile_val,
Some(loading_bar),
)
.await?;
}
}
if let Some(profile_val) =
crate::api::profile::get(&profile, None).await?
{
crate::launcher::install_minecraft(
&profile_val,
Some(loading_bar),
)
.await?;
Ok::<PathBuf, crate::Error>(profile.clone())
}
.await;
Ok::<PathBuf, crate::Error>(profile.clone())
match result {
Ok(profile) => Ok(profile),
Err(err) => {
let _ = crate::api::profile::remove(&profile).await;
Err(err)
}
}
} else {
Err(crate::Error::from(crate::ErrorKind::InputError(
"No pack manifest found in mrpack".to_string(),
)))
}
.await;
}
.await;
match result {
Ok(profile) => Ok(profile),
Err(err) => {
let _ = crate::api::profile::remove(&profile).await;
match result {
Ok(profile) => Ok(profile),
Err(err) => {
let _ = crate::api::profile::remove(&profile).await;
Err(err)
}
Err(err)
}
} else {
let _ = crate::api::profile::remove(&profile).await;
Err(crate::Error::from(crate::ErrorKind::InputError(
"No pack manifest found in mrpack".to_string(),
)))
}
}

View File

@@ -71,6 +71,8 @@ where
match profiles.0.get_mut(path) {
Some(ref mut profile) => {
action(profile).await?;
emit_profile(
profile.uuid,
profile.path.clone(),
@@ -79,7 +81,7 @@ where
)
.await?;
action(profile).await
Ok(())
}
None => Err(crate::ErrorKind::UnmanagedProfileError(
path.display().to_string(),
@@ -102,6 +104,15 @@ pub async fn edit_icon(
match profiles.0.get_mut(path) {
Some(ref mut profile) => {
profile
.set_icon(
&state.directories.caches_dir(),
&state.io_semaphore,
bytes::Bytes::from(bytes),
&icon.to_string_lossy(),
)
.await?;
emit_profile(
profile.uuid,
profile.path.clone(),
@@ -110,14 +121,7 @@ pub async fn edit_icon(
)
.await?;
profile
.set_icon(
&state.directories.caches_dir(),
&state.io_semaphore,
bytes::Bytes::from(bytes),
&icon.to_string_lossy(),
)
.await
Ok(())
}
None => Err(crate::ErrorKind::UnmanagedProfileError(
path.display().to_string(),
@@ -265,7 +269,8 @@ pub async fn update_all(
async move {
let new_path =
update_project(profile_path, &project).await?;
update_project(profile_path, &project, Some(true))
.await?;
map.write().await.insert(project, new_path);
@@ -276,6 +281,14 @@ pub async fn update_all(
)
.await?;
emit_profile(
profile.uuid,
profile.path,
&profile.metadata.name,
ProfilePayloadType::Edited,
)
.await?;
Ok(Arc::try_unwrap(map).unwrap().into_inner())
} else {
Err(crate::ErrorKind::UnmanagedProfileError(
@@ -290,6 +303,7 @@ pub async fn update_all(
pub async fn update_project(
profile_path: &Path,
project_path: &Path,
skip_send_event: Option<bool>,
) -> crate::Result<PathBuf> {
if let Some(profile) = get(profile_path, None).await? {
if let Some(project) = profile.projects.get(project_path) {
@@ -322,6 +336,16 @@ pub async fn update_project(
}
}
if !skip_send_event.unwrap_or(false) {
emit_profile(
profile.uuid,
profile.path,
&profile.metadata.name,
ProfilePayloadType::Edited,
)
.await?;
}
return Ok(path);
}
}
@@ -347,6 +371,14 @@ pub async fn add_project_from_version(
if let Some(profile) = get(profile_path, None).await? {
let (path, _) = profile.add_project_version(version_id).await?;
emit_profile(
profile.uuid,
profile.path,
&profile.metadata.name,
ProfilePayloadType::Edited,
)
.await?;
Ok(path)
} else {
Err(crate::ErrorKind::UnmanagedProfileError(
@@ -379,6 +411,14 @@ pub async fn add_project_from_path(
)
.await?;
emit_profile(
profile.uuid,
profile.path,
&profile.metadata.name,
ProfilePayloadType::Edited,
)
.await?;
Ok(path)
} else {
Err(crate::ErrorKind::UnmanagedProfileError(
@@ -395,7 +435,17 @@ pub async fn toggle_disable_project(
project: &Path,
) -> crate::Result<PathBuf> {
if let Some(profile) = get(profile, None).await? {
Ok(profile.toggle_disable_project(project).await?)
let res = profile.toggle_disable_project(project).await?;
emit_profile(
profile.uuid,
profile.path,
&profile.metadata.name,
ProfilePayloadType::Edited,
)
.await?;
Ok(res)
} else {
Err(crate::ErrorKind::UnmanagedProfileError(
profile.display().to_string(),
@@ -413,6 +463,14 @@ pub async fn remove_project(
if let Some(profile) = get(profile, None).await? {
profile.remove_project(project, None).await?;
emit_profile(
profile.uuid,
profile.path,
&profile.metadata.name,
ProfilePayloadType::Edited,
)
.await?;
Ok(())
} else {
Err(crate::ErrorKind::UnmanagedProfileError(

View File

@@ -96,44 +96,57 @@ pub async fn profile_create(
let path = canonicalize(&path)?;
let mut profile =
Profile::new(uuid, name, game_version, path.clone()).await?;
if let Some(ref icon) = icon {
let bytes = tokio::fs::read(icon).await?;
profile
.set_icon(
&state.directories.caches_dir(),
&state.io_semaphore,
bytes::Bytes::from(bytes),
&icon.to_string_lossy(),
)
.await?;
let result = async {
if let Some(ref icon) = icon {
let bytes = tokio::fs::read(icon).await?;
profile
.set_icon(
&state.directories.caches_dir(),
&state.io_semaphore,
bytes::Bytes::from(bytes),
&icon.to_string_lossy(),
)
.await?;
}
profile.metadata.icon_url = icon_url;
if let Some(loader_version) = loader {
profile.metadata.loader = modloader;
profile.metadata.loader_version = Some(loader_version);
}
profile.metadata.linked_data = linked_data;
emit_profile(
uuid,
path.clone(),
&profile.metadata.name,
ProfilePayloadType::Created,
)
.await?;
{
let mut profiles = state.profiles.write().await;
profiles.insert(profile.clone()).await?;
}
if !skip_install_profile.unwrap_or(false) {
crate::launcher::install_minecraft(&profile, None).await?;
}
State::sync().await?;
Ok(path)
}
profile.metadata.icon_url = icon_url;
if let Some(loader_version) = loader {
profile.metadata.loader = modloader;
profile.metadata.loader_version = Some(loader_version);
.await;
match result {
Ok(profile) => Ok(profile),
Err(err) => {
let _ = crate::api::profile::remove(&profile.path).await;
Err(err)
}
}
profile.metadata.linked_data = linked_data;
emit_profile(
uuid,
path.clone(),
&profile.metadata.name,
ProfilePayloadType::Created,
)
.await?;
{
let mut profiles = state.profiles.write().await;
profiles.insert(profile.clone()).await?;
}
if !skip_install_profile.unwrap_or(false) {
crate::launcher::install_minecraft(&profile, None).await?;
}
State::sync().await?;
Ok(path)
}
#[tracing::instrument]

View File

@@ -137,10 +137,6 @@ pub fn get_jvm_arguments(
parsed_arguments.push("-cp".to_string());
parsed_arguments.push(class_paths.to_string());
}
if let Some(minimum) = memory.minimum {
parsed_arguments.push(format!("-Xms{minimum}M"));
}
parsed_arguments.push(format!("-Xmx{}M", memory.maximum));
for arg in custom_args {
if !arg.is_empty() {

View File

@@ -34,7 +34,11 @@ pub fn parse_rule(rule: &d::minecraft::Rule, java_version: &str) -> bool {
Rule {
features: Some(ref features),
..
} => features.has_demo_resolution.unwrap_or(false),
} => {
features.has_demo_resolution.unwrap_or(false)
|| (features.has_demo_resolution.is_none()
&& features.is_demo_user.is_none())
}
_ => false,
};

View File

@@ -13,7 +13,9 @@ impl AuthTask {
AuthTask(None)
}
pub async fn begin_auth(&mut self) -> crate::Result<url::Url> {
pub async fn begin_auth() -> crate::Result<url::Url> {
let state = crate::State::get().await?;
// Creates a channel to receive the URL
let (tx, rx) = tokio::sync::oneshot::channel::<url::Url>();
let task = tokio::spawn(crate::auth::authenticate(tx));
@@ -29,16 +31,20 @@ impl AuthTask {
};
// Flow is going, store in state and return
self.0 = Some(task);
let mut write = state.auth_flow.write().await;
write.0 = Some(task);
Ok(url)
}
pub async fn await_auth_completion(
&mut self,
) -> crate::Result<Credentials> {
pub async fn await_auth_completion() -> crate::Result<Credentials> {
// Gets the task handle from the state, replacing with None
let task = mem::replace(&mut self.0, None);
let task = {
let state = crate::State::get().await?;
let mut write = state.auth_flow.write().await;
mem::replace(&mut write.0, None)
};
// Waits for the task to complete, and returns the credentials
let credentials = task
@@ -49,13 +55,20 @@ impl AuthTask {
Ok(credentials)
}
pub async fn cancel(&mut self) {
pub async fn cancel() -> crate::Result<()> {
// Gets the task handle from the state, replacing with None
let task = mem::replace(&mut self.0, None);
let task = {
let state = crate::State::get().await?;
let mut write = state.auth_flow.write().await;
mem::replace(&mut write.0, None)
};
if let Some(task) = task {
// Cancels the task
task.abort();
}
Ok(())
}
}

View File

@@ -403,14 +403,6 @@ impl Profile {
}
}
emit_profile(
self.uuid,
self.path.clone(),
&self.metadata.name,
ProfilePayloadType::Synced,
)
.await?;
Ok(path)
}

View File

@@ -196,6 +196,7 @@ pub enum ProjectMetadata {
authors: Vec<String>,
version: Option<String>,
icon: Option<PathBuf>,
project_type: Option<String>,
},
Unknown,
}
@@ -484,6 +485,7 @@ pub async fn infer_data_from_files(
.unwrap_or_default(),
version: pack.version.clone(),
icon,
project_type: Some("mod".to_string()),
},
},
);
@@ -544,6 +546,7 @@ pub async fn infer_data_from_files(
authors: pack.author_list.unwrap_or_default(),
version: pack.version,
icon,
project_type: Some("mod".to_string()),
},
},
);
@@ -612,6 +615,7 @@ pub async fn infer_data_from_files(
.collect(),
version: Some(pack.version),
icon,
project_type: Some("mod".to_string()),
},
},
);
@@ -687,6 +691,7 @@ pub async fn infer_data_from_files(
.unwrap_or_default(),
version: Some(pack.version),
icon,
project_type: Some("mod".to_string()),
},
},
);
@@ -735,6 +740,7 @@ pub async fn infer_data_from_files(
authors: Vec::new(),
version: None,
icon,
project_type: None,
},
},
);

View File

@@ -118,17 +118,12 @@ pub enum Theme {
/// Minecraft memory settings
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct MemorySettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub minimum: Option<u32>,
pub maximum: u32,
}
impl Default for MemorySettings {
fn default() -> Self {
Self {
minimum: None,
maximum: 2048,
}
Self { maximum: 2048 }
}
}

View File

@@ -33,9 +33,17 @@ pub async fn get_all_jre() -> Result<Vec<JavaVersion>, JREError> {
// Add JRES directly on PATH
jre_paths.extend(get_all_jre_path().await?);
jre_paths.extend(get_all_autoinstalled_jre_path().await?);
if let Ok(java_home) = env::var("JAVA_HOME") {
jre_paths.insert(PathBuf::from(java_home));
}
// Hard paths for locations for commonly installed .exes
let java_paths = [r"C:/Program Files/Java", r"C:/Program Files (x86)/Java"];
let java_paths = [
r"C:/Program Files/Java",
r"C:/Program Files (x86)/Java",
r"C:\Program Files\Eclipse Adoptium",
r"C:\Program Files (x86)\Eclipse Adoptium",
];
for java_path in java_paths {
let Ok(java_subpaths) = std::fs::read_dir(java_path) else {continue };
for java_subpath in java_subpaths {
@@ -201,7 +209,6 @@ async fn get_all_autoinstalled_jre_path() -> Result<HashSet<PathBuf>, JREError>
let contents = std::fs::read_to_string(file_path)?;
let entry = entry.path().join(contents);
println!("{:?}", entry);
jre_paths.insert(entry);
}
}