Skip to content

Commit 568f0a2

Browse files
committed
make specifying unpack file optional
1 parent 724cd2a commit 568f0a2

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/command/unpack.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::io_ext::ReadExt;
1313
use crate::unity::AssetsFile;
1414
use crate::unity::util::{AlignedString, AlignmentArgs};
1515

16-
pub fn unpack(args: &NewArgs, input: &PathBuf, output: &PathBuf) -> anyhow::Result<()> {
16+
pub fn unpack(args: &NewArgs, input: &Option<PathBuf>, output: &PathBuf) -> anyhow::Result<()> {
17+
let input = &find_input(args, input)?;
1718
let extension = input.extension();
1819
match extension {
1920
Some(ext) => {
@@ -33,6 +34,29 @@ pub fn unpack(args: &NewArgs, input: &PathBuf, output: &PathBuf) -> anyhow::Resu
3334
Ok(())
3435
}
3536

37+
fn find_input(args: &NewArgs, input: &Option<PathBuf>) -> anyhow::Result<PathBuf> {
38+
match input {
39+
// Check if an input path was provided
40+
Some(path) => {
41+
if !path.is_file() {
42+
anyhow::bail!("Input path is not a file");
43+
}
44+
Ok(path.clone())
45+
}
46+
None => {
47+
let assets = args.game_dir
48+
.join("PapersPlease_Data")
49+
.join("sharedassets0.assets");
50+
51+
if assets.is_file() {
52+
Ok(assets)
53+
} else {
54+
anyhow::bail!("No input file provided and no sharedassets0.assets file found in game directory");
55+
}
56+
}
57+
}
58+
}
59+
3660
pub fn unpack_dat(args: &NewArgs, input: &PathBuf, output: &PathBuf) -> anyhow::Result<()> {
3761
let mut data = std::fs::read(input)
3862
.context("Failed to read input file")?;

src/main.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ enum Command {
6060
},
6161
/// Unpack assets from an Art.dat or unity asset bundle.
6262
Unpack {
63-
/// Input file. Can either be an Art.dat file or a unity asset bundle. Make sure to either use the .dat or .assets extension.
63+
/// 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.
6464
#[arg(short, long)]
65-
input: PathBuf,
65+
input: Option<PathBuf>,
6666

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

8585
impl Command {
86-
8786
fn needs_key(&self) -> bool {
8887
match self {
8988
Command::Revert => false,
9089
_ => true,
9190
}
9291
}
93-
9492
}
9593

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

0 commit comments

Comments
 (0)