Skip to content

Commit

Permalink
chore: made flush optional
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed May 10, 2024
1 parent 8c70500 commit 0098c18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontends/sdl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ pub fn read_file(path: &str) -> Result<Vec<u8>, 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<bool>) -> 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(())
}

Expand Down

0 comments on commit 0098c18

Please sign in to comment.