Skip to content

Commit ca8ceb7

Browse files
committed
add additional checkbox for historical versions
1 parent d6e5df8 commit ca8ceb7

File tree

4 files changed

+86
-20
lines changed

4 files changed

+86
-20
lines changed

src/actions/mmc_pack.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ pub async fn install(
7272
let output_file = if generate_zip {
7373
output_dir.join("Ornithe-".to_owned() + &version.id + ".zip")
7474
} else {
75-
output_dir.join("Ornithe-".to_owned() + &version.id)
75+
let dir = output_dir.join("Ornithe-".to_owned() + &version.id);
76+
if std::fs::exists(&dir).unwrap_or_default() {
77+
return Err(InstallerError("Instance already exists".to_string()));
78+
}
79+
std::fs::create_dir_all(&dir)?;
80+
dir
7681
};
7782

7883
info!("Fetching library information...");

src/net/manifest.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ impl MinecraftVersion {
136136
GameSide::Server => downloads.server,
137137
})
138138
}
139+
140+
pub fn is_snapshot(&self) -> bool {
141+
self._type == "snapshot"
142+
}
143+
144+
pub fn is_historical(&self) -> bool {
145+
!self.is_release() && !self.is_snapshot() && self._type != "pending"
146+
}
147+
148+
pub fn is_release(&self) -> bool {
149+
self._type == "release"
150+
}
139151
}
140152

141153
#[allow(dead_code)]

src/ui/cli.rs

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{io::Write, path::PathBuf};
22

33
use clap::{ArgMatches, Command, arg, command, value_parser};
4+
use log::info;
45

56
use crate::{
67
errors::InstallerError,
@@ -10,6 +11,12 @@ use crate::{
1011
},
1112
};
1213

14+
#[derive(PartialEq, Eq)]
15+
enum InstallationResult {
16+
Installed,
17+
NotInstalled,
18+
}
19+
1320
pub async fn run() {
1421
let matches = command!()
1522
.arg_required_else_help(true)
@@ -40,7 +47,7 @@ pub async fn run() {
4047
.default_value(super::current_location())
4148
.value_parser(value_parser!(PathBuf)),
4249
)
43-
.arg(arg!(-z --"generate-zip" <VALUE> "Whether to generate an instance zip instead of installing into the directory")
50+
.arg(arg!(-z --"generate-zip" <VALUE> "Whether to generate an instance zip instead of installing an instance into the directory")
4451
.default_value("true").value_parser(value_parser!(bool)))
4552
.arg(arg!(-c --"copy-profile-path" <VALUE> "Whether to copy the path of the generated profile to the clipboard")
4653
.default_value("false").value_parser(value_parser!(bool))
@@ -67,7 +74,8 @@ pub async fn run() {
6774
.long_flag("list-game-versions")
6875
.long_flag_alias("list-minecraft-versions")
6976
.about("List supported game versions")
70-
.arg(arg!(-s --"show-snapshots" "Include snapshot versions")),
77+
.arg(arg!(-s --"show-snapshots" "Include snapshot versions"))
78+
.arg(arg!(--"show-historical" "Include historical versions")),
7179
)
7280
.subcommand(
7381
Command::new("loader-versions")
@@ -82,7 +90,16 @@ pub async fn run() {
8290
.get_matches();
8391

8492
match parse(matches).await {
85-
Ok(_) => {}
93+
Ok(r) => {
94+
if r == InstallationResult::Installed {
95+
info!("Installation complete!");
96+
info!("Ornithe has been successfully installed.");
97+
info!(
98+
"Most mods require that you also download the Ornithe Standard Libraries mod and place it in your mods folder."
99+
);
100+
info!("You can find it at {}", crate::OSL_MODRINTH_URL);
101+
}
102+
}
86103
Err(e) => {
87104
std::io::stderr()
88105
.write_all(("Failed to load Ornithe Installer CLI: ".to_owned() + &e.0).as_bytes())
@@ -91,7 +108,7 @@ pub async fn run() {
91108
}
92109
}
93110

94-
async fn parse(matches: ArgMatches) -> Result<(), InstallerError> {
111+
async fn parse(matches: ArgMatches) -> Result<InstallationResult, InstallerError> {
95112
if let Some(matches) = matches.subcommand_matches("loader-versions") {
96113
let versions = crate::net::meta::fetch_loader_versions().await?;
97114
let loader_type = get_loader_type(matches)?;
@@ -120,7 +137,7 @@ async fn parse(matches: ArgMatches) -> Result<(), InstallerError> {
120137
)?;
121138
writeln!(std::io::stdout(), "{}", out)?;
122139

123-
return Ok(());
140+
return Ok(InstallationResult::NotInstalled);
124141
}
125142

126143
let minecraft_versions = crate::net::manifest::fetch_versions().await?;
@@ -140,14 +157,26 @@ async fn parse(matches: ArgMatches) -> Result<(), InstallerError> {
140157
if let Some(matches) = matches.subcommand_matches("game-versions") {
141158
let mut out = String::new();
142159
let snapshots = matches.get_flag("show-snapshots");
160+
let historical = matches.get_flag("show-historical");
143161
for version in available_minecraft_versions {
144-
if snapshots || version._type == "release" {
162+
let mut displayed = if snapshots && historical {
163+
true
164+
} else {
165+
version.is_release()
166+
};
167+
if !displayed && snapshots {
168+
displayed |= version.is_snapshot();
169+
}
170+
if !displayed && historical {
171+
displayed |= version.is_historical();
172+
}
173+
if displayed {
145174
out += &(version.id.clone() + " ");
146175
}
147176
}
148177
writeln!(std::io::stdout(), "Available Minecraft versions:\n")?;
149178
writeln!(std::io::stdout(), "{}", out)?;
150-
return Ok(());
179+
return Ok(InstallationResult::NotInstalled);
151180
}
152181

153182
let loader_versions = crate::net::meta::fetch_loader_versions().await?;
@@ -159,14 +188,15 @@ async fn parse(matches: ArgMatches) -> Result<(), InstallerError> {
159188
let loader_version = get_loader_version(matches, loader_versions)?;
160189
let location = matches.get_one::<PathBuf>("dir").unwrap().clone();
161190
let create_profile = matches.get_flag("generate-profile");
162-
return crate::actions::client::install(
191+
crate::actions::client::install(
163192
minecraft_version,
164193
loader_type,
165194
loader_version,
166195
location,
167196
create_profile,
168197
)
169-
.await;
198+
.await?;
199+
return Ok(InstallationResult::Installed);
170200
}
171201

172202
if let Some(matches) = matches.subcommand_matches("server") {
@@ -178,24 +208,26 @@ async fn parse(matches: ArgMatches) -> Result<(), InstallerError> {
178208
if let Some(matches) = matches.subcommand_matches("run") {
179209
let java = matches.get_one::<PathBuf>("java");
180210
let run_args = matches.get_one::<String>("args");
181-
return crate::actions::server::install_and_run(
211+
crate::actions::server::install_and_run(
182212
minecraft_version,
183213
loader_type,
184214
loader_version,
185215
location,
186216
java,
187217
run_args.map(|s| s.split(" ")),
188218
)
189-
.await;
219+
.await?;
220+
return Ok(InstallationResult::Installed);
190221
}
191-
return crate::actions::server::install(
222+
crate::actions::server::install(
192223
minecraft_version,
193224
loader_type,
194225
loader_version,
195226
location,
196227
matches.get_flag("download-minecraft"),
197228
)
198-
.await;
229+
.await?;
230+
return Ok(InstallationResult::Installed);
199231
}
200232

201233
if let Some(matches) = matches.subcommand_matches("mmc") {
@@ -209,18 +241,19 @@ async fn parse(matches: ArgMatches) -> Result<(), InstallerError> {
209241
.unwrap()
210242
.clone();
211243
let generate_zip = matches.get_one::<bool>("generate-zip").unwrap().clone();
212-
return crate::actions::mmc_pack::install(
244+
crate::actions::mmc_pack::install(
213245
minecraft_version,
214246
loader_type,
215247
loader_version,
216248
output_dir,
217249
copy_profile_path,
218250
generate_zip,
219251
)
220-
.await;
252+
.await?;
253+
return Ok(InstallationResult::Installed);
221254
}
222255

223-
Ok(())
256+
Ok(InstallationResult::NotInstalled)
224257
}
225258

226259
fn get_minecraft_version(

src/ui/gui.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct App {
8282
available_minecraft_versions: Vec<MinecraftVersion>,
8383
available_intermediary_versions: Vec<String>,
8484
show_snapshots: bool,
85+
show_historical: bool,
8586
selected_loader_type: LoaderType,
8687
selected_loader_version: String,
8788
available_loader_versions: HashMap<LoaderType, Vec<LoaderVersion>>,
@@ -138,6 +139,7 @@ impl App {
138139
available_minecraft_versions,
139140
available_intermediary_versions,
140141
show_snapshots: false,
142+
show_historical: false,
141143
selected_loader_type: LoaderType::Fabric,
142144
selected_loader_version: available_loader_versions
143145
.get(&LoaderType::Fabric)
@@ -223,17 +225,31 @@ impl App {
223225
}),
224226
)
225227
})
226-
.filter(|v| self.show_snapshots || v._type == "release")
228+
.filter(|v| {
229+
if self.show_snapshots && self.show_historical {
230+
return true;
231+
}
232+
let mut displayed = v.is_release();
233+
if !displayed && self.show_snapshots {
234+
displayed = v.is_snapshot();
235+
}
236+
if !displayed && self.show_historical {
237+
displayed = v.is_historical();
238+
}
239+
displayed
240+
})
227241
.map(|v| v.id.clone())
228242
.collect::<Vec<String>>(),
229243
"minecraft_version",
230244
&mut self.selected_minecraft_version,
231245
|ui, text| ui.selectable_label(false, text),
232246
)
233247
.max_height(130.0)
248+
.desired_width(170.0)
234249
.hint_text("Search available versions..."),
235250
);
236-
ui.checkbox(&mut self.show_snapshots, "Show Snapshots")
251+
ui.checkbox(&mut self.show_snapshots, "Snapshots");
252+
ui.checkbox(&mut self.show_historical, "Historical Versions");
237253
});
238254
}
239255

@@ -291,8 +307,8 @@ impl App {
291307
.get(&self.selected_loader_type)
292308
.unwrap()
293309
.iter()
310+
.filter(|v| self.show_betas || v.is_stable())
294311
.map(|v| v.version.clone())
295-
.filter(|v| self.show_betas || !v.contains("-"))
296312
.next()
297313
.unwrap()
298314
.clone();

0 commit comments

Comments
 (0)