|
| 1 | +//! Standard installer actions. |
| 2 | +
|
| 3 | +use std::default; |
| 4 | + |
| 5 | +use serde_json::Value; |
| 6 | + |
| 7 | +use crate::context::Context; |
| 8 | + |
| 9 | + |
| 10 | +/// This is the standard version installer that provides minimal and common installation |
| 11 | +/// of Minecraft versions. The install procedure given by this installer is idempotent, |
| 12 | +/// which mean that if the installer's configuration has not been modified, running it a |
| 13 | +/// second time won't do any modification. |
| 14 | +pub struct Installer { |
| 15 | + /// The directory context to install the game. |
| 16 | + context: Context, |
| 17 | + /// The version identifier to ultimately install. |
| 18 | + version: Version, |
| 19 | +} |
| 20 | + |
| 21 | +impl Installer { |
| 22 | + |
| 23 | + /// Create a new installer for the latest release and a default context. |
| 24 | + pub fn new() -> Self { |
| 25 | + Self::with_version(MojangVersion::Release.into()) |
| 26 | + } |
| 27 | + |
| 28 | + /// Create a new installer for the given version and a default context. |
| 29 | + #[inline] |
| 30 | + pub fn with_version(version: Version) -> Self { |
| 31 | + Self::with_context(Context::default(), version) |
| 32 | + } |
| 33 | + |
| 34 | + /// Create a new installer with the given version and context. |
| 35 | + pub fn with_context(context: Context, version: Version) -> Self { |
| 36 | + Self { |
| 37 | + context, |
| 38 | + version, |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + /// Get a reference to the context used by this installer. |
| 43 | + #[inline] |
| 44 | + pub fn context(&self) -> &Context { |
| 45 | + &self.context |
| 46 | + } |
| 47 | + |
| 48 | + /// Get a reference to the version to install. |
| 49 | + #[inline] |
| 50 | + pub fn version(&self) -> &Version { |
| 51 | + &self.version |
| 52 | + } |
| 53 | + |
| 54 | + pub fn install(&mut self) -> () { |
| 55 | + |
| 56 | + let main_id = match &self.version { |
| 57 | + Version::Local(id) => &id[..], |
| 58 | + Version::Mojang(_) => todo!(), |
| 59 | + Version::Fabric(_) => todo!(), |
| 60 | + Version::Forge(_) => todo!(), |
| 61 | + }; |
| 62 | + |
| 63 | + let mut resolving_id = main_id; |
| 64 | + |
| 65 | + loop { |
| 66 | + |
| 67 | + let dir = self.context.get_version_dir(main_id); |
| 68 | + |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + fn resolve_hierarchy(&mut self) { |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | +} |
| 79 | + |
| 80 | +/// An event handler for installation process. |
| 81 | +pub trait Handler { |
| 82 | + |
| 83 | +} |
| 84 | + |
| 85 | +/// Describe a version to install. |
| 86 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 87 | +pub enum Version { |
| 88 | + /// Install a version from its local metadata only. |
| 89 | + Local(String), |
| 90 | + /// Install a Mojang's official version from manifest. |
| 91 | + Mojang(MojangVersion), |
| 92 | + /// Install a Fabric mod loader version. |
| 93 | + Fabric(FabricVersion), |
| 94 | + /// Install a Forge mod loader version. |
| 95 | + Forge(ForgeVersion), |
| 96 | +} |
| 97 | + |
| 98 | +/// Describe a Mojang version from manifest. |
| 99 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 100 | +pub enum MojangVersion { |
| 101 | + /// Target the latest version, this will be resolved against the manifest. |
| 102 | + Release, |
| 103 | + /// Target the latest snapshot, this will be resolved against the manifest. |
| 104 | + Snapshot, |
| 105 | + /// Target a version from its identifier. |
| 106 | + Specific(String), |
| 107 | +} |
| 108 | + |
| 109 | +/// Describe a fabric version to install. |
| 110 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 111 | +pub struct FabricVersion { |
| 112 | + pub api: (), |
| 113 | + pub mojang_version: MojangVersion, |
| 114 | + pub loader_version: Option<String>, |
| 115 | +} |
| 116 | + |
| 117 | +/// Describe a forge version to install. |
| 118 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 119 | +pub struct ForgeVersion { |
| 120 | + pub mojang_version: MojangVersion, |
| 121 | +} |
| 122 | + |
| 123 | +impl From<MojangVersion> for Version { |
| 124 | + #[inline] |
| 125 | + fn from(value: MojangVersion) -> Self { |
| 126 | + Self::Mojang(value) |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +impl From<FabricVersion> for Version { |
| 131 | + #[inline] |
| 132 | + fn from(value: FabricVersion) -> Self { |
| 133 | + Self::Fabric(value) |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +impl From<ForgeVersion> for Version { |
| 138 | + #[inline] |
| 139 | + fn from(value: ForgeVersion) -> Self { |
| 140 | + Self::Forge(value) |
| 141 | + } |
| 142 | +} |
0 commit comments