fix bootstrapper not being able to write errors when log dir doesn't exist

This commit is contained in:
Chris
2024-05-01 19:45:02 -06:00
parent c9089be0a4
commit 41aa72ae0f
2 changed files with 15 additions and 6 deletions

View File

@ -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

View File

@ -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<dyn std::error::Error>> {
]
.iter()
.collect();
let write = fs::create_dir_all(&file_path.parent().unwrap()).and_then(|()| {
let mut file = OpenOptions::new()
.append(true)
.create(true)
.open(&file_path)?;
if let Err(e) = writeln!(&mut file, "Bootstrapper Error MinEdLauncher.exe: {}", msg) {
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);
}