summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2024-12-17 16:40:27 -0600
committerLibravatar bigfoot547 <[email protected]>2024-12-17 16:40:27 -0600
commitf1541829109d988e485388cf09cfa1932e1c3a99 (patch)
treea549ef8f5bb731390acc736c86bbdf2f90c8caef
parentinitial commit (diff)
remove getter business
-rw-r--r--src/version.rs158
-rw-r--r--src/version/manifest.rs78
2 files changed, 74 insertions, 162 deletions
diff --git a/src/version.rs b/src/version.rs
index d120093..0c1e65f 100644
--- a/src/version.rs
+++ b/src/version.rs
@@ -65,46 +65,20 @@ impl<'de> Deserialize<'de> for WrappedRegex {
#[derive(Deserialize, Debug)]
pub struct OSRestriction {
- name: Option<OperatingSystem>,
+ pub name: Option<OperatingSystem>,
- version: Option<WrappedRegex>,
- arch: Option<WrappedRegex>
-}
-
-impl OSRestriction {
- pub fn get_name(&self) -> Option<OperatingSystem> {
- self.name
- }
-
- pub fn get_version(&self) -> Option<&Regex> {
- self.version.as_deref()
- }
-
- pub fn get_arch(&self) -> Option<&Regex> {
- self.arch.as_deref()
- }
+ pub version: Option<WrappedRegex>,
+ pub arch: Option<WrappedRegex>
}
#[derive(Deserialize, Debug)]
pub struct CompatibilityRule {
- action: RuleAction,
- features: Option<BTreeMap<String, bool>>,
- os: Option<OSRestriction>
+ pub action: RuleAction,
+ pub features: Option<BTreeMap<String, bool>>,
+ pub os: Option<OSRestriction>
}
impl CompatibilityRule {
- pub fn get_action(&self) -> RuleAction {
- self.action
- }
-
- pub fn get_os(&self) -> Option<&OSRestriction> {
- self.os.as_ref()
- }
-
- pub fn get_features(&self) -> Option<&BTreeMap<String, bool>> {
- self.features.as_ref()
- }
-
pub fn features_match(&self, checker: fn(&str) -> bool) -> bool {
if let Some(m) = self.features.as_ref() {
for (feat, expect) in m {
@@ -121,21 +95,11 @@ impl CompatibilityRule {
#[derive(Deserialize, Debug)]
pub struct Argument {
#[serde(default)]
- rules: Option<Vec<CompatibilityRule>>,
+ pub rules: Option<Vec<CompatibilityRule>>,
#[serde(default)]
#[serde(deserialize_with = "string_or_array")]
- value: Vec<String>
-}
-
-impl Argument {
- fn get_rules(&self) -> Option<&Vec<CompatibilityRule>> {
- self.rules.as_ref()
- }
-
- fn get_value(&self) -> &Vec<String> {
- &self.value
- }
+ pub value: Vec<String>
}
#[derive(Debug)]
@@ -170,18 +134,8 @@ impl<'de> Deserialize<'de> for WrappedArgument {
#[derive(Deserialize, Debug)]
pub struct Arguments {
- game: Option<Vec<WrappedArgument>>,
- jvm: Option<Vec<WrappedArgument>>
-}
-
-impl Arguments {
- fn get_game(&self) -> Option<&Vec<WrappedArgument>> {
- self.game.as_ref()
- }
-
- fn get_jvm(&self) -> Option<&Vec<WrappedArgument>> {
- self.jvm.as_ref()
- }
+ pub game: Option<Vec<WrappedArgument>>,
+ pub jvm: Option<Vec<WrappedArgument>>
}
#[derive(Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
@@ -196,91 +150,93 @@ pub enum DownloadType {
#[derive(Deserialize, Debug)]
pub struct DownloadInfo {
- sha1: Option<String>,
- size: Option<usize>,
- total_size: Option<usize>, // available for asset index
- url: Option<String>, // may not be present for libraries
- id: Option<String>,
- path: Option<String>
+ pub sha1: Option<String>,
+ pub size: Option<usize>,
+ pub total_size: Option<usize>, // available for asset index
+ pub url: Option<String>, // may not be present for libraries
+ pub id: Option<String>,
+ pub path: Option<String>
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JavaVersionInfo {
- component: String,
- major_version: u32
+ pub component: String,
+ pub major_version: u32
}
#[derive(Deserialize, Debug)]
pub struct LibraryDownloads {
- artifact: Option<DownloadInfo>,
- classifiers: Option<BTreeMap<String, DownloadInfo>>
+ pub artifact: Option<DownloadInfo>,
+ pub classifiers: Option<BTreeMap<String, DownloadInfo>>
}
#[derive(Deserialize, Debug)]
pub struct LibraryExtractRule {
#[serde(default)]
- exclude: Vec<String>
+ pub exclude: Vec<String>
}
#[derive(Deserialize, Debug)]
pub struct Library {
- downloads: Option<LibraryDownloads>,
- name: String,
- extract: Option<LibraryExtractRule>,
- natives: Option<BTreeMap<OperatingSystem, String>>,
- rules: Option<Vec<CompatibilityRule>>,
- url: Option<String> // old format
+ pub downloads: Option<LibraryDownloads>,
+ pub name: String,
+ pub extract: Option<LibraryExtractRule>,
+ pub natives: Option<BTreeMap<OperatingSystem, String>>,
+ pub rules: Option<Vec<CompatibilityRule>>,
+ pub url: Option<String> // old format
}
#[derive(Deserialize, Debug)]
pub struct ClientLogging {
- argument: String,
- r#type: String,
- file: DownloadInfo
+ pub argument: String,
+
+ #[serde(rename = "type")]
+ pub logger_type: String,
+ pub file: DownloadInfo
}
#[derive(Deserialize, Debug)]
pub struct Logging {
- client: ClientLogging // other fields unknown
+ pub client: ClientLogging // other fields unknown
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CompleteVersion {
- arguments: Option<Arguments>,
- minecraft_arguments: Option<String>,
+ pub arguments: Option<Arguments>,
+ pub minecraft_arguments: Option<String>,
- asset_index: Option<DownloadInfo>,
- assets: Option<String>,
+ pub asset_index: Option<DownloadInfo>,
+ pub assets: Option<String>,
- compliance_level: Option<u32>,
+ pub compliance_level: Option<u32>,
- java_version: Option<JavaVersionInfo>,
+ pub java_version: Option<JavaVersionInfo>,
#[serde(default)]
- downloads: BTreeMap<DownloadType, DownloadInfo>,
+ pub downloads: BTreeMap<DownloadType, DownloadInfo>,
#[serde(default)]
- libraries: Vec<Library>,
+ pub libraries: Vec<Library>,
- id: String,
- jar: Option<String>, // used as the jar filename if specified? (no longer used officially)
+ pub id: String,
+ pub jar: Option<String>, // used as the jar filename if specified? (no longer used officially)
- logging: Option<Logging>,
+ pub logging: Option<Logging>,
- main_class: Option<String>,
- minimum_launcher_version: Option<u32>,
- release_time: Option<DateTime<Utc>>,
- time: Option<DateTime<Utc>>,
+ pub main_class: Option<String>,
+ pub minimum_launcher_version: Option<u32>,
+ pub release_time: Option<DateTime<Utc>>,
+ pub time: Option<DateTime<Utc>>,
#[serde(rename = "type")]
- version_type: Option<VersionType>,
+ pub version_type: Option<VersionType>,
- compatibility_rules: Option<Vec<CompatibilityRule>>, //
- incompatibility_reason: Option<String>, // message shown when compatibility rules fail for this version
+ pub compatibility_rules: Option<Vec<CompatibilityRule>>, //
+ pub incompatibility_reason: Option<String>, // message shown when compatibility rules fail for this version
- inherits_from: Option<String>
+ pub inherits_from: Option<String>
/* omitting field `savableVersion' because it seems like a vestigial part from old launcher versions
* (also it isn't even a string that is present in modern liblauncher.so, so I assume it will never be used.)
@@ -360,8 +316,6 @@ where
mod tests {
use std::fs;
- use serde_json::json;
-
use super::*;
#[test]
@@ -371,4 +325,12 @@ mod tests {
let arg: CompleteVersion = serde_json::from_str(s.unwrap().as_str()).unwrap();
dbg!(arg);
}
+
+ #[test]
+ fn test_it2() {
+ let s = fs::read_to_string("./test_stuff/version_manifest_v2.json");
+
+ let arg: VersionManifest = serde_json::from_str(s.unwrap().as_str()).unwrap();
+ dbg!(arg);
+ }
}
diff --git a/src/version/manifest.rs b/src/version/manifest.rs
index a44e435..1fa8041 100644
--- a/src/version/manifest.rs
+++ b/src/version/manifest.rs
@@ -3,20 +3,10 @@ use core::fmt;
use chrono::{DateTime, Utc};
use serde::{de::Visitor, Deserialize};
-#[derive(Deserialize)]
+#[derive(Deserialize, Debug)]
pub struct LatestVersions {
- release: String,
- snapshot: String
-}
-
-impl LatestVersions {
- pub fn get_release(&self) -> &String {
- &self.release
- }
-
- pub fn get_snapshot(&self) -> &String {
- &self.snapshot
- }
+ pub release: String,
+ pub snapshot: String
}
#[derive(Debug)]
@@ -59,61 +49,21 @@ impl<'de> Deserialize<'de> for VersionType {
}
// https://piston-meta.mojang.com/mc/game/version_manifest_v2.json
-#[derive(Deserialize)]
+#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct VersionManifestVersion {
- id: String,
+ pub id: String,
#[serde(rename = "type")]
- version_type: VersionType,
- url: String,
- time: DateTime<Utc>,
- release_time: DateTime<Utc>,
- sha1: String,
- compliance_level: u32
+ pub version_type: VersionType,
+ pub url: String,
+ pub time: DateTime<Utc>,
+ pub release_time: DateTime<Utc>,
+ pub sha1: String,
+ pub compliance_level: u32
}
-impl VersionManifestVersion {
- pub fn get_id(&self) -> &String {
- &self.id
- }
-
- pub fn get_version_type(&self) -> &VersionType {
- &self.version_type
- }
-
- pub fn get_url(&self) -> &String {
- &self.url
- }
-
- pub fn get_time(&self) -> &DateTime<Utc> {
- &self.time
- }
-
- pub fn get_release_time(&self) -> &DateTime<Utc> {
- &self.release_time
- }
-
- pub fn get_sha1(&self) -> &String {
- &self.sha1
- }
-
- pub fn get_compliance_level(&self) -> u32 {
- self.compliance_level
- }
-}
-
-#[derive(Deserialize)]
+#[derive(Deserialize, Debug)]
pub struct VersionManifest {
- latest: LatestVersions,
- versions: Vec<VersionManifestVersion>
-}
-
-impl VersionManifest {
- pub fn get_latest(&self) -> &LatestVersions {
- &self.latest
- }
-
- pub fn get_versions(&self) -> &Vec<VersionManifestVersion> {
- &self.versions
- }
+ pub latest: LatestVersions,
+ pub versions: Vec<VersionManifestVersion>
}