-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf740ed
commit b82bdf6
Showing
5 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! A Minecraft's installation context. | ||
|
||
use std::path::{Path, PathBuf}; | ||
|
||
|
||
/// This structure represents the context of a Minecraft's installation. | ||
#[derive(Debug)] | ||
pub struct Context { | ||
/// The working directory from where the game is run, the game stores thing like | ||
/// saves, resource packs, options and mods if relevant. | ||
pub work_dir: PathBuf, | ||
/// The versions directory contains one directory per version, each containing the | ||
/// version metadata and potentially the version jar file. | ||
pub versions_dir: PathBuf, | ||
/// The assets directory contains the whole assets index. | ||
pub assets_dir: PathBuf, | ||
/// The libraries directory contains the various Java libraries required by the game. | ||
pub libraries_dir: PathBuf, | ||
/// The JVM directory is specific to PortableMC, and contains the official Java | ||
/// versions provided by Microsoft for some common architectures. | ||
pub jvm_dir: PathBuf, | ||
/// The binary directory contains temporary directories that are used only during the | ||
/// game's runtime, modern versions no longer use it but it. | ||
pub bin_dir: PathBuf, | ||
} | ||
|
||
impl Default for Context { | ||
|
||
fn default() -> Self { | ||
todo!("new with default minecraft dir"); | ||
} | ||
|
||
} | ||
|
||
impl Context { | ||
|
||
/// Create a basic context with all common directories derived from the given main | ||
/// directory. The work directory is also set to the main directory. | ||
pub fn new(main_dir: impl AsRef<Path>) -> Self { | ||
|
||
let main_dir: &Path = main_dir.as_ref(); | ||
|
||
Self { | ||
work_dir: main_dir.to_path_buf(), | ||
versions_dir: main_dir.join("versions"), | ||
assets_dir: main_dir.join("assets"), | ||
libraries_dir: main_dir.join("libraries"), | ||
jvm_dir: main_dir.join("jvm"), | ||
bin_dir: main_dir.join("bin"), | ||
} | ||
|
||
} | ||
|
||
/// Change the work directory to the given one. | ||
pub fn with_work_dir(&mut self, work_dir: impl Into<PathBuf>) -> &mut Self { | ||
self.work_dir = work_dir.into(); | ||
self | ||
} | ||
|
||
/// Get a version directory from its version id. | ||
pub fn get_version_dir(&self, id: &str) -> PathBuf { | ||
self.versions_dir.join(id) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
//! Standard installer actions. | ||
|
||
use std::default; | ||
|
||
use serde_json::Value; | ||
|
||
use crate::context::Context; | ||
|
||
|
||
/// This is the standard version installer that provides minimal and common installation | ||
/// of Minecraft versions. The install procedure given by this installer is idempotent, | ||
/// which mean that if the installer's configuration has not been modified, running it a | ||
/// second time won't do any modification. | ||
pub struct Installer { | ||
/// The directory context to install the game. | ||
context: Context, | ||
/// The version identifier to ultimately install. | ||
version: Version, | ||
} | ||
|
||
impl Installer { | ||
|
||
/// Create a new installer for the latest release and a default context. | ||
pub fn new() -> Self { | ||
Self::with_version(MojangVersion::Release.into()) | ||
} | ||
|
||
/// Create a new installer for the given version and a default context. | ||
#[inline] | ||
pub fn with_version(version: Version) -> Self { | ||
Self::with_context(Context::default(), version) | ||
} | ||
|
||
/// Create a new installer with the given version and context. | ||
pub fn with_context(context: Context, version: Version) -> Self { | ||
Self { | ||
context, | ||
version, | ||
} | ||
} | ||
|
||
/// Get a reference to the context used by this installer. | ||
#[inline] | ||
pub fn context(&self) -> &Context { | ||
&self.context | ||
} | ||
|
||
/// Get a reference to the version to install. | ||
#[inline] | ||
pub fn version(&self) -> &Version { | ||
&self.version | ||
} | ||
|
||
pub fn install(&mut self) -> () { | ||
|
||
let main_id = match &self.version { | ||
Version::Local(id) => &id[..], | ||
Version::Mojang(_) => todo!(), | ||
Version::Fabric(_) => todo!(), | ||
Version::Forge(_) => todo!(), | ||
}; | ||
|
||
let mut resolving_id = main_id; | ||
|
||
loop { | ||
|
||
let dir = self.context.get_version_dir(main_id); | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
fn resolve_hierarchy(&mut self) { | ||
|
||
} | ||
|
||
} | ||
|
||
/// An event handler for installation process. | ||
pub trait Handler { | ||
|
||
} | ||
|
||
/// Describe a version to install. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub enum Version { | ||
/// Install a version from its local metadata only. | ||
Local(String), | ||
/// Install a Mojang's official version from manifest. | ||
Mojang(MojangVersion), | ||
/// Install a Fabric mod loader version. | ||
Fabric(FabricVersion), | ||
/// Install a Forge mod loader version. | ||
Forge(ForgeVersion), | ||
} | ||
|
||
/// Describe a Mojang version from manifest. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub enum MojangVersion { | ||
/// Target the latest version, this will be resolved against the manifest. | ||
Release, | ||
/// Target the latest snapshot, this will be resolved against the manifest. | ||
Snapshot, | ||
/// Target a version from its identifier. | ||
Specific(String), | ||
} | ||
|
||
/// Describe a fabric version to install. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct FabricVersion { | ||
pub api: (), | ||
pub mojang_version: MojangVersion, | ||
pub loader_version: Option<String>, | ||
} | ||
|
||
/// Describe a forge version to install. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct ForgeVersion { | ||
pub mojang_version: MojangVersion, | ||
} | ||
|
||
impl From<MojangVersion> for Version { | ||
#[inline] | ||
fn from(value: MojangVersion) -> Self { | ||
Self::Mojang(value) | ||
} | ||
} | ||
|
||
impl From<FabricVersion> for Version { | ||
#[inline] | ||
fn from(value: FabricVersion) -> Self { | ||
Self::Fabric(value) | ||
} | ||
} | ||
|
||
impl From<ForgeVersion> for Version { | ||
#[inline] | ||
fn from(value: ForgeVersion) -> Self { | ||
Self::Forge(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters