Skip to content

Commit e30183c

Browse files
runner: Add documentation
1 parent 38f6fba commit e30183c

File tree

5 files changed

+148
-13
lines changed

5 files changed

+148
-13
lines changed

src/runner/gptk.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ use std::path::{Path, PathBuf};
55
///
66
/// GPTK is Apple's translation layer that allows running Windows games on macOS,
77
/// particularly on Apple Silicon Macs. It combines Wine with Apple's D3DMetal
8-
/// to support DirectX 11 and 12 games.
8+
/// to support DirectX 11 and 12 games with hardware acceleration.
9+
///
10+
/// # Features
11+
///
12+
/// - DirectX 11 and 12 support through D3DMetal translation
13+
/// - Optimized for Apple Silicon architecture
14+
/// - Integration with macOS graphics stack
15+
/// - Metal Performance Shaders acceleration
16+
/// - Enhanced gaming compatibility on macOS
917
///
1018
/// # Requirements
1119
/// - macOS 14 Sonoma or later

src/runner/mod.rs

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,39 @@ use std::{
1616
process::Command,
1717
};
1818

19-
/// Common information about a runner
19+
/// Contains metadata and paths for any runner implementation. This struct is used
20+
/// internally by all runner types to store their basic information.
2021
#[derive(Debug)]
2122
pub struct RunnerInfo {
23+
/// Human-readable name of the runner, typically derived from the directory name
2224
name: String,
25+
/// Version string obtained from the runner's `--version` output
2326
version: String,
27+
/// Base directory where the runner is installed
2428
directory: PathBuf,
29+
/// Relative path to the main executable within the directory
2530
executable: PathBuf,
2631
}
2732

2833
impl RunnerInfo {
29-
// This fuction is only meant to be called by the runners themselves hence this is not public
34+
/// Create a new RunnerInfo by validating the directory and executable
35+
///
36+
/// This function is only meant to be called by the runners themselves, hence it's not public.
37+
/// It performs validation to ensure the directory exists and contains the specified executable.
38+
///
39+
/// # Arguments
40+
///
41+
/// * `directory` - The base directory where the runner is installed
42+
/// * `executable` - The relative path to the executable within the directory
43+
///
44+
/// # Returns
45+
///
46+
/// Returns a `RunnerInfo` instance if validation succeeds
47+
///
48+
/// # Errors
49+
///
50+
/// This function will return an error if the directory or executable path is invalid,
51+
/// or if the executable cannot be executed to determine its version.
3052
fn try_from(directory: &Path, executable: &Path) -> Result<Self, Error> {
3153
if !directory.exists() {
3254
return Err(std::io::Error::new(
@@ -77,41 +99,110 @@ impl RunnerInfo {
7799
}
78100

79101
/// Get the full path to the executable for the runner
102+
///
103+
/// Combines the base directory with the relative executable path to provide
104+
/// the complete path that can be used to execute the runner.
105+
///
106+
/// # Returns
107+
///
108+
/// A `PathBuf` containing the full path to the runner's executable
80109
pub fn executable_path(&self) -> PathBuf {
81110
self.directory.join(&self.executable)
82111
}
83112
}
84113

85114
impl RunnerInfo {
86-
/// Name of the runner
115+
/// Get the name of the runner
116+
///
117+
/// Returns the human-readable name, typically derived from the directory name
118+
/// where the runner is installed.
119+
///
120+
/// # Returns
121+
///
122+
/// A string slice containing the runner's name
87123
pub fn name(&self) -> &str {
88124
&self.name
89125
}
90126

91-
/// Version of the runner
127+
/// Get the version of the runner
128+
///
129+
/// Returns the version string as reported by the runner's `--version` command.
130+
/// If the version cannot be determined, this may return the runner's name instead.
131+
///
132+
/// # Returns
133+
///
134+
/// A string slice containing the runner's version information
92135
pub fn version(&self) -> &str {
93136
&self.version
94137
}
95138

96-
/// Directory where the runner is located
139+
/// Returns the directory path where the runner is installed.
140+
///
141+
/// # Returns
142+
///
143+
/// A path reference to the runner's installation directory
97144
pub fn directory(&self) -> &Path {
98145
&self.directory
99146
}
100147
}
101148

149+
/// Trait defining the common interface for all Windows compatibility runners
150+
///
151+
/// All runners in this module implement this trait, providing a unified way to interact
152+
/// with different compatibility layers like Wine, Proton, UMU, and GPTK.
102153
pub trait Runner {
103154
/// Get the Wine runner associated with this runner
104155
///
105-
/// This is possible because all runners are built on top of Wine
156+
/// All runners are built on top of Wine, so this method provides access to the
157+
/// underlying Wine instance. This allows for Wine-specific operations and
158+
/// configuration even when using higher-level runners like Proton.
159+
///
160+
/// # Returns
161+
///
162+
/// A reference to the underlying Wine runner instance
106163
fn wine(&self) -> &Wine;
107164

108-
/// Get the common runner information
165+
/// Provides access to metadata about the runner including its name, version,
166+
/// installation directory, and executable path.
167+
///
168+
/// # Returns
169+
///
170+
/// A reference to the runner's information structure
109171
fn info(&self) -> &RunnerInfo;
110172

111-
/// Get the common runner information
173+
/// Get a mutable reference to the common runner information
174+
///
175+
/// Allows modification of the runner's metadata. This is typically used
176+
/// internally by runner implementations during initialization.
177+
///
178+
/// # Returns
179+
///
180+
/// A mutable reference to the runner's information structure
112181
fn info_mut(&mut self) -> &mut RunnerInfo;
113182

114-
/// Check if the runner executable is available and functional
183+
/// Performs basic validation to ensure the runner can be executed. The default
184+
/// implementation checks if the executable file exists and is accessible.
185+
/// Individual runners may override this to perform additional checks.
186+
///
187+
/// # Returns
188+
///
189+
/// `true` if the runner appears to be functional, `false` otherwise
190+
///
191+
/// # Example
192+
///
193+
/// ```rust
194+
/// use bottles_core::runner::{Wine, Runner};
195+
/// use std::path::Path;
196+
///
197+
/// let wine_path = Path::new("/usr/bin/wine");
198+
/// if let Ok(wine) = Wine::try_from(wine_path) {
199+
/// if wine.is_available() {
200+
/// println!("Wine is ready to use");
201+
/// } else {
202+
/// println!("Wine is not available");
203+
/// }
204+
/// }
205+
/// ```
115206
fn is_available(&self) -> bool {
116207
let executable_path = self.info().executable_path();
117208
executable_path.exists() && executable_path.is_file()

src/runner/proton.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
use super::{Runner, RunnerInfo, Wine};
22
use std::path::{Path, PathBuf};
33

4-
// TODO: These need to be set to use proton outside steam
5-
// STEAM_COMPAT_DATA_PATH
6-
// STEAM_COMPAT_CLIENT_INSTALL_PATH
4+
/// Proton runner implementation
5+
///
6+
/// Proton is Valve's Wine fork designed specifically for gaming on Linux. It includes
7+
/// numerous patches and enhancements over standard Wine, making it particularly
8+
/// effective for running Windows games through Steam or standalone.
9+
///
10+
/// # Note
11+
/// When used outside of Steam, Proton requires specific environment variables:
12+
/// - `STEAM_COMPAT_DATA_PATH`: Path to store compatibility data
13+
/// - `STEAM_COMPAT_CLIENT_INSTALL_PATH`: Steam installation directory
714
#[derive(Debug)]
815
pub struct Proton {
916
info: RunnerInfo,

src/runner/umu.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
use super::{Proton, Runner, RunnerInfo, Wine};
22
use std::path::{Path, PathBuf};
33

4+
/// UMU (Unified Launcher) runner implementation
5+
///
6+
/// UMU is a universal compatibility layer that wraps other runners like Proton
7+
/// to provide enhanced game compatibility and launcher functionality. It can
8+
/// automatically configure optimal settings for different games and provides
9+
/// a unified interface for various Windows compatibility tools.
410
#[derive(Debug)]
511
pub struct UMU {
612
info: RunnerInfo,
13+
/// Underlying Proton runner that UMU wraps
14+
///
15+
/// When present, UMU will use this Proton instance to run applications.
16+
/// If None, UMU will download the latest Proton version it can find and set that up.
717
proton: Option<Proton>,
818
}
919

src/runner/wine.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
use super::{Runner, RunnerInfo};
22
use std::path::{Path, PathBuf};
33

4+
/// Wine runner implementation
5+
///
6+
/// Wine is the base compatibility layer that all other runners build upon. It provides
7+
/// the core Windows API translation functionality that allows Windows applications
8+
/// to run on Unix-like systems.
49
#[derive(Debug)]
510
pub struct Wine {
611
info: RunnerInfo,
712
}
813

14+
/// Architecture for Wine prefix creation
15+
///
16+
/// Determines whether a Wine prefix should be configured for 32-bit or 64-bit
17+
/// Windows compatibility. This affects which Windows applications can run
18+
/// in the prefix
19+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
920
pub enum PrefixArch {
21+
/// 32-bit Windows prefix architecture
1022
Win32,
23+
/// 64-bit Windows prefix architecture (recommended)
1124
Win64,
1225
}
1326

27+
/// Windows version compatibility settings
28+
///
29+
/// Specifies which version of Windows the Wine prefix should emulate.
30+
/// Different applications may require specific Windows versions for
31+
/// optimal compatibility.
32+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1433
pub enum WindowsVersion {
1534
Win7,
1635
Win8,

0 commit comments

Comments
 (0)