1use std::{fmt::Display, path::PathBuf};
2
3
4
5use crate::steam::SteamData;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
8pub enum ProtonVersion {
9 Proton37Beta,
10 Proton37,
11 Proton316Beta,
12 Proton316,
13 Proton42,
14 Proton411,
15 Proton50,
16 Proton513,
17 Proton63,
18 Proton70,
19 ProtonNext,
20 ProtonExperimental,
21}
22#[cfg(feature = "commandline")]
23impl clap::ValueEnum for ProtonVersion {
24 fn value_variants<'a>() -> &'a [Self] {
25 use ProtonVersion::*;
26 &[
27 ProtonExperimental,
28 ProtonNext,
29 Proton70,
30 Proton63,
31 Proton513,
32 Proton50,
33 Proton411,
34 Proton42,
35 Proton316,
36 Proton316Beta,
37 Proton37,
38 Proton37Beta,
39 ]
40 }
41
42 fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
43 Some(clap::builder::PossibleValue::new(self.arg_name()))
44 }
45}
46
47impl Display for ProtonVersion {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 match self {
50 ProtonVersion::Proton37 => write!(f, "Proton 3.7"),
51 ProtonVersion::Proton37Beta => write!(f, "Proton 3.7 Beta"),
52 ProtonVersion::Proton316 => write!(f, "Proton 3.16"),
53 ProtonVersion::Proton316Beta => write!(f, "Proton 3.16 Beta"),
54 ProtonVersion::Proton42 => write!(f, "Proton 4.2"),
55 ProtonVersion::Proton411 => write!(f, "Proton 4.11"),
56 ProtonVersion::Proton50 => write!(f, "Proton 5.0"),
57 ProtonVersion::Proton513 => write!(f, "Proton 5.13"),
58 ProtonVersion::Proton63 => write!(f, "Proton 6.3"),
59 ProtonVersion::Proton70 => write!(f, "Proton 7.0"),
60 ProtonVersion::ProtonExperimental => write!(f, "Proton Experimental"),
61 ProtonVersion::ProtonNext => write!(f, "Proton Next"),
62 }
63 }
64}
65
66impl ProtonVersion {
67 pub fn get_appid(&self) -> u64 {
68 match self {
69 ProtonVersion::Proton37 => 858280,
70 ProtonVersion::Proton37Beta => 930400,
71 ProtonVersion::Proton316 => 961940,
72 ProtonVersion::Proton316Beta => 996510,
73 ProtonVersion::Proton42 => 1054830,
74 ProtonVersion::Proton411 => 1113280,
75 ProtonVersion::Proton50 => 1245040,
76 ProtonVersion::Proton513 => 1420170,
77 ProtonVersion::Proton63 => 1580130,
78 ProtonVersion::Proton70 => 1887720,
79 ProtonVersion::ProtonExperimental => 1493710,
80 ProtonVersion::ProtonNext => 2230260,
81 }
82 }
83
84 pub fn all() -> Vec<Self> {
85 use ProtonVersion::*;
86 vec![
87 ProtonExperimental,
88 ProtonNext,
89 Proton70,
90 Proton63,
91 Proton513,
92 Proton50,
93 Proton411,
94 Proton42,
95 Proton316,
96 Proton316Beta,
97 Proton37,
98 Proton37Beta,
99 ]
100 }
101
102 pub fn install_url(&self) -> String {
103 format!("steam://install/{}", self.get_appid())
104 }
105
106 pub fn uninstall_url(&self) -> String {
107 format!("steam://uninstall/{}", self.get_appid())
108 }
109
110 pub fn best_installed(steam: &SteamData) -> Option<Self> {
111 Self::all().into_iter().find(|p| p.is_installed(steam))
112 }
113
114 pub fn is_installed(&self, steam: &SteamData) -> bool {
115 steam.has_app(self.get_appid())
116 }
117
118 pub fn arg_name(&self) -> String {
119 format!("{:?}", self).to_lowercase().replace("proton", "")
120 }
121
122 pub fn get_path(&self, steam_data: &SteamData) -> Option<PathBuf> {
123 steam_data.get_app_dir(self.get_appid())
124 }
125}