From 2ac897ffd82a784657d3fb9ab763256887bfb43a Mon Sep 17 00:00:00 2001 From: thehobbit85 Date: Wed, 25 Nov 2026 15:33:32 -0800 Subject: [PATCH] Skip empty logs when picking a game's crash log A game that makes its log at start and crashes before writing to it left an empty .log file, and that file was picked as the crash log over what the game printed. The crash window, reports and logs then showed nothing. Empty logs are now passed over, as the game's printed output already was. --- src-tauri/src/lib.rs | 46 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c133cbd1..b6c2ae08 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -6572,6 +6572,11 @@ pub(crate) fn recent_log_path(st: &App, id: &str, since: u64) -> Option if !(n.ends_with(".log") || n.ends_with("log.txt")) { continue; } + // An empty log (made at start, nothing written before it closed) says nothing, and it + // would hide what the game printed. + if m.len() == 0 { + continue; + } let Ok(t) = m.modified() else { continue }; let secs = t.duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0); if secs + 5 >= since && best.as_ref().map(|b| t > b.0).unwrap_or(true) && !old_inside(&p, since) { @@ -6590,9 +6595,10 @@ pub(crate) fn recent_log_path(st: &App, id: &str, since: u64) -> Option // Nor that: ReShade's, when it ran with a look. let best = best.or_else(|| { let p = st.dir.join("looks").join(&id).join("ReShade.log"); - let t = std::fs::metadata(&p).ok()?.modified().ok()?; + let m = std::fs::metadata(&p).ok()?; + let t = m.modified().ok()?; let secs = t.duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0); - (secs + 5 >= since).then_some((t, p)) + (m.len() > 0 && secs + 5 >= since).then_some((t, p)) }); best.map(|(_, p)| p) } @@ -11638,6 +11644,42 @@ mod tests { let _ = std::fs::remove_dir_all(&d); } + /// A game in `/game` whose logs folder holds `game.log` with `log` in it, and that printed + /// `printed` while it ran. The app's own folder is `d`. + fn game_with_logs(d: &Path, log: &str, printed: &str) -> App { + let _ = std::fs::remove_dir_all(d); + std::fs::create_dir_all(d.join("game/logs")).unwrap(); + std::fs::write(d.join("game/logs/game.log"), log).unwrap(); + let output = game_output_path(d, "g"); + std::fs::create_dir_all(output.parent().unwrap()).unwrap(); + std::fs::write(&output, printed).unwrap(); + let mut lib = Library::default(); + lib.installed.insert("g".into(), Installed { id: "g".into(), path: d.join("game"), local: true, ..Default::default() }); + app_in(d, lib) + } + + fn a_minute_ago() -> u64 { + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - 60 + } + + #[test] + fn an_empty_game_log_doesnt_hide_what_the_game_printed() { + let d = std::env::temp_dir().join(format!("rl-empty-log-{}", std::process::id())); + let st = game_with_logs(&d, "", "fatal: missing rom\n"); + let got = recent_log_path(&st, "g", a_minute_ago()); + let _ = std::fs::remove_dir_all(&d); + assert_eq!(got, Some(game_output_path(&d, "g"))); + } + + #[test] + fn a_game_log_with_lines_in_it_is_still_the_crash_log() { + let d = std::env::temp_dir().join(format!("rl-full-log-{}", std::process::id())); + let st = game_with_logs(&d, "loading level 3\nerror: out of memory\n", "fatal: missing rom\n"); + let got = recent_log_path(&st, "g", a_minute_ago()); + let _ = std::fs::remove_dir_all(&d); + assert_eq!(got, Some(d.join("game/logs/game.log"))); + } + pub(crate) fn app_in(dir: &Path, lib: Library) -> App { App { dir: dir.to_path_buf(),