From 242c22e9043602e601d5299749c5c0f4c4d1cd09 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Wed, 1 Jan 2025 16:11:41 -0600 Subject: prelim launcher init code --- src/launcher.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++--- src/launcher/strsub.rs | 2 +- 2 files changed, 53 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/launcher.rs b/src/launcher.rs index 06a5d5b..a4a36e2 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -4,6 +4,8 @@ mod profile; mod strsub; use std::collections::HashMap; +use std::error::Error; +use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; use version::VersionList; use crate::launcher::profile::{Instance, Profile}; @@ -15,17 +17,64 @@ pub struct Settings { } pub struct Launcher { + home: PathBuf, versions: VersionList, + + settings_path: PathBuf, // maybe redundant but idc >:3 settings: Settings, } impl Launcher { - pub fn new(versions: VersionList, settings: Settings) -> Launcher { - Launcher { + // FIXME: more descriptive error type por favor + pub async fn new(home: &Path, online: bool) -> Result> { + let home = home.to_owned(); + let versions; + + if online { + versions = VersionList::online(home.join("versions").as_ref()).await?; + } else { + versions = VersionList::offline(home.join("versions").as_ref()).await?; + } + + let settings_path = home.join("ozone.json"); + let settings = serde_json::from_str(tokio::fs::read_to_string(&settings_path).await?.as_str())?; + + Ok(Launcher { + home: home.to_owned(), versions, + settings_path, settings - } + }) } + pub async fn launch(profile: &Profile) -> Result<(), Box> { + /* tasks 2 l;aunch the gayme!!!! :3 + * - java runtime + * - normal process (good research, past figboot :3) + * - libraries + * - check which libraries we actually need (some have classifiers that don't apply to us) + * - of the libraries we need, check which have correct size and sha1 + * - redownload necessary libraries + * - (if offline mode and there are libraries to download, then explode violently) + * - extract natives + * - logging + * - download the config if present and necessary + * - (explode if offline mode and we need to download stuff) + * - assets + * - get asset index (check if our local copy is good and redownload if not) + * - check what ones are good and what needs to be downloaded + * - download them + * - (if offline mode, explode) + * - if virtual or resource-mapped, copy (or perhaps hardlink? that would be cool) + * - the actual client jar + * - check integriddy and download if needed + * - (explode if offline mode) + * - launch the game + * - build argument list and whatnot also + */ + + + todo!() + } } \ No newline at end of file diff --git a/src/launcher/strsub.rs b/src/launcher/strsub.rs index fba449a..447021a 100644 --- a/src/launcher/strsub.rs +++ b/src/launcher/strsub.rs @@ -34,7 +34,7 @@ where // handles ${replacements} on this string IN-PLACE. Calls the "sub" function for each key it receives. // if "sub" returns None, it will use a default value or ignore the ${substitution}. -// There are no "invalid inputs" and this function should never panic. +// There are no "invalid inputs" and this function should never panic unless "sub" panics. pub fn replace_string(input: &mut String, sub: T) where T: Fn(/*key: */ &str) -> Option -- cgit v1.2.3-70-g09d2