diff options
| author | Filip Wandzio <contact@philw.dev> | 2026-01-24 08:29:14 +0100 |
|---|---|---|
| committer | Filip Wandzio <contact@philw.dev> | 2026-01-24 08:29:14 +0100 |
| commit | a393e0a2f2c3678a3ea869dc1417fa269f2b1040 (patch) | |
| tree | 606df6a9284b5bd2dbf84fa5e3d363b8e6a01322 /src/platform | |
| parent | 72ddd7b7704f2087a52c9c0552446682918c513b (diff) | |
| download | dml-a393e0a2f2c3678a3ea869dc1417fa269f2b1040.tar.gz dml-a393e0a2f2c3678a3ea869dc1417fa269f2b1040.zip | |
Resolve audio not loading bug
Ensure all assets are downloading for each version
Temporarily disable minecraft versions older than 1.8 because of the asset/manifest loading issues
Implement basic documentation of modules
Implement basic async/multithreading for downloading assets
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/mod.rs | 10 | ||||
| -rw-r--r-- | src/platform/paths.rs | 36 |
2 files changed, 26 insertions, 20 deletions
diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 8118b29..24619ff 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs | |||
| @@ -1 +1,11 @@ | |||
| 1 | //! Platform-specific helpers for the DML launcher. | ||
| 2 | //! | ||
| 3 | //! This module provides utilities for handling file paths and directories | ||
| 4 | //! across operating systems. It includes functions to get standard locations | ||
| 5 | //! for Minecraft game data, assets, libraries, and version directories. | ||
| 6 | //! | ||
| 7 | //! # Submodules | ||
| 8 | //! - `paths`: Functions to construct paths for Minecraft data, assets, | ||
| 9 | //! libraries, and versions. | ||
| 10 | |||
| 1 | pub mod paths; | 11 | pub mod paths; |
diff --git a/src/platform/paths.rs b/src/platform/paths.rs index 47aae9a..b430f09 100644 --- a/src/platform/paths.rs +++ b/src/platform/paths.rs | |||
| @@ -1,48 +1,44 @@ | |||
| 1 | use std::{fs, path::PathBuf}; | 1 | use std::{fs::create_dir_all, path::PathBuf}; |
| 2 | |||
| 3 | use directories::ProjectDirs; | ||
| 4 | 2 | ||
| 5 | use crate::{config::Config, errors::McError}; | 3 | use crate::{config::Config, errors::McError}; |
| 6 | 4 | ||
| 7 | fn project_dirs() -> ProjectDirs { | 5 | /// ~/.local/share/dml/minecraft |
| 8 | ProjectDirs::from("com", "dml", "dml").expect("failed to determine project directories") | 6 | pub fn minecraft_root(cfg: &Config) -> PathBuf { |
| 7 | cfg.data_dir.join("minecraft") | ||
| 9 | } | 8 | } |
| 10 | 9 | ||
| 11 | /// Root Minecraft directory | 10 | pub fn assets_dir(cfg: &Config) -> PathBuf { |
| 12 | pub fn minecraft_root(_cfg: &Config) -> PathBuf { project_dirs().data_dir().join("minecraft") } | 11 | minecraft_root(cfg).join("assets") |
| 13 | 12 | } | |
| 14 | /* ---------------- setup ---------------- */ | ||
| 15 | 13 | ||
| 14 | pub fn game_dir(cfg: &Config) -> PathBuf { minecraft_root(cfg) } | ||
| 16 | pub fn ensure_dirs(cfg: &Config) -> Result<(), McError> { | 15 | pub fn ensure_dirs(cfg: &Config) -> Result<(), McError> { |
| 17 | let root = minecraft_root(cfg); | 16 | let root = minecraft_root(cfg); |
| 18 | 17 | create_dir_all(&root)?; | |
| 19 | fs::create_dir_all(root.join("versions"))?; | 18 | create_dir_all(root.join("versions"))?; |
| 20 | fs::create_dir_all(root.join("libraries"))?; | 19 | create_dir_all(root.join("libraries"))?; |
| 21 | fs::create_dir_all(root.join("assets"))?; | 20 | create_dir_all(assets_dir(cfg))?; |
| 21 | create_dir_all(assets_dir(cfg).join("indexes"))?; | ||
| 22 | create_dir_all(assets_dir(cfg).join("objects"))?; | ||
| 23 | create_dir_all(root.join("saves"))?; | ||
| 22 | 24 | ||
| 23 | Ok(()) | 25 | Ok(()) |
| 24 | } | 26 | } |
| 25 | 27 | ||
| 26 | /* ---------------- versions ---------------- */ | ||
| 27 | |||
| 28 | pub fn version_dir(cfg: &Config, version: &str) -> PathBuf { | 28 | pub fn version_dir(cfg: &Config, version: &str) -> PathBuf { |
| 29 | minecraft_root(cfg).join("versions").join(version) | 29 | minecraft_root(cfg).join("versions").join(version) |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | pub fn client_jar(cfg: &Config, version: &str) -> Result<PathBuf, McError> { | 32 | pub fn client_jar(cfg: &Config, version: &str) -> Result<PathBuf, McError> { |
| 33 | Ok(version_dir(cfg, version).join(format!("{}.jar", version))) | 33 | Ok(version_dir(cfg, version).join(format!("{version}.jar"))) |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | /* ---------------- libraries ---------------- */ | ||
| 37 | |||
| 38 | pub fn library_file(cfg: &Config, rel_path: &str) -> Result<PathBuf, McError> { | 36 | pub fn library_file(cfg: &Config, rel_path: &str) -> Result<PathBuf, McError> { |
| 39 | Ok(minecraft_root(cfg) | 37 | Ok(minecraft_root(cfg) |
| 40 | .join("libraries") | 38 | .join("libraries") |
| 41 | .join(rel_path)) | 39 | .join(rel_path)) |
| 42 | } | 40 | } |
| 43 | 41 | ||
| 44 | /* ---------------- natives ---------------- */ | ||
| 45 | |||
| 46 | pub fn natives_dir(cfg: &Config, version: &str) -> PathBuf { | 42 | pub fn natives_dir(cfg: &Config, version: &str) -> PathBuf { |
| 47 | version_dir(cfg, version).join("natives") | 43 | version_dir(cfg, version).join("natives") |
| 48 | } | 44 | } |
