|
| 1 | +use super::{Runner, RunnerInfo}; |
| 2 | +use std::path::{Path, PathBuf}; |
| 3 | + |
| 4 | +/// GPTK (Game Porting Toolkit) runner for macOS |
| 5 | +/// |
| 6 | +/// GPTK is Apple's translation layer that allows running Windows games on macOS, |
| 7 | +/// particularly on Apple Silicon Macs. It combines Wine with Apple's D3DMetal |
| 8 | +/// to support DirectX 11 and 12 games. |
| 9 | +/// |
| 10 | +/// # Requirements |
| 11 | +/// - macOS 14 Sonoma or later |
| 12 | +/// - Apple Silicon Mac (recommended) or Intel Mac with Rosetta 2 |
| 13 | +/// - Command Line Tools for Xcode 15 or later |
| 14 | +/// - Game Porting Toolkit installed via Homebrew |
| 15 | +/// |
| 16 | +/// # Example |
| 17 | +/// ```rust |
| 18 | +/// use bottles_core::runner::{GPTK, Runner}; |
| 19 | +/// use std::path::Path; |
| 20 | +/// |
| 21 | +/// // Create a GPTK runner from a path containing the gameportingtoolkit executable |
| 22 | +/// let gptk_path = Path::new("/opt/homebrew/bin"); |
| 23 | +/// match GPTK::try_from(gptk_path) { |
| 24 | +/// Ok(gptk) => { |
| 25 | +/// println!("GPTK Name: {}", gptk.info().name()); |
| 26 | +/// println!("GPTK Version: {}", gptk.info().version()); |
| 27 | +/// println!("GPTK Available: {}", gptk.is_available()); |
| 28 | +/// } |
| 29 | +/// Err(e) => println!("Failed to create GPTK runner: {}", e), |
| 30 | +/// } |
| 31 | +/// ``` |
| 32 | +#[derive(Debug)] |
| 33 | +pub struct GPTK { |
| 34 | + info: RunnerInfo, |
| 35 | +} |
| 36 | + |
| 37 | +impl TryFrom<&Path> for GPTK { |
| 38 | + type Error = crate::Error; |
| 39 | + |
| 40 | + fn try_from(path: &Path) -> Result<Self, Self::Error> { |
| 41 | + let executable = PathBuf::from("./gameportingtoolkit"); |
| 42 | + let info = RunnerInfo::try_from(path, &executable)?; |
| 43 | + Ok(GPTK { info }) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +impl Runner for GPTK { |
| 48 | + fn wine(&self) -> &super::Wine { |
| 49 | + todo!() |
| 50 | + } |
| 51 | + |
| 52 | + fn info(&self) -> &RunnerInfo { |
| 53 | + &self.info |
| 54 | + } |
| 55 | + |
| 56 | + /// GPTK has special availability requirements - it only works on Apple Silicon Macs |
| 57 | + /// running macOS 14 Sonoma or later with Rosetta 2 |
| 58 | + fn is_available(&self) -> bool { |
| 59 | + if !self.info().executable_path().exists() { |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + // Check if running under Rosetta or on Apple Silicon |
| 64 | + use std::process::Command; |
| 65 | + let arch_output = Command::new("arch") |
| 66 | + .output() |
| 67 | + .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_string()) |
| 68 | + .unwrap_or_default(); |
| 69 | + |
| 70 | + // GPTK requires either x86_64 (Rosetta) or arm64 (Apple Silicon) |
| 71 | + arch_output == "i386" || arch_output == "arm64" |
| 72 | + } |
| 73 | +} |
0 commit comments