emu_runner/
includes.rs

1use camino::Utf8Path;
2use sha1_smol::Sha1;
3
4pub const BIZHAWK_BASH_DEFAULT: &'static [u8] = include_bytes!("includes/start-bizhawk.sh");
5pub const BIZHAWK_BASH_PRE290: &'static [u8] = include_bytes!("includes/start-bizhawk-pre290.sh");
6
7/// Writes data to the destination path, replacing if destination file exists and SHA1 mismatches.
8/// 
9/// Does _not_ create missing parent directories!
10pub fn copy_if_different<P: AsRef<Utf8Path>>(data: &[u8], dest: P) -> std::io::Result<()> {
11    let dest = dest.as_ref();
12    
13    if dest.is_file() {
14        let old = std::fs::read(&dest)?;
15        let hash_new = Sha1::from(&data).digest();
16        let hash_old = Sha1::from(&old).digest();
17        
18        if hash_new == hash_old {
19            return Ok(());
20        }
21    }
22    
23    std::fs::write(dest, data)
24}