From 41aa72ae0f21082ac754984fecb7f4571372e49d Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 1 May 2024 19:45:02 -0600 Subject: [PATCH] fix bootstrapper not being able to write errors when log dir doesn't exist --- CHANGELOG.md | 3 +++ src/bootstrapper-rs/main.rs | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 217ea46..d49d2a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ If you relied on this behavior, you'll need to append `/autorun` to your launch options going forward. +### Bug fixes +- Prevent bootstrapper from not logging errors if log directory didn't already exist + ## [0.9.0] - 2023-09-12 ### New Features diff --git a/src/bootstrapper-rs/main.rs b/src/bootstrapper-rs/main.rs index a30b2a5..5290fd9 100644 --- a/src/bootstrapper-rs/main.rs +++ b/src/bootstrapper-rs/main.rs @@ -1,12 +1,12 @@ #[cfg(not(target_os = "windows"))] compile_error!("Can only be built on Windows"); -use std::env; use std::ffi::OsStr; use std::fs::OpenOptions; use std::io::Write; use std::os::windows::ffi::OsStrExt; use std::path::PathBuf; +use std::{env, fs}; use windows::core::{w, PCWSTR}; use windows::Win32::Foundation::GetLastError; use windows::Win32::UI::Shell::{ @@ -50,12 +50,18 @@ fn write_error(msg: &str) -> Result<(), Box> { ] .iter() .collect(); - let mut file = OpenOptions::new() - .append(true) - .create(true) - .open(&file_path)?; - if let Err(e) = writeln!(&mut file, "Bootstrapper Error MinEdLauncher.exe: {}", msg) { + let write = fs::create_dir_all(&file_path.parent().unwrap()).and_then(|()| { + let mut file = OpenOptions::new() + .append(true) + .create(true) + .open(&file_path)?; + + eprintln!("Bootstrapper Error MinEdLauncher.exe: {}", msg); + writeln!(&mut file, "Bootstrapper Error MinEdLauncher.exe: {}", msg) + }); + + if let Err(e) = write { eprintln!("Couldn't write to {}: {}", file_path.display(), e); }