1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
//! Mod manager installation logic
//!
//! Stripped for Fluorine: no common.rs, mo2.rs, plugin.rs, compatdata_scanner.rs.
pub mod symlinks;
mod prefix_setup;
pub use prefix_setup::{
apply_dpi, apply_registry_for_game_path, auto_apply_game_registries, cleanup_prefix_drives,
install_all_dependencies, kill_wineserver, known_game_names, launch_dpi_test_app, DPI_PRESETS,
};
use std::error::Error;
use std::fs;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use crate::logging::log_install;
use crate::steam::SteamProton;
// ============================================================================
// Shared Types
// ============================================================================
/// Context for background installation tasks
#[derive(Clone)]
pub struct TaskContext {
pub status_callback: Arc<dyn Fn(String) + Send + Sync>,
pub log_callback: Arc<dyn Fn(String) + Send + Sync>,
pub progress_callback: Arc<dyn Fn(f32) + Send + Sync>,
pub cancel_flag: Arc<AtomicBool>,
}
impl TaskContext {
pub fn new(
status: impl Fn(String) + Send + Sync + 'static,
log: impl Fn(String) + Send + Sync + 'static,
progress: impl Fn(f32) + Send + Sync + 'static,
cancel: Arc<AtomicBool>,
) -> Self {
Self {
status_callback: Arc::new(status),
log_callback: Arc::new(log),
progress_callback: Arc::new(progress),
cancel_flag: cancel,
}
}
pub fn set_status(&self, msg: String) {
(self.status_callback)(msg);
}
pub fn log(&self, msg: String) {
(self.log_callback)(msg);
}
pub fn set_progress(&self, p: f32) {
(self.progress_callback)(p);
}
pub fn is_cancelled(&self) -> bool {
self.cancel_flag.load(std::sync::atomic::Ordering::Relaxed)
}
/// Run a command that can be killed if the user cancels.
pub fn run_cancellable(&self, mut cmd: std::process::Command) -> Result<std::process::ExitStatus, Box<dyn std::error::Error>> {
let mut child = cmd.spawn()?;
loop {
match child.try_wait()? {
Some(status) => return Ok(status),
None => {
if self.is_cancelled() {
let _ = child.kill();
let _ = child.wait();
return Err("Cancelled".into());
}
std::thread::sleep(std::time::Duration::from_millis(250));
}
}
}
}
}
// ============================================================================
// Shared Wine Registry Settings
// ============================================================================
/// Wine registry settings
pub const WINE_SETTINGS_REG: &str = r#"Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Wine\DllOverrides]
"dwrite.dll"="native,builtin"
"dwrite"="native,builtin"
"winmm.dll"="native,builtin"
"winmm"="native,builtin"
"version.dll"="native,builtin"
"version"="native,builtin"
"ArchiveXL.dll"="native,builtin"
"ArchiveXL"="native,builtin"
"Codeware.dll"="native,builtin"
"Codeware"="native,builtin"
"TweakXL.dll"="native,builtin"
"TweakXL"="native,builtin"
"input_loader.dll"="native,builtin"
"input_loader"="native,builtin"
"RED4ext.dll"="native,builtin"
"RED4ext"="native,builtin"
"mod_settings.dll"="native,builtin"
"mod_settings"="native,builtin"
"scc_lib.dll"="native,builtin"
"scc_lib"="native,builtin"
"dxgi.dll"="native,builtin"
"dxgi"="native,builtin"
"dbghelp.dll"="native,builtin"
"dbghelp"="native,builtin"
"d3d12.dll"="native,builtin"
"d3d12"="native,builtin"
"wininet.dll"="native,builtin"
"wininet"="native,builtin"
"winhttp.dll"="native,builtin"
"winhttp"="native,builtin"
"dinput.dll"="native,builtin"
"dinput8"="native,builtin"
"dinput8.dll"="native,builtin"
[HKEY_CURRENT_USER\Software\Wine]
"ShowDotFiles"="Y"
[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"
"FontSmoothingGamma"=dword:00000578
"FontSmoothingOrientation"=dword:00000001
"FontSmoothingType"=dword:00000002
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
@="~ HIGHDPIAWARE"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\Pandora Behaviour Engine+.exe\X11 Driver]
"Decorated"="N"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\Vortex.exe\X11 Driver]
"Decorated"="N"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\SSEEdit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\SSEEdit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\FO4Edit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\FO4Edit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\TES4Edit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\TES4Edit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\xEdit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\SF1Edit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\FNVEdit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\FNVEdit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\xFOEdit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\xFOEdit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\xSFEEdit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\xSFEEdit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\xTESEdit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\xTESEdit64.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\FO3Edit.exe]
"Version"="winxp"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\FO3Edit64.exe]
"Version"="winxp"
; =============================================================================
; Native file browser integration (opens folders in native file manager)
; =============================================================================
[HKEY_CLASSES_ROOT\Folder\shell\explore\command]
@="C:\\windows\\system32\\winebrowser.exe -nohome \"%1\""
[HKEY_CLASSES_ROOT\Directory\shell\explore\command]
@="C:\\windows\\system32\\winebrowser.exe -nohome \"%1\""
[HKEY_CLASSES_ROOT\Folder\shell\open\command]
@="C:\\windows\\system32\\winebrowser.exe -nohome \"%1\""
[HKEY_CLASSES_ROOT\Directory\shell\open\command]
@="C:\\windows\\system32\\winebrowser.exe -nohome \"%1\""
; =============================================================================
; Native text editor integration (opens text files in native editor)
; =============================================================================
[HKEY_CLASSES_ROOT\txtfile\shell\open\command]
@="C:\\windows\\system32\\winebrowser.exe \"%1\""
[HKEY_CLASSES_ROOT\inifile\shell\open\command]
@="C:\\windows\\system32\\winebrowser.exe \"%1\""
[HKEY_CLASSES_ROOT\.txt]
@="txtfile"
[HKEY_CLASSES_ROOT\.ini]
@="inifile"
[HKEY_CLASSES_ROOT\.cfg]
@="txtfile"
[HKEY_CLASSES_ROOT\.log]
@="txtfile"
[HKEY_CLASSES_ROOT\.xml]
@="txtfile"
[HKEY_CLASSES_ROOT\.json]
@="txtfile"
[HKEY_CLASSES_ROOT\.yml]
@="txtfile"
[HKEY_CLASSES_ROOT\.yaml]
@="txtfile"
"#;
// ============================================================================
// Shared Functions
// ============================================================================
/// Apply Wine registry settings to a prefix
pub fn apply_wine_registry_settings(
prefix_path: &std::path::Path,
proton: &SteamProton,
log_callback: &impl Fn(String),
_app_id: Option<u32>,
) -> Result<(), Box<dyn Error>> {
use std::io::Write;
use crate::config::AppConfig;
use crate::logging::{log_error, log_warning};
use crate::runtime_wrap;
let tmp_dir = AppConfig::get_tmp_path();
fs::create_dir_all(&tmp_dir)?;
let reg_file = tmp_dir.join("wine_settings.reg");
let mut file = fs::File::create(®_file)?;
file.write_all(WINE_SETTINGS_REG.as_bytes())?;
let wine_bin = proton.wine_binary().ok_or_else(|| {
let err_msg = format!(
"Wine binary not found for Proton '{}' (checked files/bin/wine and dist/bin/wine)",
proton.name
);
log_callback(format!("Error: {}", err_msg));
err_msg
})?;
let wineserver_bin = proton.wineserver_binary().unwrap_or_else(|| {
wine_bin.with_file_name("wineserver")
});
let bin_dir = proton.bin_dir().ok_or_else(|| {
let err_msg = "Could not determine Proton bin directory";
log_callback(format!("Error: {}", err_msg));
err_msg
})?;
let path_env = format!(
"{}:{}",
bin_dir.to_string_lossy(),
std::env::var("PATH").unwrap_or_default()
);
log_callback("Applying Wine registry settings...".to_string());
log_install("Running wine regedit...");
let reg_envs: Vec<(&str, String)> = vec![
("WINEPREFIX", prefix_path.display().to_string()),
("WINE", wine_bin.display().to_string()),
("WINESERVER", wineserver_bin.display().to_string()),
("PATH", path_env),
("WINEDLLOVERRIDES", "mshtml=d".to_string()),
("PROTON_USE_XALIA", "0".to_string()),
];
let regedit_status = runtime_wrap::build_command(&wine_bin, ®_envs)
.arg("regedit")
.arg(®_file)
.status();
match regedit_status {
Ok(status) => {
if status.success() {
log_callback("Registry settings applied successfully".to_string());
log_install("Wine registry settings applied successfully");
} else {
let msg = format!("regedit exited with code {:?}", status.code());
log_callback(format!("Warning: {}", msg));
log_warning(&msg);
}
}
Err(e) => {
let msg = format!("Failed to run regedit: {}", e);
log_callback(format!("Error: {}", msg));
log_error(&msg);
return Err(msg.into());
}
}
let _ = fs::remove_file(®_file);
Ok(())
}
|