diff options
| author | 2025-01-01 16:40:02 -0600 | |
|---|---|---|
| committer | 2025-01-01 16:40:02 -0600 | |
| commit | 74c7d40d25f7ee294546c419a016916fa6fa5f10 (patch) | |
| tree | 4e3f56925bb94fe3dfe6994c938c6c9e959493b9 /src | |
| parent | prelim launcher init code (diff) | |
make prev_char more concise
Diffstat (limited to 'src')
| -rw-r--r-- | src/launcher.rs | 160 | ||||
| -rw-r--r-- | src/launcher/strsub.rs | 16 |
2 files changed, 83 insertions, 93 deletions
diff --git a/src/launcher.rs b/src/launcher.rs index a4a36e2..0e1639d 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -1,80 +1,82 @@ -mod constants;
-mod version;
-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};
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct Settings {
- profiles: HashMap<String, Profile>,
- instances: HashMap<String, Instance>
-}
-
-pub struct Launcher {
- home: PathBuf,
- versions: VersionList,
-
- settings_path: PathBuf, // maybe redundant but idc >:3
- settings: Settings,
-}
-
-impl Launcher {
- // FIXME: more descriptive error type por favor
- pub async fn new(home: &Path, online: bool) -> Result<Launcher, Box<dyn Error>> {
- 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<dyn Error>> {
- /* 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!()
- }
+mod constants; +mod version; +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}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Settings { + profiles: HashMap<String, Profile>, + instances: HashMap<String, Instance> +} + +pub struct Launcher { + online: bool, + home: PathBuf, + versions: VersionList, + + settings_path: PathBuf, // maybe redundant but idc >:3 + settings: Settings, +} + +impl Launcher { + // FIXME: more descriptive error type por favor + pub async fn new(home: &Path, online: bool) -> Result<Launcher, Box<dyn Error>> { + 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 { + online, + home: home.to_owned(), + versions, + settings_path, + settings + }) + } + + pub async fn launch(profile: &Profile) -> Result<(), Box<dyn Error>> { + /* 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 447021a..a50555d 100644 --- a/src/launcher/strsub.rs +++ b/src/launcher/strsub.rs @@ -6,20 +6,8 @@ const VAR_BEGIN: &str = "${"; const VAR_END: &str = "}"; const VAR_DEFAULT: &str = ":-"; -fn prev_char(slice: &str, mut idx: usize) -> Option<(usize, char)> { - if idx == 0 || idx >= slice.len() { - return None; - } - - loop { - // will never panic because the condition always succeeds for idx == 0 - // (the precondition will handle cases where the slice is empty) - idx -= 1; - - if slice.is_char_boundary(idx) { - return Some((idx, slice[idx..].chars().next().unwrap())) - } - } +fn prev_char(slice: &str, idx: usize) -> Option<(usize, char)> { + slice[..idx].char_indices().rev().next() } // basically the same thing as replace_string, but it creates the String itself and returns it. |
