SGA
What is SGA? SGA is a file format used by Relic games studio for many of their games. This library helps to parse and extract those files for viewing.
Installation
To install just run cargo add sga or add the following to your Cargo.toml
[dependencies]
sga = "0.1"
Usage
To unpack to a specified destination, just use the extract_all function.
use sga::extract_all;
fn main() {
extract_all("./ArtJapanese.sga", "./ArtJapanese").unwrap();
}
If you wish to do something more elaborate, for example only extracting the first folder and files from the table_of_contents, it is possible to construct the file tree, and then write it to disk.
pub fn extract_toc_folders_only<P: AsRef<Path>>(sga_file: P, out_path: P) -> anyhow::Result<()> {
let mut sga_file = BufReader::new(File::open(sga_file)?);
let mut entries = SgaEntries::new(&mut sga_file)?;
let toc_entries = std::mem::replace(&mut entries.tocs, Vec::new());
let tocs: Vec<_> = toc_entries
.into_iter()
.map(|toc| Toc::initialize_from_entry(&mut sga_file, &entries, toc).unwrap())
.collect();
for toc in tocs {
let folder = toc.root_folder.clone();
let files = FolderNode::read_files_from_folder(folder.clone(), &mut sga_file, &entries)?;
for file in files {
let file = Arc::new(file);
folder.lock().unwrap().add_child(Node::File(file));
}
write_to_disk(&mut sga_file, folder, &out_path)?;
}
Ok(())
}