1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-07-19 23:37:46 +00:00
physis/examples/extractor.rs
Joshua Goins 81fff744f2 Overhaul file resource handling
This is a big API change, and it's probably not in it's ideal
shape right now. Physis makes a big assumption that the pool of
game data that you're reading from is in the compressed, SqPack
format like in retail. However, as the projects that use Physis
expand - so does the scope of data people want to punt into it.

For example, we have Icarus that makes it easy to read Excel data
but it can only do so through SqPack which makes it less useful in
scenarios where you want to read unpacked Excel modded files or
perhaps Excel data from the network.

So I created a Resource trait that GameData now implements (and
it's now called SqPackResource.) In a similar vain, Physis comes
with an UnpackedResource and a ResourceResolver to chain multiple
Resources together.
2025-07-08 21:37:03 -04:00

48 lines
1.5 KiB
Rust

// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
use physis::common::Platform;
use physis::resource::SqPackResource;
use std::env;
use std::fs::File;
use std::io::Write;
/// A simple program that allows a user to extract raw files from the game
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 4 {
println!("Usage: extractor [game dir] [filepath_to_extract] [destination]");
return;
}
// Collect our arguments
let game_dir = &args[1];
let file_path = &args[2];
let destination_path = &args[3];
// Create a GameData struct, this manages the repositories. It allows us to easily extract files.
let mut game_data = SqPackResource::from_existing(Platform::Win32, game_dir);
// Extract said file:
let Some(game_file) = game_data.extract(file_path) else {
println!("File {} not found!", file_path);
return;
};
// Create the file to write into.
let Ok(mut file) = File::create(destination_path) else {
println!("Failed to open file {} for writing.", destination_path);
return;
};
// Since GameData::extract returns a byte buffer, it's trivial to write that to a file on disk.
if file.write_all(&game_file).is_err() {
println!("Failed to write to file {}.", destination_path);
return;
};
println!(
"Successfully extracted {} to {}!",
file_path, destination_path
);
}