* basic push

* actual push

* JRE detection, and autosetting

* removed a println, retrying CI/CD

* new game version compare; preset java 7 and 8 using our jre

* 1.8 mislabeled

* working JRE changes

* fixed bugs with JRE setup

* fixed bugs with JRE setup

* manual merge

* prettier

* fixes + jre 17

* clippy, prettier

* typo

* forgot to hook up a function

* pr fix + comment fix

* added loader_version

* take 2
This commit is contained in:
Wyatt Verchere
2023-04-07 13:31:06 -07:00
committed by GitHub
parent 4b41ffbd8a
commit 34005dd2e2
21 changed files with 542 additions and 83 deletions

View File

@@ -42,7 +42,7 @@ impl AuthTask {
// Waits for the task to complete, and returns the credentials
let credentials = task
.ok_or_else(|| AuthTaskError::TaskMissing)?
.ok_or(AuthTaskError::TaskMissing)?
.await
.map_err(AuthTaskError::from)??;

View File

@@ -0,0 +1,61 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use crate::prelude::JavaVersion;
use crate::util::jre;
// All stored Java versions, chosen by the user
// A wrapper over a Hashmap connecting key -> java version
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct JavaGlobals(HashMap<String, JavaVersion>);
impl JavaGlobals {
pub fn new() -> JavaGlobals {
JavaGlobals(HashMap::new())
}
pub fn insert(&mut self, key: String, java: JavaVersion) {
self.0.insert(key, java);
}
pub fn remove(&mut self, key: &String) {
self.0.remove(key);
}
pub fn get(&self, key: &String) -> Option<&JavaVersion> {
self.0.get(key)
}
pub fn get_mut(&mut self, key: &String) -> Option<&mut JavaVersion> {
self.0.get_mut(key)
}
pub fn count(&self) -> usize {
self.0.len()
}
// Validates that every path here is a valid Java version and that the version matches the version stored here
// If false, when checked, the user should be prompted to reselect the Java version
pub fn is_all_valid(&self) -> bool {
for (_, java) in self.0.iter() {
let jre = jre::check_java_at_filepath(
PathBuf::from(&java.path).as_path(),
);
if let Some(jre) = jre {
if jre.version != java.version {
return false;
}
} else {
return false;
}
}
true
}
}
impl Default for JavaGlobals {
fn default() -> Self {
Self::new()
}
}

View File

@@ -1,5 +1,6 @@
//! Theseus state management system
use crate::config::sled_config;
use crate::jre;
use std::sync::Arc;
use tokio::sync::{Mutex, OnceCell, RwLock, Semaphore};
@@ -31,6 +32,9 @@ pub use self::auth_task::*;
mod tags;
pub use self::tags::*;
mod java_globals;
pub use self::java_globals::*;
// Global state
static LAUNCHER_STATE: OnceCell<Arc<State>> = OnceCell::const_new();
pub struct State {
@@ -74,7 +78,7 @@ impl State {
.open()?;
// Settings
let settings =
let mut settings =
Settings::init(&directories.settings_file()).await?;
// Loose initializations
@@ -101,6 +105,12 @@ impl State {
);
};
// On launcher initialization, if global java variables are unset, try to find and set them
// (they are required for the game to launch)
if settings.java_globals.count() == 0 {
settings.java_globals = jre::autodetect_java_globals()?;
}
Ok(Arc::new(Self {
database,
directories,

View File

@@ -83,7 +83,7 @@ impl std::fmt::Display for ModLoader {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct JavaSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub install: Option<PathBuf>,
pub jre_key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub extra_arguments: Option<Vec<String>>,
}
@@ -146,6 +146,15 @@ impl Profile {
}
}
#[tracing::instrument]
pub fn set_java_settings(
&mut self,
java: Option<JavaSettings>,
) -> crate::Result<()> {
self.java = java;
Ok(())
}
pub fn get_profile_project_paths(&self) -> crate::Result<Vec<PathBuf>> {
let mut files = Vec::new();
let mut read_paths = |path: &str| {

View File

@@ -322,7 +322,9 @@ pub async fn infer_data_from_files(
title: Some(
pack.display_name
.clone()
.unwrap_or(pack.mod_id.clone()),
.unwrap_or_else(|| {
pack.mod_id.clone()
}),
),
description: pack.description.clone(),
authors: pack

View File

@@ -1,11 +1,10 @@
//! Theseus settings file
use serde::{Deserialize, Serialize};
use std::{
collections::HashSet,
path::{Path, PathBuf},
};
use std::{collections::HashSet, path::Path};
use tokio::fs;
use super::JavaGlobals;
// TODO: convert to semver?
const CURRENT_FORMAT_VERSION: u32 = 1;
@@ -18,8 +17,7 @@ pub struct Settings {
pub game_resolution: WindowSize,
pub custom_java_args: Vec<String>,
pub custom_env_args: Vec<(String, String)>,
pub java_8_path: Option<PathBuf>,
pub java_17_path: Option<PathBuf>,
pub java_globals: JavaGlobals,
pub default_user: Option<uuid::Uuid>,
pub hooks: Hooks,
pub max_concurrent_downloads: usize,
@@ -33,8 +31,7 @@ impl Default for Settings {
game_resolution: WindowSize::default(),
custom_java_args: Vec::new(),
custom_env_args: Vec::new(),
java_8_path: None,
java_17_path: None,
java_globals: JavaGlobals::new(),
default_user: None,
hooks: Hooks::default(),
max_concurrent_downloads: 64,

View File

@@ -140,7 +140,6 @@ impl Tags {
let licenses = self.fetch_tag("license");
let donation_platforms = self.fetch_tag("donation_platform");
let report_types = self.fetch_tag("report_type");
let (
categories,
loaders,
@@ -241,14 +240,6 @@ pub struct Loader {
pub supported_project_types: Vec<String>,
}
#[derive(Debug, Clone, Decode, Encode, Serialize, Deserialize)]
pub struct GameVersion {
pub version: String,
pub version_type: String,
pub date: String,
pub major: bool,
}
#[derive(Debug, Clone, Decode, Encode, Serialize, Deserialize)]
pub struct License {
pub short: String,
@@ -260,3 +251,11 @@ pub struct DonationPlatform {
pub short: String,
pub name: String,
}
#[derive(Debug, Clone, Decode, Encode, Serialize, Deserialize)]
pub struct GameVersion {
pub version: String,
pub version_type: String,
pub date: String,
pub major: bool,
}