summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ozone-cli/src/main.rs46
-rw-r--r--ozone/src/launcher.rs2
-rw-r--r--ozone/src/launcher/settings.rs46
3 files changed, 69 insertions, 25 deletions
diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs
index adfeb71..e0cbada 100644
--- a/ozone-cli/src/main.rs
+++ b/ozone-cli/src/main.rs
@@ -2,10 +2,10 @@ mod cli;
use std::error::Error;
use std::process::ExitCode;
-use log::{error, info, trace};
+use log::{error, info, trace, LevelFilter};
use clap::Parser;
-use ozone::launcher::{Launcher, Settings};
-use ozone::launcher::version::VersionList;
+use ozone::launcher::{Instance, Launcher, Profile, Settings};
+use ozone::launcher::version::{VersionList, VersionResult};
use crate::cli::{Cli, ProfileCommand, RootCommand};
async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> {
@@ -38,7 +38,7 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> {
let exists = if settings.get_instances().contains_key(profile.get_instance_name()) { "" } else { " (missing!)" };
println!("Profile {name}:{sel}");
- println!(" Version: {}", profile.get_version());
+ println!(" Version: {}", profile.game_version);
println!(" Instance: {}{}", profile.get_instance_name(), exists);
}
},
@@ -48,23 +48,46 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> {
return Ok(ExitCode::FAILURE);
}
- if let Some(ref src) = args.clone {
+ if let Err(e) = Profile::check_name(&args.name) {
+ eprintln!("The profile name is invalid: {e}");
+ return Ok(ExitCode::FAILURE);
+ }
+
+ let mut profile = if let Some(ref src) = args.clone {
if let Some(profile) = settings.get_profiles().get(src) {
- let profile = profile.clone();
- settings.profiles.insert(args.name.clone(), profile);
+ profile.clone()
} else {
eprintln!("Unknown profile `{src}'.");
return Ok(ExitCode::FAILURE);
}
+ } else {
+ let inst_name = args.instance.as_ref().unwrap_or(&args.name);
+ if let Err(e) = Instance::check_name(inst_name) {
+ eprintln!("The profile name is invalid for an instance: {e}");
+ eprintln!("Please specify an instance name manually with --instance.");
+ return Ok(ExitCode::FAILURE);
+ }
- return Ok(ExitCode::SUCCESS);
- }
+ Profile::new(inst_name)
+ };
// creating a new profile from scratch
todo!()
},
ProfileCommand::Select(args) => {
-
+ let ver = VersionList::new(home.join("versions"), !cli.offline).await?;
+
+ match ver.get_version_lazy(&args.profile) {
+ VersionResult::None => {
+ println!("Unknown version");
+ },
+ VersionResult::Remote(v) => {
+ println!("Remote version: {v:?}");
+ },
+ VersionResult::Complete(v) => {
+ println!("Complete version: {v:?}");
+ }
+ }
}
_ => todo!()
},
@@ -92,7 +115,8 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> {
#[tokio::main]
async fn main() -> ExitCode {
- simple_logger::SimpleLogger::new().env().init().unwrap();
+ // use Warn as the default level to minimize noise on the command line
+ simple_logger::SimpleLogger::new().with_level(LevelFilter::Warn).env().init().unwrap();
let arg = Cli::parse();
diff --git a/ozone/src/launcher.rs b/ozone/src/launcher.rs
index 6feeab5..5cda9d7 100644
--- a/ozone/src/launcher.rs
+++ b/ozone/src/launcher.rs
@@ -331,7 +331,7 @@ impl Launcher {
pub async fn prepare_launch(&self, profile: &Profile, instance: &Instance, client_id: Uuid) -> Result<Launch, LaunchError> {
let start = Instant::now();
let feature_matcher = ProfileFeatureMatcher { profile };
- let version_id = profile.get_version();
+ let version_id = &profile.game_version;
let version_id = self.versions.get_profile_version_id(version_id);
diff --git a/ozone/src/launcher/settings.rs b/ozone/src/launcher/settings.rs
index c480c33..62d72c2 100644
--- a/ozone/src/launcher/settings.rs
+++ b/ozone/src/launcher/settings.rs
@@ -14,7 +14,7 @@ use uuid::Uuid;
use super::constants;
lazy_static! {
- pub static ref VALID_IDENTIFIER: Regex = Regex::new("^[a-z0-9_.\\-]+$").expect("hardcoded regex");
+ static ref VALID_IDENTIFIER: Regex = Regex::new("^[a-z0-9_.\\-]{1,128}$").expect("hardcoded regex");
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -43,6 +43,14 @@ impl SettingsData {
return Err(format!("selected instance {} does not exist", self.selected_instance.as_ref().unwrap()));
}
+ if let Some(key) = self.profiles.keys().find(|k| Profile::check_name(k).is_err()) {
+ return Err(format!("profile {key} has an invalid name"));
+ }
+
+ if let Some(key) = self.instances.keys().find(|k| Instance::check_name(k).is_err()) {
+ return Err(format!("instance {key} has an invalid name"));
+ }
+
Ok(())
}
}
@@ -182,11 +190,19 @@ impl Settings {
pub fn get_selected_profile(&self) -> Option<&Profile> {
self.inner.selected_profile.as_ref().and_then(|s| self.inner.profiles.get(s))
}
+
+ fn check_identifier(ident: &str) -> Result<(), &'static str> {
+ if VALID_IDENTIFIER.is_match(ident) {
+ Ok(())
+ } else {
+ Err("must contain 1-128 lowercase characters, digits, and the following symbols: _ . -")
+ }
+ }
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Instance {
- path: PathBuf // relative to launcher home (or absolute)
+ pub path: PathBuf // relative to launcher home (or absolute)
}
#[derive(Deserialize, Serialize, Debug, Clone)]
@@ -238,17 +254,17 @@ impl JavaRuntimeSetting {
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Profile {
- game_version: ProfileVersion,
- java_runtime: Option<JavaRuntimeSetting>,
- instance: String,
+ pub game_version: ProfileVersion,
+ pub java_runtime: Option<JavaRuntimeSetting>,
+ pub instance: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
- jvm_arguments: Vec<String>,
+ pub jvm_arguments: Vec<String>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
- jni_launch: bool,
+ pub jni_launch: bool,
#[serde(skip_serializing_if = "Option::is_none")]
- resolution: Option<Resolution>
+ pub resolution: Option<Resolution>
}
impl<P: AsRef<Path>> From<P> for Instance {
@@ -267,6 +283,10 @@ impl Instance {
fs::canonicalize(path).await
}
}
+
+ pub fn check_name(name: &str) -> Result<(), &'static str> {
+ Settings::check_identifier(name)
+ }
}
const DEF_JVM_ARGUMENTS: [&str; 7] = [
@@ -280,7 +300,7 @@ const DEF_JVM_ARGUMENTS: [&str; 7] = [
];
impl Profile {
- fn new(instance_name: &str) -> Self {
+ pub fn new(instance_name: &str) -> Self {
Self {
game_version: ProfileVersion::LatestRelease,
java_runtime: None,
@@ -291,10 +311,6 @@ impl Profile {
}
}
- pub fn get_version(&self) -> &ProfileVersion {
- &self.game_version
- }
-
pub fn get_instance_name(&self) -> &str {
&self.instance
}
@@ -314,4 +330,8 @@ impl Profile {
pub fn is_jni_launch(&self) -> bool {
self.jni_launch
}
+
+ pub fn check_name(name: &str) -> Result<(), &'static str> {
+ Settings::check_identifier(name)
+ }
}