Skip to content

Commit

Permalink
make specifying unpack file optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZ1337 committed May 26, 2024
1 parent 724cd2a commit 568f0a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
26 changes: 25 additions & 1 deletion src/command/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::io_ext::ReadExt;
use crate::unity::AssetsFile;
use crate::unity::util::{AlignedString, AlignmentArgs};

pub fn unpack(args: &NewArgs, input: &PathBuf, output: &PathBuf) -> anyhow::Result<()> {
pub fn unpack(args: &NewArgs, input: &Option<PathBuf>, output: &PathBuf) -> anyhow::Result<()> {
let input = &find_input(args, input)?;
let extension = input.extension();
match extension {
Some(ext) => {
Expand All @@ -33,6 +34,29 @@ pub fn unpack(args: &NewArgs, input: &PathBuf, output: &PathBuf) -> anyhow::Resu
Ok(())
}

fn find_input(args: &NewArgs, input: &Option<PathBuf>) -> anyhow::Result<PathBuf> {
match input {
// Check if an input path was provided
Some(path) => {
if !path.is_file() {
anyhow::bail!("Input path is not a file");
}
Ok(path.clone())
}
None => {
let assets = args.game_dir
.join("PapersPlease_Data")
.join("sharedassets0.assets");

if assets.is_file() {
Ok(assets)
} else {
anyhow::bail!("No input file provided and no sharedassets0.assets file found in game directory");
}
}
}
}

pub fn unpack_dat(args: &NewArgs, input: &PathBuf, output: &PathBuf) -> anyhow::Result<()> {
let mut data = std::fs::read(input)
.context("Failed to read input file")?;
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ enum Command {
},
/// Unpack assets from an Art.dat or unity asset bundle.
Unpack {
/// Input file. Can either be an Art.dat file or a unity asset bundle. Make sure to either use the .dat or .assets extension.
/// Input file. Can either be an Art.dat file or a unity asset bundle. Make sure to either use the .dat or .assets extension. Defaults to the sharedassets0.assets in the game directory.
#[arg(short, long)]
input: PathBuf,
input: Option<PathBuf>,

/// Output directory.
#[arg(short, long, default_value = "./out")]
Expand All @@ -83,14 +83,12 @@ enum Command {
}

impl Command {

fn needs_key(&self) -> bool {
match self {
Command::Revert => false,
_ => true,
}
}

}

#[derive(Debug, Clone, Eq, PartialEq, ValueEnum)]
Expand Down

0 comments on commit 568f0a2

Please sign in to comment.