diff options
| author | Filip Wandzio <contact@philw.dev> | 2026-02-25 16:10:23 +0100 |
|---|---|---|
| committer | Filip Wandzio <contact@philw.dev> | 2026-02-25 16:10:23 +0100 |
| commit | f7b4b643ebc52a4d72d90d9adbdddc9aa0721e4a (patch) | |
| tree | c96432be342b02bc0409e5b78b6b5d54afcc7cd6 /src/constants.rs | |
| parent | 2e10b0713f5369f489d2ababd70108cc359c5d2d (diff) | |
| download | dml-f7b4b643ebc52a4d72d90d9adbdddc9aa0721e4a.tar.gz dml-f7b4b643ebc52a4d72d90d9adbdddc9aa0721e4a.zip | |
Feat: Refactor core download logic with concurrency and async features
Implement basic unit testing
Implement automatic java executable switching based on game version
Split loader module into smaller modules
Implement basic documentation
Diffstat (limited to 'src/constants.rs')
| -rw-r--r-- | src/constants.rs | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/constants.rs b/src/constants.rs index 3234fe6..72de325 100644 --- a/src/constants.rs +++ b/src/constants.rs | |||
| @@ -1,13 +1,123 @@ | |||
| 1 | #![allow(dead_code)] | 1 | #![allow(dead_code)] |
| 2 | 2 | ||
| 3 | //! Constants module for the DML Launcher. | ||
| 4 | //! | ||
| 5 | //! This module defines immutable configuration values and defaults | ||
| 6 | //! used throughout the launcher. These constants provide a single | ||
| 7 | //! source of truth for URLs, download behavior, memory settings, | ||
| 8 | //! JVM defaults, download concurrency, directory names, and version selection. | ||
| 9 | //! | ||
| 10 | //! Centralizing these constants ensures consistency across the | ||
| 11 | //! application and simplifies maintenance when defaults need to change. | ||
| 12 | |||
| 3 | use std::time::Duration; | 13 | use std::time::Duration; |
| 4 | 14 | ||
| 15 | /// URL to the Minecraft version manifest. | ||
| 16 | /// | ||
| 17 | /// This manifest contains metadata for all available Minecraft | ||
| 18 | /// releases, including release dates, type (release, snapshot), | ||
| 19 | /// and download URLs for the client and server distributions. | ||
| 5 | pub const VERSION_MANIFEST_URL: &str = | 20 | pub const VERSION_MANIFEST_URL: &str = |
| 6 | "https://launchermeta.mojang.com/mc/game/version_manifest.json"; | 21 | "https://launchermeta.mojang.com/mc/game/version_manifest.json"; |
| 7 | 22 | ||
| 23 | /// Number of times to retry a failed download. | ||
| 24 | /// | ||
| 25 | /// Used by asset and library download routines to tolerate | ||
| 26 | /// transient network failures. Downloads will be retried | ||
| 27 | /// up to this number of attempts before returning an error. | ||
| 8 | pub const DOWNLOAD_RETRIES: usize = 3; | 28 | pub const DOWNLOAD_RETRIES: usize = 3; |
| 29 | |||
| 30 | /// Duration to wait between download retries. | ||
| 31 | /// | ||
| 32 | /// Provides fixed delay for network resilience when fetching | ||
| 33 | /// game assets. Specified in milliseconds. | ||
| 9 | pub const DOWNLOAD_BACKOFF: Duration = Duration::from_millis(400); | 34 | pub const DOWNLOAD_BACKOFF: Duration = Duration::from_millis(400); |
| 10 | 35 | ||
| 36 | /// Default maximum memory allocation for the Minecraft JVM process in | ||
| 37 | /// megabytes. | ||
| 38 | /// | ||
| 39 | /// If the user does not specify memory settings via configuration | ||
| 40 | /// or JVM arguments, this value will be applied as the default heap size. | ||
| 11 | pub const DEFAULT_MAX_MEMORY_MB: u32 = 4048; | 41 | pub const DEFAULT_MAX_MEMORY_MB: u32 = 4048; |
| 42 | |||
| 43 | /// Default path to the Java executable. | ||
| 44 | /// | ||
| 45 | /// Used when launching the Minecraft client. Can be overridden | ||
| 46 | /// via configuration or environment variables if a custom Java | ||
| 47 | /// installation is required. | ||
| 12 | pub const DEFAULT_JAVA_PATH: &str = "java"; | 48 | pub const DEFAULT_JAVA_PATH: &str = "java"; |
| 49 | |||
| 50 | /// Default Minecraft version to launch when no specific version is provided. | ||
| 51 | /// | ||
| 52 | /// The launcher will resolve "latest" to the most recent stable release | ||
| 53 | /// according to the version manifest. | ||
| 13 | pub const DEFAULT_VERSION: &str = "latest"; | 54 | pub const DEFAULT_VERSION: &str = "latest"; |
| 55 | |||
| 56 | /// Default Java major version for launching Minecraft. | ||
| 57 | /// | ||
| 58 | /// This value is used when generating the JVM runtime configuration | ||
| 59 | /// for the launcher. | ||
| 60 | pub const DEFAULT_JAVA_MAJOR: u8 = 8; | ||
| 61 | |||
| 62 | /// Default number of concurrent downloads for libraries. | ||
| 63 | /// | ||
| 64 | /// Limits the number of simultaneous HTTP requests when fetching | ||
| 65 | /// Minecraft libraries to avoid saturating network or file handles. | ||
| 66 | pub const DEFAULT_LIBRARY_CONCURRENCY: usize = 20; | ||
| 67 | |||
| 68 | /// Default number of concurrent downloads for assets. | ||
| 69 | /// | ||
| 70 | /// Limits the number of simultaneous HTTP requests when fetching | ||
| 71 | /// Minecraft assets to optimize throughput without overloading the system. | ||
| 72 | pub const DEFAULT_ASSET_CONCURRENCY: usize = 20; | ||
| 73 | |||
| 74 | /// Default launcher cache directory name. | ||
| 75 | /// | ||
| 76 | /// Used as the base subdirectory for downloaded assets, libraries, | ||
| 77 | /// versions, and configuration. | ||
| 78 | pub const DEFAULT_LAUNCHER_DIR: &str = "dml"; | ||
| 79 | |||
| 80 | /// Default environment variable names for overriding configuration. | ||
| 81 | pub const ENV_USERNAME: &str = "MC_USERNAME"; | ||
| 82 | pub const ENV_VERSION: &str = "MC_VERSION"; | ||
| 83 | pub const ENV_JAVA_PATH: &str = "MC_JAVA_PATH"; | ||
| 84 | pub const ENV_MAX_MEMORY_MB: &str = "MC_MAX_MEMORY_MB"; | ||
| 85 | |||
| 86 | /// Default project/platform constants for `directories::ProjectDirs`. | ||
| 87 | pub const DEFAULT_COMPANY: &str = "com"; | ||
| 88 | pub const DEFAULT_PROJECT_GROUP: &str = "example"; | ||
| 89 | pub const DEFAULT_PROJECT_NAME: &str = "dml"; | ||
| 90 | |||
| 91 | /// Default error messages for common failures. | ||
| 92 | pub const DEFAULT_ERR_PLATFORM_DIR: &str = "cannot determine config dir"; | ||
| 93 | pub const DEFAULT_ERR_CREATE_DIR: &str = "failed to create directory"; | ||
| 94 | |||
| 95 | /// Default configuration filename within the launcher directory. | ||
| 96 | pub const DEFAULT_CONFIG_FILENAME: &str = "config.toml"; | ||
| 97 | |||
| 98 | /// Default username if none is provided by environment or config. | ||
| 99 | pub const DEFAULT_USERNAME: &str = "phil"; | ||
| 100 | |||
| 101 | /// Default subdirectory names within the launcher directory. | ||
| 102 | pub mod directory { | ||
| 103 | /// Directory for Minecraft versions. | ||
| 104 | pub const VERSIONS: &str = "versions"; | ||
| 105 | |||
| 106 | /// Directory for downloaded libraries. | ||
| 107 | pub const LIBRARIES: &str = "libraries"; | ||
| 108 | |||
| 109 | /// Directory for Minecraft assets. | ||
| 110 | pub const ASSETS: &str = "assets"; | ||
| 111 | |||
| 112 | /// Subdirectory for asset indexes. | ||
| 113 | pub const INDEXES: &str = "indexes"; | ||
| 114 | |||
| 115 | /// Subdirectory for asset objects. | ||
| 116 | pub const OBJECTS: &str = "objects"; | ||
| 117 | |||
| 118 | /// Directory for native libraries. | ||
| 119 | pub const NATIVES: &str = "natives"; | ||
| 120 | |||
| 121 | /// Directory for saved worlds. | ||
| 122 | pub const SAVES: &str = "saves"; | ||
| 123 | } | ||
