diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs index 8c9acdf2..71fbe702 100644 --- a/frontends/sdl/src/main.rs +++ b/frontends/sdl/src/main.rs @@ -411,7 +411,7 @@ impl Emulator { // into a *.sav file in the file system if counter % store_count == 0 && self.system.rom().has_battery() { let ram_data = self.system.rom().ram_data(); - write_file(&self.ram_path, ram_data).unwrap(); + write_file(&self.ram_path, ram_data, None).unwrap(); } // obtains an event from the SDL sub-system to be diff --git a/src/util.rs b/src/util.rs index ac82676f..9ff1883a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -32,13 +32,15 @@ pub fn read_file(path: &str) -> Result, Error> { } /// Writes the given data to the file at the given path. -pub fn write_file(path: &str, data: &[u8]) -> Result<(), Error> { +pub fn write_file(path: &str, data: &[u8], flush: Option) -> Result<(), Error> { let mut file = File::create(path) .map_err(|_| Error::CustomError(format!("Failed to create file: {}", path)))?; file.write_all(data) .map_err(|_| Error::CustomError(format!("Failed to write to file: {}", path)))?; - file.flush() - .map_err(|_| Error::CustomError(format!("Failed to flush file: {}", path)))?; + if flush.unwrap_or(true) { + file.flush() + .map_err(|_| Error::CustomError(format!("Failed to flush file: {}", path)))?; + } Ok(()) }