From ffb5f47894611e9eff04066e352c0d26820f5d6e Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 24 Nov 2026 03:07:40 +0100 Subject: [PATCH] xcl run: the launcher menu can pick the game's folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opened from Explorer, xcl.exe offered a file dialog for the game's exe or MicrosoftGame.config only; `xcl run` itself takes the game's folder. The menu now has "Add a game folder…" (the default when there is no last game): the standard Windows folder picker (IFileOpenDialog with FOS_PICKFOLDERS, through COM – no dialog library is imported by xcl.exe), and the folder runs as `xcl run ` does. Cargo.toml: the windows crate's Win32_UI_Shell features for IFileOpenDialog (no new dependency). From theaustinayers' modified build (theaustinayers/xcl, v0.1.0-mod.10). Assisted-by: Claude Code (Claude Opus 5.5) Co-authored-by: theaustinayers <153482135+theaustinayers@users.noreply.github.com> --- README.md | 6 +++--- crates/xcl/Cargo.toml | 2 ++ crates/xcl/src/main.rs | 30 ++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f55cad72e..a0ee21322 100644 --- a/README.md +++ b/README.md @@ -124,9 +124,9 @@ xcl shaders D:\data\shaders.rpf --top 50 # pack statistics; --recomp / --compi xcl rpf D:\data\shaders.rpf --extract NAME --out folder ``` -- **Without a command line** (xcl.exe opened from Explorer) XCL shows a small menu: *Choose a - game…* (pick its exe or `MicrosoftGame.config`) or *Run again* (the last one). On an error the - window stays open until Enter. +- **Without a command line** (xcl.exe opened from Explorer) XCL shows a small menu: *Add a game + folder…* (pick the folder of the game's unpacked files), *Choose a game…* (pick its exe or + `MicrosoftGame.config`) or *Run again* (the last one). On an error the window stays open until Enter. - XCL works on **unpacked** game files you own; it contains nothing for decrypting or circumventing DRM. - **The game folder is never modified** – writes go to the overlay. diff --git a/crates/xcl/Cargo.toml b/crates/xcl/Cargo.toml index f3f6d604d..e70d75988 100644 --- a/crates/xcl/Cargo.toml +++ b/crates/xcl/Cargo.toml @@ -37,6 +37,8 @@ features = [ "Win32_System_Com", "Win32_System_LibraryLoader", "Win32_System_Threading", + "Win32_UI_Shell", + "Win32_UI_Shell_Common", "Win32_UI_WindowsAndMessaging", ] diff --git a/crates/xcl/src/main.rs b/crates/xcl/src/main.rs index 83ed10292..98973017f 100644 --- a/crates/xcl/src/main.rs +++ b/crates/xcl/src/main.rs @@ -100,6 +100,7 @@ fn run_picked_game() -> i32 { Choice::Again => last.clone(), Choice::Cancel => None, Choice::Choose | Choice::NoMenu => pick_game_file(), + Choice::Folder => pick_game_folder(), }; // MicrosoftGame.config stands for its folder: XCL picks the exe the config names picked.map(|file| match file.file_name() { @@ -186,6 +187,7 @@ impl Drop for Ui { enum Choice { Choose, + Folder, Again, Cancel, /// no task dialog on this system: straight to the file dialog @@ -197,17 +199,20 @@ fn menu(last: Option<&std::path::Path>) -> Choice { use windows_sys::Win32::UI::Controls::*; const CHOOSE: i32 = 100; const AGAIN: i32 = 101; + const FOLDER: i32 = 102; type TaskDialogIndirect = unsafe extern "system" fn(*const TASKDIALOGCONFIG, *mut i32, *mut i32, *mut i32) -> i32; let Some(f) = (unsafe { system_proc("comctl32.dll", "TaskDialogIndirect") }) else { return Choice::NoMenu }; let title = wide("XCL"); let heading = wide("Run an Xbox Series game"); - let content = wide("XCL runs the game from its unpacked files. Choose the game's exe or its MicrosoftGame.config."); + let content = wide("XCL runs the game from its unpacked files. Choose the game's folder, its exe or its MicrosoftGame.config."); + let folder = wide("Add a game folder…\nThe folder with the game's unpacked files"); let again = last.map(|p| wide(&format!("Run again\n{}", p.display()))); let choose = wide("Choose a game…\nThe game's exe or MicrosoftGame.config"); let mut buttons = Vec::new(); if let Some(a) = &again { buttons.push(TASKDIALOG_BUTTON { nButtonID: AGAIN, pszButtonText: a.as_ptr() }); } + buttons.push(TASKDIALOG_BUTTON { nButtonID: FOLDER, pszButtonText: folder.as_ptr() }); buttons.push(TASKDIALOG_BUTTON { nButtonID: CHOOSE, pszButtonText: choose.as_ptr() }); let mut c: TASKDIALOGCONFIG = unsafe { std::mem::zeroed() }; c.cbSize = std::mem::size_of::() as u32; @@ -219,17 +224,38 @@ fn menu(last: Option<&std::path::Path>) -> Choice { c.pszContent = content.as_ptr(); c.cButtons = buttons.len() as u32; c.pButtons = buttons.as_ptr(); - c.nDefaultButton = if again.is_some() { AGAIN } else { CHOOSE }; + c.nDefaultButton = if again.is_some() { AGAIN } else { FOLDER }; let mut pressed = 0i32; let hr = unsafe { std::mem::transmute::(f)(&c, &mut pressed, std::ptr::null_mut(), std::ptr::null_mut()) }; match (hr, pressed) { (h, _) if h < 0 => Choice::NoMenu, (_, CHOOSE) => Choice::Choose, (_, AGAIN) => Choice::Again, + (_, FOLDER) => Choice::Folder, _ => Choice::Cancel, } } +/// The standard Windows folder picker (None: cancelled). COM only, through ole32 – no dialog +/// library is imported for it. +fn pick_game_folder() -> Option { + use windows::Win32::Foundation::HWND; + use windows::Win32::System::Com::{CoCreateInstance, CoTaskMemFree, CLSCTX_INPROC_SERVER}; + use windows::Win32::UI::Shell::{FileOpenDialog, IFileOpenDialog, FOS_FORCEFILESYSTEM, FOS_PICKFOLDERS, SIGDN_FILESYSPATH}; + unsafe { + let dialog: IFileOpenDialog = CoCreateInstance(&FileOpenDialog, None, CLSCTX_INPROC_SERVER).ok()?; + let options = dialog.GetOptions().ok()?; + dialog.SetOptions(options | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM).ok()?; + let _ = dialog.SetTitle(windows::core::w!("XCL – choose the game's folder")); + let owner = HWND(windows_sys::Win32::System::Console::GetConsoleWindow() as _); + dialog.Show(Some(owner)).ok()?; + let name = dialog.GetResult().ok()?.GetDisplayName(SIGDN_FILESYSPATH).ok()?; + let path = name.to_string().ok().map(PathBuf::from); + CoTaskMemFree(Some(name.0 as _)); + path + } +} + /// The standard Windows open dialog (None: cancelled). fn pick_game_file() -> Option { use windows_sys::Win32::UI::Controls::Dialogs::*;