Skip to content

Commit 55e0b5f

Browse files
committed
add checkbox whether to include flap
1 parent a488826 commit 55e0b5f

7 files changed

Lines changed: 131 additions & 80 deletions

File tree

locales/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"gui.mode.mmc": "MultiMC/PrismLauncher",
3636
"gui.mode.server": "Server",
3737
"gui.ui.show_loader_betas": "Beta-Versionen Anzeigen",
38+
"gui.checkbox.include_flap": "Flap mitliefern",
3839
"client.error.directory_does_not_exist": "Der Ordner %{dir} existiert nicht. Stelle sicher, dass du den richtigen Ordner ausgewählt und dass du das Spiel mindestens einmal vorher gestartet hast.",
3940
"client.info.installation_start": "Installiere client für %{version} mit %{loader} Loader %{loader_version} nach %{destination}",
4041
"client.info.fetching_launch_jsons": "Hole Start-jsons...",

locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"gui.mode.mmc": "MultiMC/PrismLauncher",
3636
"gui.mode.server": "Server",
3737
"gui.ui.show_loader_betas": "Show Betas",
38+
"gui.checkbox.include_flap":"Include Flap",
3839
"client.error.directory_does_not_exist": "The directory %{dir} does not exist. Make sure you selected the correct folder and that you have started the game at least once before.",
3940
"client.info.installation_start": "Installing client for %{version} using %{loader} Loader %{loader_version} to %{destination}",
4041
"client.info.fetching_launch_jsons": "Fetching launch jsons...",

src/actions/client.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub async fn install(
2323
generation: Option<u32>,
2424
location: PathBuf,
2525
create_profile: bool,
26+
include_flap: bool,
2627
) -> Result<(), InstallerError> {
2728
if !location.exists() {
2829
return Err(InstallerError::from(t!(
@@ -76,24 +77,26 @@ pub async fn install(
7677
std::fs::remove_dir_all(&profile_dir)?;
7778
}
7879

79-
maven::download_latest_release("flap", &flap_jar).await?;
80-
81-
if let Some(obj) = ornithe_launch_json.as_object_mut() {
82-
if !obj.contains_key("arguments") {
83-
let a = Value::Object(Map::new());
84-
obj.insert("arguments".to_string(), a);
85-
};
86-
let arguments = obj.get_mut("arguments").unwrap();
87-
if let Some(args) = arguments.as_object_mut() {
88-
if !args.contains_key("jvm") {
89-
args.insert("jvm".to_string(), Value::Array(Vec::new()));
90-
}
91-
let jvm_args = args.get_mut("jvm").unwrap().as_array_mut();
92-
if let Some(jvm) = jvm_args {
93-
jvm.insert(
94-
0,
95-
json!(format!("-javaagent:{}", flap_jar.to_string_lossy())),
96-
);
80+
if include_flap {
81+
maven::download_latest_release("flap", &flap_jar).await?;
82+
83+
if let Some(obj) = ornithe_launch_json.as_object_mut() {
84+
if !obj.contains_key("arguments") {
85+
let a = Value::Object(Map::new());
86+
obj.insert("arguments".to_string(), a);
87+
};
88+
let arguments = obj.get_mut("arguments").unwrap();
89+
if let Some(args) = arguments.as_object_mut() {
90+
if !args.contains_key("jvm") {
91+
args.insert("jvm".to_string(), Value::Array(Vec::new()));
92+
}
93+
let jvm_args = args.get_mut("jvm").unwrap().as_array_mut();
94+
if let Some(jvm) = jvm_args {
95+
jvm.insert(
96+
0,
97+
json!(format!("-javaagent:{}", flap_jar.to_string_lossy())),
98+
);
99+
}
97100
}
98101
}
99102
}

src/actions/mmc_pack.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub async fn install(
3030
copy_profile_path: bool,
3131
generate_zip: bool,
3232
generation: Option<u32>,
33+
include_flap: bool,
3334
) -> Result<(), InstallerError> {
3435
let _ = sender.send((
3536
0.1,
@@ -210,26 +211,29 @@ pub async fn install(
210211
)?;
211212
}
212213

213-
zip.write_file(
214-
"patches/net.ornithemc.flap.json",
215-
serde_json::to_string(&json!({
216-
"formatVersion": 1,
217-
"name": "Flap",
218-
"type": "release",
219-
"uid": "net.ornithemc.flap",
220-
"version": flap_version,
221-
"+agents": [{
222-
"name": format!("net.ornithemc:flap:{}", flap_version),
223-
"url": maven::MAVEN_URL
224-
}]
225-
}))?
226-
.as_bytes(),
227-
)?;
228-
pack_components.push(json!({
229-
"cachedName": "Flap",
230-
"cachedVersion": flap_version,
231-
"uid": "net.ornithemc.flap"
232-
}));
214+
if include_flap {
215+
zip.write_file(
216+
"patches/net.ornithemc.flap.json",
217+
serde_json::to_string(&json!({
218+
"formatVersion": 1,
219+
"name": "Flap",
220+
"type": "release",
221+
"uid": "net.ornithemc.flap",
222+
"version": flap_version,
223+
"+agents": [{
224+
"name": format!("net.ornithemc:flap:{}", flap_version),
225+
"url": maven::MAVEN_URL
226+
}]
227+
}))?
228+
.as_bytes(),
229+
)?;
230+
231+
pack_components.push(json!({
232+
"cachedName": "Flap",
233+
"cachedVersion": flap_version,
234+
"uid": "net.ornithemc.flap"
235+
}));
236+
}
233237

234238
zip.write_file(
235239
"mmc-pack.json",

src/actions/server.rs

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub async fn install(
3131
generation: Option<u32>,
3232
location: PathBuf,
3333
install_server: bool,
34+
include_flap: bool,
3435
) -> Result<(), InstallerError> {
3536
install_path(
3637
sender.clone(),
@@ -41,6 +42,7 @@ pub async fn install(
4142
&generation,
4243
&location,
4344
install_server,
45+
include_flap,
4446
)
4547
.await?;
4648

@@ -68,6 +70,7 @@ async fn install_path(
6870
generation: &Option<u32>,
6971
location: &PathBuf,
7072
install_server: bool,
73+
include_flap: bool,
7174
) -> Result<(), InstallerError> {
7275
if !location.exists() {
7376
std::fs::create_dir_all(&location)?;
@@ -168,13 +171,17 @@ async fn install_path(
168171
library_files.spawn(async move { download_library(&dir, name, url).await });
169172
}
170173

171-
let flap_version = maven::get_latest_version("flap").await?;
172-
let flap_path = library_dir.join(format!(
173-
"net/ornithemc/flap/flap-{}.jar",
174-
flap_version.version
175-
));
176-
{
177-
let out_path = flap_path.clone();
174+
let flap_path = if include_flap {
175+
let flap_version = maven::get_latest_version("flap").await?;
176+
Some(library_dir.join(format!(
177+
"net/ornithemc/flap/flap-{}.jar",
178+
flap_version.version
179+
)))
180+
} else {
181+
None
182+
};
183+
if include_flap {
184+
let out_path = flap_path.as_ref().unwrap().clone();
178185
library_files.spawn(async move {
179186
maven::download_latest_release("flap", &out_path).await?;
180187
Ok(out_path)
@@ -246,7 +253,7 @@ async fn install_path(
246253
&launch_main_class,
247254
&downloaded_library_files,
248255
jvm_args,
249-
flap_path.strip_prefix(&location.canonicalize()?)?,
256+
flap_path.as_deref(),
250257
)
251258
.await?;
252259

@@ -269,7 +276,7 @@ async fn create_launch_jar(
269276
launch_main_class: &str,
270277
library_files: &Vec<PathBuf>,
271278
jvm_args: Vec<String>,
272-
flap_jar_path: &Path,
279+
flap_jar_path: Option<&Path>,
273280
) -> Result<(), InstallerError> {
274281
let jar_out = install_location.join(loader_type.get_name().to_owned() + "-server-launch.jar");
275282
if jar_out.exists() {
@@ -288,10 +295,19 @@ async fn create_launch_jar(
288295
}
289296
}
290297

291-
let mut jar_manifest = launch_jar.by_path("META-INF/MANIFEST.MF")?;
292-
let mut mf = String::new();
293-
jar_manifest.read_to_string(&mut mf)?;
294-
write!(manifest, "{}", mf.replace("\n\r\n", "\n"))?;
298+
if flap_jar_path.is_some() {
299+
let mut jar_manifest = launch_jar.by_path("META-INF/MANIFEST.MF")?;
300+
let mut mf = String::new();
301+
jar_manifest.read_to_string(&mut mf)?;
302+
write!(manifest, "{}", mf.replace("\n\r\n", "\n"))?;
303+
} else {
304+
writeln!(manifest, "Manifest-Version: 1.0\r")?;
305+
writeln!(
306+
manifest,
307+
"{}\r",
308+
wrap_manifest_line(&format!("Main-Class: {}", launch_main_class))
309+
)?;
310+
}
295311
zip.start_file("META-INF/MANIFEST.MF", SimpleFileOptions::default())?;
296312

297313
let mut class_path = String::from("Class-Path: ");
@@ -310,12 +326,14 @@ async fn create_launch_jar(
310326
)?;
311327
zip.write_all(&manifest)?;
312328

313-
zip.start_file("ornithe-args.json", SimpleFileOptions::default())?;
314-
zip.write_all(&serde_json::to_vec(&json!({
315-
"flap_jar": flap_jar_path,
316-
"main_class": launch_main_class,
317-
"jvm_args": jvm_args
318-
}))?)?;
329+
if let Some(flap_path) = flap_jar_path {
330+
zip.start_file("ornithe-args.json", SimpleFileOptions::default())?;
331+
zip.write_all(&serde_json::to_vec(&json!({
332+
"flap_jar": flap_path,
333+
"main_class": launch_main_class,
334+
"jvm_args": jvm_args
335+
}))?)?;
336+
}
319337

320338
if loader_type == &LoaderType::Fabric {
321339
zip.start_file(
@@ -399,6 +417,7 @@ pub async fn install_and_run<I, S>(
399417
loader_version: LoaderVersion,
400418
generation: Option<u32>,
401419
location: PathBuf,
420+
include_flap: bool,
402421
java: Option<&PathBuf>,
403422
args: Option<I>,
404423
) -> Result<bool, InstallerError>
@@ -429,6 +448,7 @@ where
429448
&generation,
430449
&location,
431450
true,
451+
include_flap,
432452
)
433453
.await?;
434454
}

src/ui/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ async fn do_install(
223223
info.calamus_generation,
224224
location,
225225
create_profile,
226+
!matches.get_flag("exclude-flap"),
226227
)
227228
.await?;
228229
return Ok(InstallationResult::Installed);
@@ -249,6 +250,7 @@ async fn do_install(
249250
loader_version,
250251
info.calamus_generation,
251252
location,
253+
!matches.get_flag("exclude-flap"),
252254
java,
253255
run_args.map(|s| s.split(" ")),
254256
)
@@ -267,6 +269,7 @@ async fn do_install(
267269
info.calamus_generation,
268270
location,
269271
matches.get_flag("download-minecraft"),
272+
!matches.get_flag("exclude-flap"),
270273
)
271274
.await?;
272275
return Ok(InstallationResult::Installed);
@@ -296,6 +299,7 @@ async fn do_install(
296299
copy_profile_path,
297300
generate_zip,
298301
info.calamus_generation,
302+
!matches.get_flag("exclude-flap"),
299303
)
300304
.await?;
301305
return Ok(InstallationResult::Installed);
@@ -417,6 +421,7 @@ fn add_arguments(command: Command) -> Command {
417421
.value_parser(["fabric", "quilt"]),
418422
)
419423
.arg(arg!(--"loader-version" <VERSION> "Loader version to use").default_value("latest"))
424+
.arg(arg!(--"exclude-flap" "Do not include Flap (Cross-Intermediary Generation Remapper)"))
420425
}
421426

422427
fn add_gen_argument(command: Command) -> Command {

0 commit comments

Comments
 (0)