Launcher graphique (Rust/egui, FR/EN)
Choix du jeu (dossier, lecteur ou ISO montee automatiquement), verification des prerequis, installation de capstone et de SDL2, generation et compilation, lancement du jeu avec ses options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
821f9c7e25
commit
e91fa9e8ba
6 files changed
+3726
-2
No files matched your search
@@ -39,6 +39,9 @@ SAVEGM.*
|
||||
# Dépendances tierces téléchargées (SDL2, etc.)
|
||||
third_party/
|
||||
|
||||
# Rust (launcher)
|
||||
launcher/target/
|
||||
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
+17
-1
@@ -51,7 +51,22 @@ build/tucker.exe
|
||||
of functions replaced by hand-written C (`overrides.c`). The original function remains available
|
||||
as `F_xxxxxxxx_orig`. Sound, system calls, and later rendering and mods all go through this.
|
||||
|
||||
## Building
|
||||
## Launcher (easiest)
|
||||
|
||||
The graphical launcher does everything for you: pick the game (folder, drive, or `.iso` image,
|
||||
mounted automatically), check the requirements, install `capstone` or download SDL2 in one click,
|
||||
generate and build, then start the game with its options (sound, fullscreen, intro, scale). It is
|
||||
available in French and English.
|
||||
|
||||
```bat
|
||||
cd launcher
|
||||
cargo build --release
|
||||
target\release\DoubleTroubleLauncher.exe
|
||||
```
|
||||
|
||||
Settings are saved to `%APPDATA%\DoubleTroubleRecomp\launcher.ini`.
|
||||
|
||||
## Building by hand
|
||||
|
||||
### Requirements
|
||||
|
||||
@@ -107,6 +122,7 @@ tools/
|
||||
le.py LE format reader (DOS/4GW)
|
||||
recomp.py x86 → C translator
|
||||
runtime/ C runtime (CPU, DOS, hardware, sound, hosts, overrides)
|
||||
launcher/ graphical launcher (Rust, egui)
|
||||
docs/ roadmap, technical notes
|
||||
```
|
||||
|
||||
|
||||
@@ -53,7 +53,22 @@ build/tucker.exe
|
||||
reste disponible sous le nom `F_xxxxxxxx_orig`. Le son, les appels système, puis l'affichage et
|
||||
les mods passent par ce mécanisme.
|
||||
|
||||
## Compiler
|
||||
## Launcher (le plus simple)
|
||||
|
||||
Le launcher graphique fait tout à votre place : choisir le jeu (dossier, lecteur ou image `.iso`
|
||||
montée automatiquement), vérifier les prérequis, installer `capstone` ou télécharger SDL2 en un
|
||||
clic, générer et compiler, puis lancer le jeu avec ses options (son, plein écran, intro, taille).
|
||||
Il est en français et en anglais.
|
||||
|
||||
```bat
|
||||
cd launcher
|
||||
cargo build --release
|
||||
target\release\DoubleTroubleLauncher.exe
|
||||
```
|
||||
|
||||
Les réglages sont enregistrés dans `%APPDATA%\DoubleTroubleRecomp\launcher.ini`.
|
||||
|
||||
## Compiler à la main
|
||||
|
||||
### Prérequis
|
||||
|
||||
@@ -109,6 +124,7 @@ tools/
|
||||
le.py lecteur du format LE (DOS/4GW)
|
||||
recomp.py traducteur x86 → C
|
||||
runtime/ runtime C (CPU, DOS, matériel, son, hôtes, remplacements)
|
||||
launcher/ launcher graphique (Rust, egui)
|
||||
docs/ feuille de route, notes techniques
|
||||
```
|
||||
|
||||
|
||||
Generated
+2867
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "dtr-launcher"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "Launcher de DoubleTroubleRecomp : choix du jeu, vérifications, compilation, lancement"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "DoubleTroubleLauncher"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
eframe = { version = "0.38", default-features = false, features = ["glow", "default_fonts", "clipboard", "links"] }
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
lto = "thin"
|
||||
strip = true
|
||||
@@ -0,0 +1,804 @@
|
||||
//! Launcher de DoubleTroubleRecomp.
|
||||
//!
|
||||
//! - choisir où se trouve le jeu (dossier du CD, lecteur, ou image .iso montée automatiquement) ;
|
||||
//! - vérifier les prérequis (Python + capstone, MSVC, SDL2) et en installer certains ;
|
||||
//! - générer le C et compiler (mêmes étapes que build.bat) ;
|
||||
//! - lancer le jeu avec ses options, et afficher son journal.
|
||||
//!
|
||||
//! Aucun fichier du jeu n'est copié : le launcher ne fait que passer des chemins.
|
||||
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
use eframe::egui::{self, Color32, RichText};
|
||||
use std::io::{BufRead, BufReader, Read};
|
||||
use std::os::windows::process::CommandExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::thread;
|
||||
|
||||
const NO_WINDOW: u32 = 0x0800_0000;
|
||||
const SDL_VER: &str = "2.32.10";
|
||||
const SDL_URL: &str =
|
||||
"https://github.com/libsdl-org/SDL/releases/download/release-2.32.10/SDL2-devel-2.32.10-VC.zip";
|
||||
const VSWHERE: &str = r"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe";
|
||||
const MAX_LOG: usize = 5000;
|
||||
|
||||
// ------------------------------------------------------------------ langue
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Lang {
|
||||
Fr,
|
||||
En,
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ configuration
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
struct Config {
|
||||
lang: Lang,
|
||||
game_path: String,
|
||||
install_dir: String,
|
||||
sound: bool,
|
||||
skip_intro: bool,
|
||||
fullscreen: bool,
|
||||
scale: u32,
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
lang: Lang::Fr,
|
||||
game_path: String::new(),
|
||||
install_dir: String::new(),
|
||||
sound: true,
|
||||
skip_intro: false,
|
||||
fullscreen: true,
|
||||
scale: 3,
|
||||
verbose: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn config_file() -> Option<PathBuf> {
|
||||
std::env::var_os("APPDATA").map(|a| PathBuf::from(a).join("DoubleTroubleRecomp").join("launcher.ini"))
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn load() -> Self {
|
||||
let mut c = Config::default();
|
||||
let Some(text) = config_file().and_then(|f| std::fs::read_to_string(f).ok()) else { return c };
|
||||
for line in text.lines() {
|
||||
let Some((k, v)) = line.split_once('=') else { continue };
|
||||
let (k, v) = (k.trim(), v.trim());
|
||||
let b = v == "1";
|
||||
match k {
|
||||
"lang" => c.lang = if v == "en" { Lang::En } else { Lang::Fr },
|
||||
"game_path" => c.game_path = v.to_string(),
|
||||
"install_dir" => c.install_dir = v.to_string(),
|
||||
"sound" => c.sound = b,
|
||||
"skip_intro" => c.skip_intro = b,
|
||||
"fullscreen" => c.fullscreen = b,
|
||||
"scale" => c.scale = v.parse().unwrap_or(3).clamp(1, 8),
|
||||
"verbose" => c.verbose = b,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
c
|
||||
}
|
||||
|
||||
fn save(&self) {
|
||||
let Some(f) = config_file() else { return };
|
||||
if let Some(dir) = f.parent() {
|
||||
let _ = std::fs::create_dir_all(dir);
|
||||
}
|
||||
let b = |x: bool| if x { "1" } else { "0" };
|
||||
let text = format!(
|
||||
"lang={}\ngame_path={}\ninstall_dir={}\nsound={}\nskip_intro={}\nfullscreen={}\nscale={}\nverbose={}\n",
|
||||
if self.lang == Lang::En { "en" } else { "fr" },
|
||||
self.game_path,
|
||||
self.install_dir,
|
||||
b(self.sound),
|
||||
b(self.skip_intro),
|
||||
b(self.fullscreen),
|
||||
self.scale,
|
||||
b(self.verbose)
|
||||
);
|
||||
let _ = std::fs::write(f, text);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ vérifications
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct Checks {
|
||||
done: bool,
|
||||
python: Option<String>,
|
||||
capstone: Option<String>,
|
||||
vcvars: Option<PathBuf>,
|
||||
sdl: bool,
|
||||
/// dossier qui contient TUCKER.EXE et INTRO.EXE
|
||||
game_dir: Option<PathBuf>,
|
||||
game_error: Option<String>,
|
||||
built: bool,
|
||||
}
|
||||
|
||||
impl Checks {
|
||||
fn can_build(&self) -> bool {
|
||||
self.python.is_some() && self.capstone.is_some() && self.vcvars.is_some() && self.sdl && self.game_dir.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
fn hidden(program: &str) -> Command {
|
||||
let mut c = Command::new(program);
|
||||
c.creation_flags(NO_WINDOW);
|
||||
c
|
||||
}
|
||||
|
||||
/// lance une commande et renvoie sa sortie standard (sans les espaces de fin) si elle a réussi
|
||||
fn capture(cmd: &mut Command) -> Option<String> {
|
||||
let out = cmd.stdin(Stdio::null()).output().ok()?;
|
||||
if !out.status.success() {
|
||||
return None;
|
||||
}
|
||||
let mut s = String::from_utf8_lossy(&out.stdout).trim().to_string();
|
||||
if s.is_empty() {
|
||||
s = String::from_utf8_lossy(&out.stderr).trim().to_string();
|
||||
}
|
||||
Some(s)
|
||||
}
|
||||
|
||||
fn powershell(script: &str) -> Option<String> {
|
||||
capture(hidden("powershell").args(["-NoProfile", "-NonInteractive", "-STA", "-Command", script]))
|
||||
}
|
||||
|
||||
fn ps_quote(s: &str) -> String {
|
||||
format!("'{}'", s.replace('\'', "''"))
|
||||
}
|
||||
|
||||
fn find_vcvars() -> Option<PathBuf> {
|
||||
let rel = r"VC\Auxiliary\Build\vcvars64.bat";
|
||||
if Path::new(VSWHERE).exists() {
|
||||
let out = capture(hidden(VSWHERE).args([
|
||||
"-latest",
|
||||
"-products",
|
||||
"*",
|
||||
"-requires",
|
||||
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
|
||||
"-property",
|
||||
"installationPath",
|
||||
]));
|
||||
if let Some(p) = out.and_then(|s| s.lines().next().map(|l| PathBuf::from(l.trim()).join(rel))) {
|
||||
if p.exists() {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
for base in [r"C:\Program Files (x86)\Microsoft Visual Studio\2022", r"C:\Program Files\Microsoft Visual Studio\2022"] {
|
||||
for ed in ["BuildTools", "Community", "Professional", "Enterprise"] {
|
||||
let p = Path::new(base).join(ed).join(rel);
|
||||
if p.exists() {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn is_iso(p: &str) -> bool {
|
||||
p.to_ascii_lowercase().ends_with(".iso")
|
||||
}
|
||||
|
||||
/// monte l'image (si besoin) et renvoie la lettre du lecteur
|
||||
fn mount_iso(iso: &str) -> Result<String, String> {
|
||||
let script = format!(
|
||||
"$ErrorActionPreference='Stop'; $p={}; $d=Get-DiskImage -ImagePath $p; \
|
||||
if(-not $d.Attached){{ $d=Mount-DiskImage -ImagePath $p -PassThru }}; \
|
||||
($d | Get-Volume).DriveLetter",
|
||||
ps_quote(iso)
|
||||
);
|
||||
match powershell(&script) {
|
||||
Some(l) if l.len() == 1 => Ok(format!("{l}:\\")),
|
||||
Some(other) => Err(other),
|
||||
None => Err("Mount-DiskImage".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// trouve le dossier qui contient TUCKER.EXE et INTRO.EXE : le dossier lui-même ou son sous-dossier TUCKER
|
||||
fn find_game_dir(dir: &Path) -> Option<PathBuf> {
|
||||
[dir.to_path_buf(), dir.join("TUCKER")]
|
||||
.into_iter()
|
||||
.find(|d| d.join("TUCKER.EXE").is_file() && d.join("INTRO.EXE").is_file())
|
||||
}
|
||||
|
||||
fn resolve_game(path: &str) -> Result<PathBuf, String> {
|
||||
let path = path.trim();
|
||||
if path.is_empty() {
|
||||
return Err(String::new());
|
||||
}
|
||||
let dir = if is_iso(path) {
|
||||
if !Path::new(path).is_file() {
|
||||
return Err(format!("introuvable / not found : {path}"));
|
||||
}
|
||||
PathBuf::from(mount_iso(path)?)
|
||||
} else {
|
||||
PathBuf::from(path)
|
||||
};
|
||||
find_game_dir(&dir).ok_or_else(|| format!("TUCKER.EXE / INTRO.EXE ? ({})", dir.display()))
|
||||
}
|
||||
|
||||
fn run_checks(root: &Path, cfg: &Config) -> Checks {
|
||||
let py = |args: &[&str]| capture(hidden("python").args(args));
|
||||
let python = py(&["--version"]);
|
||||
let capstone = python
|
||||
.as_ref()
|
||||
.and_then(|_| py(&["-c", "import capstone; print(capstone.__version__)"]));
|
||||
let (game_dir, game_error) = match resolve_game(&cfg.game_path) {
|
||||
Ok(d) => (Some(d), None),
|
||||
Err(e) => (None, Some(e)),
|
||||
};
|
||||
Checks {
|
||||
done: true,
|
||||
python,
|
||||
capstone,
|
||||
vcvars: find_vcvars(),
|
||||
sdl: root.join("third_party").join(format!("SDL2-{SDL_VER}")).join("include").join("SDL.h").is_file(),
|
||||
game_dir,
|
||||
game_error,
|
||||
built: root.join("build").join("tucker.exe").is_file(),
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ tâches de fond
|
||||
|
||||
enum Msg {
|
||||
Log(String),
|
||||
Checks(Checks),
|
||||
Picked(Pick, String),
|
||||
TaskDone { ok: bool },
|
||||
GameExited(i32),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Pick {
|
||||
GameFolder,
|
||||
GameIso,
|
||||
Install,
|
||||
}
|
||||
|
||||
struct Ui {
|
||||
tx: Sender<Msg>,
|
||||
ctx: egui::Context,
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
fn send(&self, m: Msg) {
|
||||
let _ = self.tx.send(m);
|
||||
self.ctx.request_repaint();
|
||||
}
|
||||
fn log(&self, s: impl Into<String>) {
|
||||
self.send(Msg::Log(s.into()));
|
||||
}
|
||||
}
|
||||
|
||||
/// exécute une ligne de commande cmd.exe dans `cwd` en envoyant chaque ligne de sortie au journal
|
||||
fn run_streamed(ui: &Ui, cwd: &Path, line: &str) -> bool {
|
||||
ui.log(format!("> {line}"));
|
||||
let child = hidden("cmd")
|
||||
.raw_arg(format!("/S /C \"{line} 2>&1\""))
|
||||
.current_dir(cwd)
|
||||
.env("VSLANG", "1033")
|
||||
.env("PYTHONUTF8", "1")
|
||||
.env("PYTHONIOENCODING", "utf-8")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn();
|
||||
let mut child = match child {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
ui.log(format!("!! {e}"));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if let Some(out) = child.stdout.take() {
|
||||
stream_lines(ui, out);
|
||||
}
|
||||
matches!(child.wait(), Ok(s) if s.success())
|
||||
}
|
||||
|
||||
fn stream_lines(ui: &Ui, r: impl Read) {
|
||||
let mut reader = BufReader::new(r);
|
||||
let mut buf = Vec::new();
|
||||
while let Ok(n) = reader.read_until(b'\n', &mut buf) {
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
let s = String::from_utf8_lossy(&buf);
|
||||
let s = s.trim_end();
|
||||
if !s.is_empty() {
|
||||
ui.log(s.to_string());
|
||||
}
|
||||
buf.clear();
|
||||
}
|
||||
}
|
||||
|
||||
fn pick_dialog(kind: Pick, title: &str) -> Option<String> {
|
||||
let owner = "(New-Object System.Windows.Forms.Form -Property @{TopMost=$true})";
|
||||
let script = match kind {
|
||||
Pick::GameIso => format!(
|
||||
"Add-Type -AssemblyName System.Windows.Forms; $f=New-Object System.Windows.Forms.OpenFileDialog; \
|
||||
$f.Title={}; $f.Filter='ISO (*.iso)|*.iso|*.*|*.*'; if($f.ShowDialog({owner}) -eq 'OK'){{$f.FileName}}",
|
||||
ps_quote(title)
|
||||
),
|
||||
_ => format!(
|
||||
"Add-Type -AssemblyName System.Windows.Forms; $f=New-Object System.Windows.Forms.FolderBrowserDialog; \
|
||||
$f.Description={}; $f.ShowNewFolderButton=$false; if($f.ShowDialog({owner}) -eq 'OK'){{$f.SelectedPath}}",
|
||||
ps_quote(title)
|
||||
),
|
||||
};
|
||||
powershell(&script).filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ application
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum Busy {
|
||||
No,
|
||||
Checking,
|
||||
Task(&'static str),
|
||||
}
|
||||
|
||||
struct App {
|
||||
root: Option<PathBuf>,
|
||||
cfg: Config,
|
||||
saved: Config,
|
||||
checks: Checks,
|
||||
busy: Busy,
|
||||
game_running: bool,
|
||||
last_ok: Option<bool>,
|
||||
log: Vec<String>,
|
||||
tx: Sender<Msg>,
|
||||
rx: Receiver<Msg>,
|
||||
ctx: egui::Context,
|
||||
}
|
||||
|
||||
fn find_root() -> Option<PathBuf> {
|
||||
let is_root = |d: &Path| d.join("build.bat").is_file() && d.join("tools").join("recomp.py").is_file();
|
||||
let mut starts = Vec::new();
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
starts.push(exe);
|
||||
}
|
||||
if let Ok(cwd) = std::env::current_dir() {
|
||||
starts.push(cwd);
|
||||
}
|
||||
starts.iter().find_map(|s| s.ancestors().find(|d| is_root(d)).map(Path::to_path_buf))
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
let (tx, rx) = channel();
|
||||
let cfg = Config::load();
|
||||
let mut app = Self {
|
||||
root: find_root(),
|
||||
saved: cfg.clone(),
|
||||
cfg,
|
||||
checks: Checks::default(),
|
||||
busy: Busy::No,
|
||||
game_running: false,
|
||||
last_ok: None,
|
||||
log: Vec::new(),
|
||||
tx,
|
||||
rx,
|
||||
ctx: cc.egui_ctx.clone(),
|
||||
};
|
||||
if app.cfg.game_path.is_empty() {
|
||||
// première fois : propose le dossier extrait à côté du projet, s'il existe
|
||||
if let Some(r) = &app.root {
|
||||
let guess = r.join("..").join("extracted").join("iso");
|
||||
if let Some(d) = find_game_dir(&guess) {
|
||||
app.cfg.game_path = dunce(&d);
|
||||
}
|
||||
}
|
||||
}
|
||||
app.recheck();
|
||||
app
|
||||
}
|
||||
|
||||
fn t(&self, fr: &'static str, en: &'static str) -> &'static str {
|
||||
if self.cfg.lang == Lang::En { en } else { fr }
|
||||
}
|
||||
|
||||
fn ui_handle(&self) -> Ui {
|
||||
Ui { tx: self.tx.clone(), ctx: self.ctx.clone() }
|
||||
}
|
||||
|
||||
fn recheck(&mut self) {
|
||||
let Some(root) = self.root.clone() else { return };
|
||||
if self.busy != Busy::No {
|
||||
return;
|
||||
}
|
||||
self.busy = Busy::Checking;
|
||||
let cfg = self.cfg.clone();
|
||||
let ui = self.ui_handle();
|
||||
thread::spawn(move || ui.send(Msg::Checks(run_checks(&root, &cfg))));
|
||||
}
|
||||
|
||||
fn pick(&self, kind: Pick) {
|
||||
let title = match kind {
|
||||
Pick::GameFolder => self.t("Dossier du jeu (CD ou copie)", "Game folder (CD or copy)"),
|
||||
Pick::GameIso => self.t("Image ISO du jeu", "Game ISO image"),
|
||||
Pick::Install => self.t("Dossier d'installation (TUCKER)", "Install folder (TUCKER)"),
|
||||
};
|
||||
let ui = self.ui_handle();
|
||||
thread::spawn(move || {
|
||||
if let Some(p) = pick_dialog(kind, title) {
|
||||
ui.send(Msg::Picked(kind, p));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn start_task(&mut self, name: &'static str, steps: Vec<String>) {
|
||||
let Some(root) = self.root.clone() else { return };
|
||||
self.busy = Busy::Task(name);
|
||||
self.last_ok = None;
|
||||
let ui = self.ui_handle();
|
||||
thread::spawn(move || {
|
||||
let ok = steps.iter().all(|s| run_streamed(&ui, &root, s));
|
||||
ui.log(if ok { "== OK ==" } else { "== ÉCHEC / FAILED ==" });
|
||||
ui.send(Msg::TaskDone { ok });
|
||||
});
|
||||
}
|
||||
|
||||
fn build(&mut self, regenerate: bool) {
|
||||
let (Some(dir), Some(vc)) = (self.checks.game_dir.clone(), self.checks.vcvars.clone()) else { return };
|
||||
let mut steps = Vec::new();
|
||||
if regenerate {
|
||||
// mêmes arguments que build.bat
|
||||
steps.push(format!(
|
||||
"python -I tools\\recomp.py \"{}\" build\\gen_tucker tucker F",
|
||||
dir.join("TUCKER.EXE").display()
|
||||
));
|
||||
steps.push(format!(
|
||||
"python -I tools\\recomp.py \"{}\" build\\gen_intro intro I",
|
||||
dir.join("INTRO.EXE").display()
|
||||
));
|
||||
}
|
||||
steps.push(format!("call \"{}\" >nul && build.bat nogen", vc.display()));
|
||||
self.start_task(if regenerate { "build" } else { "build-nogen" }, steps);
|
||||
}
|
||||
|
||||
fn install_capstone(&mut self) {
|
||||
self.start_task("capstone", vec!["python -m pip install --user capstone".into()]);
|
||||
}
|
||||
|
||||
fn download_sdl(&mut self) {
|
||||
let zip = format!("third_party\\dl\\SDL2-devel-{SDL_VER}-VC.zip");
|
||||
let script = format!(
|
||||
"$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; \
|
||||
New-Item -ItemType Directory -Force third_party\\dl | Out-Null; \
|
||||
Write-Output 'Téléchargement / Downloading {SDL_URL}'; \
|
||||
Invoke-WebRequest -Uri '{SDL_URL}' -OutFile '{zip}'; \
|
||||
Expand-Archive -Force '{zip}' third_party; Write-Output 'SDL2 {SDL_VER} OK'"
|
||||
);
|
||||
self.start_task("sdl", vec![format!("powershell -NoProfile -NonInteractive -Command \"{script}\"")]);
|
||||
}
|
||||
|
||||
fn install_dir(&self, game_dir: &Path) -> PathBuf {
|
||||
if !self.cfg.install_dir.trim().is_empty() {
|
||||
return PathBuf::from(self.cfg.install_dir.trim());
|
||||
}
|
||||
if let Some(r) = &self.root {
|
||||
let d = r.join("..").join("Install").join("C").join("TUCKER");
|
||||
if d.join("TUCKER.EXE").is_file() || d.is_dir() {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
game_dir.to_path_buf()
|
||||
}
|
||||
|
||||
fn play(&mut self) {
|
||||
let (Some(root), Some(dir)) = (self.root.clone(), self.checks.game_dir.clone()) else { return };
|
||||
let hd = self.install_dir(&dir);
|
||||
let hd_root = hd.parent().map(Path::to_path_buf).unwrap_or_else(|| hd.clone());
|
||||
let saves = root.join("saves");
|
||||
let _ = std::fs::create_dir_all(&saves);
|
||||
let mut cmd = hidden(&root.join("build").join("tucker.exe").to_string_lossy());
|
||||
cmd.current_dir(&root)
|
||||
.arg("--cd").arg(&dir)
|
||||
.arg("--exe").arg(dir.join("TUCKER.EXE"))
|
||||
.arg("--hd").arg(&hd)
|
||||
.arg("--root").arg(&hd_root)
|
||||
.arg("--saves").arg(&saves)
|
||||
.arg("--echelle").arg(self.cfg.scale.to_string());
|
||||
if self.cfg.sound { cmd.arg("--son"); }
|
||||
if self.cfg.skip_intro { cmd.arg("--sans-intro"); }
|
||||
if self.cfg.fullscreen { cmd.arg("--plein"); }
|
||||
if self.cfg.verbose { cmd.arg("-v"); }
|
||||
cmd.stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::piped());
|
||||
self.log.push(format!("> {:?}", cmd));
|
||||
match cmd.spawn() {
|
||||
Ok(mut child) => {
|
||||
self.game_running = true;
|
||||
let ui = self.ui_handle();
|
||||
thread::spawn(move || {
|
||||
if let Some(err) = child.stderr.take() {
|
||||
stream_lines(&ui, err);
|
||||
}
|
||||
let code = child.wait().ok().and_then(|s| s.code()).unwrap_or(-1);
|
||||
ui.send(Msg::GameExited(code));
|
||||
});
|
||||
}
|
||||
Err(e) => self.log.push(format!("!! {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn pump(&mut self) {
|
||||
while let Ok(m) = self.rx.try_recv() {
|
||||
match m {
|
||||
Msg::Log(s) => {
|
||||
self.log.push(s);
|
||||
if self.log.len() > MAX_LOG {
|
||||
self.log.drain(..self.log.len() - MAX_LOG);
|
||||
}
|
||||
}
|
||||
Msg::Checks(c) => {
|
||||
self.checks = c;
|
||||
if self.busy == Busy::Checking {
|
||||
self.busy = Busy::No;
|
||||
}
|
||||
}
|
||||
Msg::Picked(kind, p) => {
|
||||
match kind {
|
||||
Pick::GameFolder | Pick::GameIso => self.cfg.game_path = p,
|
||||
Pick::Install => self.cfg.install_dir = p,
|
||||
}
|
||||
self.recheck();
|
||||
}
|
||||
Msg::TaskDone { ok } => {
|
||||
self.last_ok = Some(ok);
|
||||
self.busy = Busy::No;
|
||||
self.recheck();
|
||||
}
|
||||
Msg::GameExited(code) => {
|
||||
self.game_running = false;
|
||||
self.log.push(format!("== {} {code} ==", self.t("jeu terminé, code", "game exited, code")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// chemin lisible (sans le préfixe \\?\ de canonicalize)
|
||||
fn dunce(p: &Path) -> String {
|
||||
let s = p.canonicalize().map(|c| c.display().to_string()).unwrap_or_else(|_| p.display().to_string());
|
||||
s.strip_prefix(r"\\?\").map(str::to_string).unwrap_or(s)
|
||||
}
|
||||
|
||||
const OK: Color32 = Color32::from_rgb(90, 200, 120);
|
||||
const BAD: Color32 = Color32::from_rgb(230, 90, 90);
|
||||
const ACCENT: Color32 = Color32::from_rgb(255, 196, 60);
|
||||
|
||||
fn status(ui: &mut egui::Ui, ok: bool, label: &str, detail: &str) {
|
||||
// pastille de couleur (les polices par défaut n'ont pas ✔/✖)
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(14.0, 14.0), egui::Sense::hover());
|
||||
ui.painter().circle_filled(rect.center(), 5.0, if ok { OK } else { BAD });
|
||||
ui.label(label);
|
||||
ui.label(RichText::new(detail).weak());
|
||||
}
|
||||
|
||||
impl eframe::App for App {
|
||||
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
self.pump();
|
||||
let busy = self.busy != Busy::No;
|
||||
if busy || self.game_running {
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_millis(200));
|
||||
}
|
||||
|
||||
// ---------------- en-tête
|
||||
egui::Panel::top("top").show(ui, |ui| {
|
||||
ui.add_space(6.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new("DoubleTroubleRecomp").size(26.0).strong().color(ACCENT));
|
||||
ui.label(RichText::new("Bud Tucker in Double Trouble").size(15.0).weak());
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.selectable_value(&mut self.cfg.lang, Lang::En, "EN");
|
||||
ui.selectable_value(&mut self.cfg.lang, Lang::Fr, "FR");
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
});
|
||||
|
||||
// ---------------- journal
|
||||
egui::Panel::bottom("log").resizable(true).default_size(140.0).show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(self.t("Journal", "Log")).strong());
|
||||
if ui.small_button(self.t("Effacer", "Clear")).clicked() {
|
||||
self.log.clear();
|
||||
}
|
||||
if ui.small_button(self.t("Copier", "Copy")).clicked() {
|
||||
ui.ctx().copy_text(self.log.join("\n"));
|
||||
}
|
||||
});
|
||||
egui::ScrollArea::vertical().stick_to_bottom(true).auto_shrink([false, false]).show(ui, |ui| {
|
||||
for l in &self.log {
|
||||
let color = if l.starts_with("> ") {
|
||||
ACCENT
|
||||
} else if l.contains("error") || l.contains("erreur") || l.starts_with("!!") || l.contains("ÉCHEC") {
|
||||
BAD
|
||||
} else {
|
||||
ui.visuals().text_color()
|
||||
};
|
||||
ui.label(RichText::new(l).monospace().size(12.0).color(color));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ui, |ui| {
|
||||
let Some(root) = self.root.clone() else {
|
||||
ui.label(RichText::new(self.t(
|
||||
"Dossier du projet introuvable : placez le launcher dans DoubleTroubleRecomp (à côté de build.bat).",
|
||||
"Project folder not found: put the launcher inside DoubleTroubleRecomp (next to build.bat).",
|
||||
)).color(BAD));
|
||||
return;
|
||||
};
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
// ---------------- 1. jeu
|
||||
ui.add_space(6.0);
|
||||
ui.heading(self.t("1. Jeu original", "1. Original game"));
|
||||
ui.label(RichText::new(self.t(
|
||||
"Dossier du CD, lecteur (ex. E:\\) ou image .iso. Les fichiers sont lus, jamais modifiés.",
|
||||
"CD folder, drive (e.g. E:\\) or .iso image. Files are read, never modified.",
|
||||
)).weak());
|
||||
ui.horizontal(|ui| {
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut self.cfg.game_path).desired_width(420.0));
|
||||
if r.lost_focus() {
|
||||
self.recheck();
|
||||
}
|
||||
if ui.button(self.t("Dossier…", "Folder…")).clicked() {
|
||||
self.pick(Pick::GameFolder);
|
||||
}
|
||||
if ui.button(self.t("Image ISO…", "ISO image…")).clicked() {
|
||||
self.pick(Pick::GameIso);
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| match (&self.checks.game_dir, &self.checks.game_error) {
|
||||
(Some(d), _) => status(ui, true, self.t("Jeu trouvé", "Game found"), &d.display().to_string()),
|
||||
(None, Some(e)) if !e.is_empty() => status(ui, false, self.t("Jeu introuvable", "Game not found"), e),
|
||||
_ if self.checks.done => status(ui, false, self.t("Choisissez le jeu", "Choose the game"), ""),
|
||||
_ => {
|
||||
ui.spinner();
|
||||
}
|
||||
});
|
||||
ui.collapsing(self.t("Avancé : dossier d'installation", "Advanced: install folder"), |ui| {
|
||||
ui.label(RichText::new(self.t(
|
||||
"Optionnel : dossier TUCKER créé par l'installation DOS (C:\\TUCKER). Vide = automatique.",
|
||||
"Optional: TUCKER folder created by the DOS install (C:\\TUCKER). Empty = automatic.",
|
||||
)).weak());
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(egui::TextEdit::singleline(&mut self.cfg.install_dir).desired_width(420.0));
|
||||
if ui.button("…").clicked() {
|
||||
self.pick(Pick::Install);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
// ---------------- 2. prérequis
|
||||
ui.horizontal(|ui| {
|
||||
ui.heading(self.t("2. Prérequis", "2. Requirements"));
|
||||
if ui.add_enabled(!busy, egui::Button::new(self.t("Vérifier", "Check"))).clicked() {
|
||||
self.recheck();
|
||||
}
|
||||
if self.busy == Busy::Checking {
|
||||
ui.spinner();
|
||||
}
|
||||
});
|
||||
let c = self.checks.clone();
|
||||
let mut action: Option<&'static str> = None;
|
||||
egui::Grid::new("checks").num_columns(4).spacing([10.0, 6.0]).show(ui, |ui| {
|
||||
status(ui, c.python.is_some(), "Python 3", c.python.as_deref().unwrap_or(self.t("absent de PATH", "not in PATH")));
|
||||
if c.python.is_none() {
|
||||
ui.hyperlink_to("python.org", "https://www.python.org/downloads/");
|
||||
}
|
||||
ui.end_row();
|
||||
status(ui, c.capstone.is_some(), "capstone", c.capstone.as_deref().unwrap_or(self.t("non installé", "not installed")));
|
||||
if c.capstone.is_none() && c.python.is_some()
|
||||
&& ui.add_enabled(!busy, egui::Button::new(self.t("Installer (pip)", "Install (pip)"))).clicked()
|
||||
{
|
||||
action = Some("capstone");
|
||||
}
|
||||
ui.end_row();
|
||||
let vc = c.vcvars.as_ref().map(|p| p.display().to_string());
|
||||
status(ui, vc.is_some(), "MSVC (Visual Studio 2022)", vc.as_deref().unwrap_or(self.t("introuvable", "not found")));
|
||||
if vc.is_none() {
|
||||
ui.hyperlink_to("Build Tools 2022", "https://visualstudio.microsoft.com/downloads/");
|
||||
}
|
||||
ui.end_row();
|
||||
status(ui, c.sdl, &format!("SDL2 {SDL_VER}"), if c.sdl { "third_party" } else { self.t("absent", "missing") });
|
||||
if !c.sdl && ui.add_enabled(!busy, egui::Button::new(self.t("Télécharger", "Download"))).clicked() {
|
||||
action = Some("sdl");
|
||||
}
|
||||
ui.end_row();
|
||||
});
|
||||
match action {
|
||||
Some("capstone") => self.install_capstone(),
|
||||
Some("sdl") => self.download_sdl(),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
// ---------------- 3. compilation
|
||||
ui.heading(self.t("3. Compilation", "3. Build"));
|
||||
ui.label(RichText::new(self.t(
|
||||
"Traduit TUCKER.EXE et INTRO.EXE en C, puis compile. Quelques minutes la première fois.",
|
||||
"Translates TUCKER.EXE and INTRO.EXE to C, then compiles. Takes a few minutes the first time.",
|
||||
)).weak());
|
||||
ui.horizontal(|ui| {
|
||||
let can = !busy && c.can_build();
|
||||
if ui.add_enabled(can, egui::Button::new(RichText::new(self.t("Générer et compiler", "Generate and build")).strong())).clicked() {
|
||||
self.build(true);
|
||||
}
|
||||
if ui.add_enabled(can && root.join("build").join("gen_tucker").is_dir(),
|
||||
egui::Button::new(self.t("Recompiler seulement", "Rebuild only"))).clicked()
|
||||
{
|
||||
self.build(false);
|
||||
}
|
||||
if let Busy::Task(_) = self.busy {
|
||||
ui.spinner();
|
||||
ui.label(self.t("en cours…", "running…"));
|
||||
} else if let Some(ok) = self.last_ok {
|
||||
ui.label(RichText::new(if ok { self.t("Terminé", "Done") } else { self.t("Échec, voir le journal", "Failed, see the log") })
|
||||
.color(if ok { OK } else { BAD }));
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| status(ui, c.built, self.t("Jeu compilé", "Game built"), "build\\tucker.exe"));
|
||||
|
||||
ui.separator();
|
||||
|
||||
// ---------------- 4. jouer
|
||||
ui.heading(self.t("4. Jouer", "4. Play"));
|
||||
let en = self.cfg.lang == Lang::En;
|
||||
let tr = |fr: &'static str, e: &'static str| if en { e } else { fr };
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.checkbox(&mut self.cfg.sound, tr("Son", "Sound"));
|
||||
ui.checkbox(&mut self.cfg.fullscreen, tr("Plein écran", "Fullscreen"));
|
||||
ui.checkbox(&mut self.cfg.skip_intro, tr("Passer l'intro", "Skip intro"));
|
||||
ui.checkbox(&mut self.cfg.verbose, tr("Journal détaillé", "Verbose log"));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(self.t("Taille de la fenêtre", "Window scale"));
|
||||
ui.add(egui::Slider::new(&mut self.cfg.scale, 1..=8).suffix("×"));
|
||||
ui.label(RichText::new(format!("{}×{}", 320 * self.cfg.scale, 240 * self.cfg.scale)).weak());
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
let can_play = !busy && !self.game_running && c.built && c.game_dir.is_some();
|
||||
let label = if self.game_running { self.t("Jeu en cours…", "Game running…") } else { self.t("JOUER", "PLAY") };
|
||||
if ui.add_enabled(can_play, egui::Button::new(RichText::new(label).size(20.0).strong().color(Color32::BLACK)).fill(ACCENT).min_size(egui::vec2(200.0, 44.0))).clicked() {
|
||||
self.play();
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.label(RichText::new(self.t("F11 ou Alt+Entrée : plein écran en jeu.", "F11 or Alt+Enter: toggle fullscreen in game.")).weak());
|
||||
});
|
||||
});
|
||||
|
||||
if self.cfg != self.saved {
|
||||
self.cfg.save();
|
||||
self.saved = self.cfg.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_title("DoubleTroubleRecomp")
|
||||
.with_inner_size([860.0, 820.0])
|
||||
.with_min_inner_size([640.0, 520.0]),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native("DoubleTroubleRecomp", options, Box::new(|cc| Ok(Box::new(App::new(cc)))))
|
||||
}
|
||||
Reference in new issue
Block a user