aboutsummaryrefslogtreecommitdiffstats
path: root/src/constants.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/constants.rs')
-rw-r--r--src/constants.rs110
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
3use std::time::Duration; 13use 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.
5pub const VERSION_MANIFEST_URL: &str = 20pub 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.
8pub const DOWNLOAD_RETRIES: usize = 3; 28pub 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.
9pub const DOWNLOAD_BACKOFF: Duration = Duration::from_millis(400); 34pub 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.
11pub const DEFAULT_MAX_MEMORY_MB: u32 = 4048; 41pub 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.
12pub const DEFAULT_JAVA_PATH: &str = "java"; 48pub 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.
13pub const DEFAULT_VERSION: &str = "latest"; 54pub 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.
60pub 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.
66pub 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.
72pub 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.
78pub const DEFAULT_LAUNCHER_DIR: &str = "dml";
79
80/// Default environment variable names for overriding configuration.
81pub const ENV_USERNAME: &str = "MC_USERNAME";
82pub const ENV_VERSION: &str = "MC_VERSION";
83pub const ENV_JAVA_PATH: &str = "MC_JAVA_PATH";
84pub const ENV_MAX_MEMORY_MB: &str = "MC_MAX_MEMORY_MB";
85
86/// Default project/platform constants for `directories::ProjectDirs`.
87pub const DEFAULT_COMPANY: &str = "com";
88pub const DEFAULT_PROJECT_GROUP: &str = "example";
89pub const DEFAULT_PROJECT_NAME: &str = "dml";
90
91/// Default error messages for common failures.
92pub const DEFAULT_ERR_PLATFORM_DIR: &str = "cannot determine config dir";
93pub const DEFAULT_ERR_CREATE_DIR: &str = "failed to create directory";
94
95/// Default configuration filename within the launcher directory.
96pub const DEFAULT_CONFIG_FILENAME: &str = "config.toml";
97
98/// Default username if none is provided by environment or config.
99pub const DEFAULT_USERNAME: &str = "phil";
100
101/// Default subdirectory names within the launcher directory.
102pub 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}