diff options
Diffstat (limited to 'src/launcher/runner.rs')
| -rw-r--r-- | src/launcher/runner.rs | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/src/launcher/runner.rs b/src/launcher/runner.rs index 4d07f20..8c7af3d 100644 --- a/src/launcher/runner.rs +++ b/src/launcher/runner.rs @@ -1,13 +1,14 @@ use std::borrow::Cow; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::iter; -use crate::version::{CompleteVersion, FeatureMatcher}; +use std::process::Command; +use crate::version::{CompleteVersion, FeatureMatcher, OperatingSystem}; use super::rules::CompatCheck; use super::strsub::{self, SubFunc}; -use super::LaunchInfo; +use super::{Launch, LaunchInfo}; #[derive(Clone, Copy)] -struct LaunchArgSub<'a: 'l, 'l, F: FeatureMatcher>(&'a LaunchInfo<'l, F>); +struct LaunchArgSub<'a, 'l, F: FeatureMatcher>(&'a LaunchInfo<'l, F>); impl<'rep, 'l, F: FeatureMatcher> SubFunc<'rep> for LaunchArgSub<'rep, 'l, F> { fn substitute(&self, key: &str) -> Option<Cow<'rep, str>> { @@ -59,32 +60,6 @@ pub enum ArgumentType { Game } -struct OptionalIterator<I> -where - I: Iterator -{ - opt: Option<I> -} - -impl<I: Iterator> Iterator for OptionalIterator<I> { - type Item = I::Item; - - fn next(&mut self) -> Option<Self::Item> { - match self.opt { - Some(ref mut i) => i.next(), - None => None - } - } -} - -impl<II: IntoIterator> From<Option<II>> for OptionalIterator<II::IntoIter> { - fn from(opt: Option<II>) -> Self { - OptionalIterator { - opt: opt.map(IntoIterator::into_iter) - } - } -} - pub fn build_arguments<'l, F: FeatureMatcher>(launch: &LaunchInfo<'l, F>, version: &CompleteVersion, arg_type: ArgumentType) -> Vec<OsString> { let sub = LaunchArgSub(launch); let system_info = &launch.launcher.system_info; @@ -94,13 +69,31 @@ pub fn build_arguments<'l, F: FeatureMatcher>(launch: &LaunchInfo<'l, F>, versio ArgumentType::Game => args.game.as_ref() }) { arguments.iter() - .flat_map(|wa| OptionalIterator::from(wa.rules_apply(system_info, launch.feature_matcher).ok().map(|_| &wa.value))) + .filter(|wa| wa.rules_apply(system_info, launch.feature_matcher).is_ok()) + .flat_map(|wa| &wa.value) .map(|s| OsString::from(strsub::replace_string(s, &sub).into_owned())).collect() } else if let Some(arguments) = version.minecraft_arguments.as_ref() { match arg_type { ArgumentType::JVM => { - todo!() - } + [ + "-Djava.library.path=${natives_directory}", + "-Dminecraft.launcher.brand=${launcher_name}", + "-Dminecraft.launcher.version=${launcher_version}", + "-Dminecraft.client.jar=${primary_jar}", + "-cp", + "${classpath}" + ].into_iter() + .chain(iter::once("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump") + .take_while(|_| system_info.os == OperatingSystem::Windows)) + .chain(iter::once(["-Dos.name=Windows 10", "-Dos.version=10.0"]) + .take_while(|_| launch.feature_matcher.matches("__ozone_win10_hack")) + .flatten()) + .chain(iter::once(["-Xdock:icon=${asset=icons/minecraft.icns}", "-Xdock:name=Minecraft"]) + .take_while(|_| system_info.os == OperatingSystem::MacOS) + .flatten()) + .map(|s| OsString::from(strsub::replace_string(s, &sub).into_owned())) + .collect() + }, ArgumentType::Game => { arguments.split(' ') .chain(iter::once("--demo") @@ -116,3 +109,14 @@ pub fn build_arguments<'l, F: FeatureMatcher>(launch: &LaunchInfo<'l, F>, versio Vec::default() } } + +pub fn run_the_game(launch: &Launch) -> Result<(), Box<dyn std::error::Error>> { + Command::new("/usr/lib/jvm/java-8-openjdk-amd64/bin/java") + .args(launch.jvm_args.iter() + .map(|o| o.as_os_str()) + .chain(iter::once(OsStr::new(launch.main_class.as_str()))) + .chain(launch.game_args.iter().map(|o| o.as_os_str()))) + .current_dir(launch.instance_path.as_path()).spawn()?.wait()?; + + Ok(()) +} |
