From c21df3c73ae0dd18999f72504f96930f2c69b4eb Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Wed, 1 Jan 2025 03:06:56 -0600 Subject: add string sub algorithm --- src/launcher/profile.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src/launcher/profile.rs') diff --git a/src/launcher/profile.rs b/src/launcher/profile.rs index 835d912..104faef 100644 --- a/src/launcher/profile.rs +++ b/src/launcher/profile.rs @@ -1,8 +1,33 @@ -use super::instance::Instance; +use std::path::{Path, PathBuf}; +use serde::{Deserialize, Serialize}; -struct Profile<'l> { - name: String, - version_id: String, - java_runtime: Option, - instance: &'l Instance +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct Instance { + pub name: String, + pub path: Option // relative to launcher home (or absolute) +} + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct Profile { + pub version_id: String, + pub java_runtime: Option, + pub instance: String // ugly that this is a string instead of reference to an Instance but whatever I'm lazy +} + +impl Instance { + fn instance_dir(home: impl AsRef, name: impl AsRef) -> PathBuf { + let mut out = home.as_ref().join("instances"); + out.push(name); + out + } + + pub fn get_path(&self, home: impl AsRef) -> PathBuf { + self.path.as_ref().map(|p| { + if p.is_relative() { + Self::instance_dir(home.as_ref(), p) + } else { + p.to_owned() + } + }).unwrap_or_else(|| Self::instance_dir(home, &self.name)) + } } \ No newline at end of file -- cgit v1.2.3-70-g09d2