1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Instance {
pub name: String,
pub path: Option<PathBuf> // relative to launcher home (or absolute)
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Profile {
pub version_id: String,
pub java_runtime: Option<String>,
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<Path>, name: impl AsRef<Path>) -> PathBuf {
let mut out = home.as_ref().join("instances");
out.push(name);
out
}
pub fn get_path(&self, home: impl AsRef<Path>) -> 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))
}
}
|