warm-up: no restart unless the mark went down

The mark's write result was discarded and the game restarted whatever
it was. The launcher arms a new warm-up whenever no mark exists, so
one write failure (a denied folder, a full disk, antivirus) had every
start play its 20 seconds and start again, for ever. The write now
decides: no mark, no restart, and the run goes on at its slow pace
with a note in the menu.

(cherry picked from commit 5cf201a877b1f4a5ff45b124d9fdc621ad2fb51b)
This commit is contained in:
Cannnabis authored and trustno1-coder committed 2026-11-27 17:29:36 -08:00
1 parent de4c8af474
commit aa7dd70250
1 file changed
+34 -7
+34 -7
View File
@@ -207,6 +207,17 @@ pub(crate) fn warmup_seconds() -> Option<u64> {
get("VICTORY_WARMUP_RESTART").parse().ok().filter(|s| *s > 0)
}
/// Marks this victory.exe as warmed up, whether it went down. Only a
/// written mark can end the warm-up: the launcher arms a new one whenever
/// none exists (`apps/victory/src/play.rs`, `warmup_mark`), so the write's
/// result is what decides whether the restart is safe to do.
fn mark_written(mark: &std::path::Path) -> bool {
if let Some(dir) = mark.parent() {
let _ = std::fs::create_dir_all(dir);
}
std::fs::write(mark, "this victory.exe was warmed up (its first start, then a restart)\r\n").is_ok()
}
/// The start's notice lines for the warm-up start ([`warmup_seconds`]).
pub(crate) fn warmup_notice(seconds: u64) -> Vec<String> {
vec![
@@ -680,14 +691,17 @@ impl Menu {
}
DONE.store(true, Ordering::Relaxed);
let mark = std::path::PathBuf::from(get("VICTORY_WARMUP_MARK"));
if !mark.as_os_str().is_empty() {
if let Some(dir) = mark.parent() {
let _ = std::fs::create_dir_all(dir);
}
let _ = std::fs::write(&mark, "this victory.exe was warmed up (its first start, then a restart)\r\n");
let marked = mark.as_os_str().is_empty() || mark_written(&mark);
if marked {
tracing::info!(seconds, mark = %mark.display(), "first start of this victory.exe: warmed up; the game starts again");
self.restart(false);
} else {
// The launcher arms a warm-up whenever no mark exists: one the
// host could not write would have the game come back here for
// ever, so this start goes on at its slow pace instead.
tracing::warn!(mark = %mark.display(), "first start: the warmed mark could not be written; the game goes on, no restart");
self.note = "WARMED UP, BUT THE MARK WOULD NOT WRITE: THIS RUN GOES ON".to_owned();
}
tracing::info!(seconds, mark = %mark.display(), "first start of this victory.exe: warmed up; the game starts again");
self.restart(false);
}
/// Reads which saves `Saves` holds, keeping the one picked if it is still there.
@@ -924,6 +938,19 @@ impl Menu {
mod tests {
use super::*;
/// A mark that lands ends the warm-up; one that cannot (here, beside a
/// file of the same name) does not: the launcher arms a new warm-up
/// whenever no mark exists, and a restart without one would come back
/// here for ever.
#[test]
fn a_mark_that_cannot_be_written_does_not_end_the_warm_up() {
let dir = tempfile::tempdir().unwrap();
let blocked = dir.path().join("a file");
std::fs::write(&blocked, b"not a folder").unwrap();
assert!(mark_written(&dir.path().join("warmed").join("mark")));
assert!(!mark_written(&blocked.join("mark")));
}
#[test]
fn a_change_is_saved_at_once_however_the_game_was_started() {
let home = std::env::temp_dir().join(format!("victory-menu-test-{}", std::process::id()));