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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
mod cli;
use std::error::Error;
use std::process::ExitCode;
use log::{error, info, trace, LevelFilter};
use clap::Parser;
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>> {
let Some(home) = cli.home.or_else(Launcher::sensible_home) else {
error!("Could not choose a launcher home directory. Please choose one with `--home'.");
return Ok(ExitCode::FAILURE); // we print our own error message
};
trace!("Sensible home could be {home:?}");
let mut settings = Settings::load(home.join("ozone.json")).await?;
match &cli.subcmd {
RootCommand::Profile(p) => match p.command() {
ProfileCommand::List => {
let mut first = true;
if settings.get_profiles().is_empty() {
eprintln!("There are no profiles. Create one with `profile create <name>'.");
return Ok(ExitCode::SUCCESS);
}
for (name, profile) in settings.get_profiles().iter() {
if !first {
println!();
}
first = false;
let sel = if settings.get_selected_profile_name().is_some_and(|n| n == name) { " (selected)" } else { "" };
let exists = if settings.get_instances().contains_key(profile.get_instance_name()) { "" } else { " (missing!)" };
println!("Profile {name}:{sel}");
println!(" Version: {}", profile.game_version);
println!(" Instance: {}{}", profile.get_instance_name(), exists);
}
},
ProfileCommand::Create(args) => {
if settings.profiles.contains_key(&args.name) {
eprintln!("A profile with that name already exists.");
return Ok(ExitCode::FAILURE);
}
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) {
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);
}
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!()
},
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!()
}
Ok(ExitCode::SUCCESS)
}
#[tokio::main]
async fn main() -> ExitCode {
// 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();
main_inner(arg).await.unwrap_or_else(|e| {
error!("Launcher initialization error:");
error!("{e}");
ExitCode::FAILURE
})
/*let launcher = Launcher::new("./work", true).await?;
*/
}
|