summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ozone-cli/src/cli.rs28
-rw-r--r--ozone-cli/src/main.rs37
-rw-r--r--ozone/src/launcher.rs10
-rw-r--r--ozone/src/launcher/settings.rs20
4 files changed, 69 insertions, 26 deletions
diff --git a/ozone-cli/src/cli.rs b/ozone-cli/src/cli.rs
index d288e3c..407ee50 100644
--- a/ozone-cli/src/cli.rs
+++ b/ozone-cli/src/cli.rs
@@ -1,10 +1,28 @@
use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
+#[derive(Args, Debug)]
+pub struct ProfileSelectArgs {
+ /// The name of the profile to select.
+ #[arg(index = 1)]
+ pub profile: String
+}
+
+#[derive(Args, Debug)]
+pub struct ProfileCreateArgs {
+ /// The name of the new profile.
+ #[arg(index = 1)]
+ pub name: String,
+
+ /// Clone profile information from an existing profile.
+ #[arg(long, short = 'c')]
+ pub clone: String
+}
+
#[derive(Subcommand, Debug)]
pub enum ProfileCommand {
- Select,
- Create,
+ Select(ProfileSelectArgs),
+ Create(ProfileCreateArgs),
List
}
@@ -15,8 +33,8 @@ pub struct ProfileArgs {
}
impl ProfileArgs {
- pub fn take_command(&mut self) -> ProfileCommand {
- self.subcmd.take().unwrap_or(ProfileCommand::List)
+ pub fn command(&self) -> &ProfileCommand {
+ self.subcmd.as_ref().unwrap_or(&ProfileCommand::List)
}
}
@@ -24,7 +42,7 @@ impl ProfileArgs {
pub enum RootCommand {
Profile(ProfileArgs),
Instance,
-
+ Launch
}
#[derive(Parser, Debug)]
diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs
index d0d7b21..346532a 100644
--- a/ozone-cli/src/main.rs
+++ b/ozone-cli/src/main.rs
@@ -16,15 +16,32 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> {
info!("Sensible home could be {home:?}");
let settings = Settings::load(home.join("ozone.json")).await?;
- settings.save().await?;
- match cli.subcmd {
- RootCommand::Profile(mut p) => match p.take_command() {
+ match &cli.subcmd {
+ RootCommand::Profile(p) => match p.command() {
ProfileCommand::List => {
- todo!()
+ for (name, profile) in settings.get_profiles().iter() {
+ println!("{name}: {profile:#?}");
+ }
}
_ => todo!()
},
+ RootCommand::Launch => {
+ settings.save().await?;
+
+ let launcher = Launcher::new(&home, !cli.offline).await?;
+ let profile = settings.get_profiles().get("default").unwrap();
+
+ let launch = launcher.prepare_launch(profile, settings.get_instances().get(profile.get_instance_name()).unwrap(), settings.get_client_id()).await.map_err(|e| {
+ error!("error launching: {e}");
+ e
+ })?;
+
+ dbg!(&launch);
+ info!("ok");
+
+ ozone::launcher::run_the_game(&launch)?;
+ }
_ => todo!()
}
@@ -46,15 +63,5 @@ async fn main() -> ExitCode {
/*let launcher = Launcher::new("./work", true).await?;
- let profile = settings.get_profile("default").unwrap();
-
- let launch = launcher.prepare_launch(profile, settings.get_instance_for(profile)).await.map_err(|e| {
- error!("error launching: {e}");
- e
- })?;
-
- dbg!(&launch);
- info!("ok");
-
- ozone::launcher::run_the_game(&launch)?;*/
+ */
}
diff --git a/ozone/src/launcher.rs b/ozone/src/launcher.rs
index 8ee532b..2165698 100644
--- a/ozone/src/launcher.rs
+++ b/ozone/src/launcher.rs
@@ -495,17 +495,19 @@ impl Launcher {
info!("Resolving java runtime environment path");
let runtime_path;
- if let Some(ref profile_jre) = profile.get_java_runtime() {
+ if let Some(JavaRuntimeSetting::Path(ref profile_jre)) = profile.get_java_runtime() {
runtime_path = fs::canonicalize(profile_jre).await
.map_err(|e| LaunchError::ResolveJavaRuntime {what: "resolving jre path", error: e})?;
} else {
- let Some(ref java_ver) = ver.java_version else {
+ let Some(component) = profile.get_java_runtime().and_then(|r| r.get_component())
+ .or_else(|| ver.java_version.as_ref().map(|ver| ver.component.as_str())) else {
+
warn!("Version {} does not specify java version information. You must select a runtime manually.", ver.id);
return Err(LaunchError::MissingJavaRuntime);
};
- let runtime = self.java_runtimes.choose_runtime(java_ver.component.as_str()).await.map_err(LaunchError::JavaRuntimeRepo)?;
- runtime_path = self.java_runtimes.ensure_jre(java_ver.component.as_str(), runtime).await.map_err(LaunchError::JavaRuntimeRepo)?;
+ let runtime = self.java_runtimes.choose_runtime(component).await.map_err(LaunchError::JavaRuntimeRepo)?;
+ runtime_path = self.java_runtimes.ensure_jre(component, runtime).await.map_err(LaunchError::JavaRuntimeRepo)?;
}
let Some(runtime_exe_path) = runner::find_java(runtime_path.as_path(), profile.is_jni_launch()).await
diff --git a/ozone/src/launcher/settings.rs b/ozone/src/launcher/settings.rs
index a050e19..842b948 100644
--- a/ozone/src/launcher/settings.rs
+++ b/ozone/src/launcher/settings.rs
@@ -158,9 +158,25 @@ impl Default for Resolution {
}
#[derive(Deserialize, Serialize, Debug, Clone)]
+#[serde(rename_all = "lowercase")]
+pub enum JavaRuntimeSetting {
+ Path(String), // I don't want the path serialized like an OsString (because it's ugly)
+ Component(String)
+}
+
+impl JavaRuntimeSetting {
+ pub fn get_component(&self) -> Option<&str> {
+ match self {
+ JavaRuntimeSetting::Component(s) => Some(s.as_str()),
+ _ => None
+ }
+ }
+}
+
+#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Profile {
game_version: ProfileVersion,
- java_runtime: Option<String>,
+ java_runtime: Option<JavaRuntimeSetting>,
instance: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
@@ -228,7 +244,7 @@ impl Profile {
self.resolution
}
- pub fn get_java_runtime(&self) -> Option<&String> {
+ pub fn get_java_runtime(&self) -> Option<&JavaRuntimeSetting> {
self.java_runtime.as_ref()
}