1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-22 13:42:47 +00:00

make vanilla extractor input and output configurable

This commit is contained in:
Sallai József 2022-08-28 14:07:01 +03:00
parent 028c60157d
commit dec913dd65
2 changed files with 20 additions and 7 deletions

View file

@ -318,7 +318,18 @@ impl SharedGameState {
let settings = Settings::load(ctx)?;
let mod_requirements = ModRequirements::load(ctx)?;
let vanilla_extractor = VanillaExtractor::from(ctx, "Doukutsu.exe".to_string());
let vanilla_ext_exe = match option_env!("VANILLA_EXT_EXE") {
Some(exe_name) => exe_name,
None => "Doukutsu.exe",
};
let vanilla_ext_outdir = match option_env!("VANILLA_EXT_OUTDIR") {
Some(outdir) => outdir,
None => "data",
};
let vanilla_extractor =
VanillaExtractor::from(ctx, vanilla_ext_exe.to_string(), vanilla_ext_outdir.to_string());
if vanilla_extractor.is_some() {
let result = vanilla_extractor.unwrap().extract_data();
if result.is_err() {

View file

@ -18,6 +18,7 @@ use crate::{
pub struct VanillaExtractor {
exe_buffer: Vec<u8>,
data_base_dir: String,
}
const VANILLA_STAGE_COUNT: u32 = 95;
@ -26,7 +27,7 @@ const VANILLA_STAGE_OFFSET: u32 = 0x937B0;
const VANILLA_STAGE_TABLE_SIZE: u32 = VANILLA_STAGE_COUNT * VANILLA_STAGE_ENTRY_SIZE;
impl VanillaExtractor {
pub fn from(ctx: &mut Context, exe_name: String) -> Option<Self> {
pub fn from(ctx: &mut Context, exe_name: String, data_base_dir: String) -> Option<Self> {
let mut vanilla_exe_path = env::current_exe().unwrap();
vanilla_exe_path.pop();
vanilla_exe_path.push(exe_name);
@ -37,7 +38,7 @@ impl VanillaExtractor {
log::info!("Found vanilla game executable, attempting to extract resources.");
if filesystem::exists(ctx, "/data/stage.sect") {
if filesystem::exists(ctx, format!("{}/stage.sect", data_base_dir.clone())) {
log::info!("Vanilla resources are already extracted, not proceeding.");
return None;
}
@ -55,7 +56,7 @@ impl VanillaExtractor {
return None;
}
Some(Self { exe_buffer })
Some(Self { exe_buffer, data_base_dir })
}
pub fn extract_data(&self) -> GameResult {
@ -96,7 +97,8 @@ impl VanillaExtractor {
for org in orgs.unwrap().data_files {
let mut org_path = env::current_exe().unwrap();
org_path.pop();
org_path.push("data/Org/");
org_path.push(self.data_base_dir.clone());
org_path.push("Org/");
if self.deep_create_dir_if_not_exists(org_path.clone()).is_err() {
return Err(ParseError("Failed to create directory structure.".to_string()));
@ -132,7 +134,7 @@ impl VanillaExtractor {
for bitmap in bitmaps.unwrap().data_files {
let mut data_path = env::current_exe().unwrap();
data_path.pop();
data_path.push("data/");
data_path.push(self.data_base_dir.clone());
if self.deep_create_dir_if_not_exists(data_path.clone()).is_err() {
return Err(ParseError("Failed to create data directory structure.".to_string()));
@ -182,7 +184,7 @@ impl VanillaExtractor {
let mut stage_tbl_path = env::current_exe().unwrap();
stage_tbl_path.pop();
stage_tbl_path.push("data/");
stage_tbl_path.push(self.data_base_dir.clone());
if self.deep_create_dir_if_not_exists(stage_tbl_path.clone()).is_err() {
return Err(ParseError("Failed to create data directory structure.".to_string()));