Skip to content

Commit

Permalink
Add additional options for the command working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Systemcluster committed Nov 21, 2023
1 parent b9113c9 commit 2c0b09b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ wrappe --compression 16 dist dist/diogenes.exe packed.exe

Run `wrappe` with an `input` directory, the `command` to launch and the `output` filename to create a single-binary executable. The input directory and all contained files and links will be packed. The command must be an executable file within the input directory that should be launched after unpacking.

If the packed executable needs to access files inside its working directory by relative path, use the `--current-dir` option to set the working directory to the unpack directory. The `WRAPPE_UNPACK_DIR` and `WRAPPE_LAUNCH_DIR` environment variables will always be set for the command allowing access to either location.
If the packed executable needs to access packed files by relative path and expects a certain working directory, use the [`--current-dir`](#current-dir) option to set it to its parent directory or the unpack directory. The `WRAPPE_UNPACK_DIR` and `WRAPPE_LAUNCH_DIR` environment variables will always be set for the command with the paths to the unpack directory and the inherited working directory.

Packed Windows executables will have their subsystem, icons and other resources automatically transferred to the output executable through [editpe](https://github.com/Systemcluster/editpe).

Expand Down Expand Up @@ -73,7 +73,7 @@ Options:
-n, --console <CONSOLE>
Show or attach to a console window (auto, always, never, attach) [default: auto]
-w, --current-dir
Set the current working directory of the target to the unpack directory
Set the working directory of the command (inherit, unpack, runner, command) [default: inherit]
-l, --list-runners
Print available runners
-h, --help
Expand Down Expand Up @@ -155,7 +155,14 @@ It defaults to `auto`. This option currently only affects Windows runners, other

#### current-dir

By default the working directory of the packed executable is set to the working directory of the runner executable. This flag changes the working directory to the unpack directory.
This option changes the working directory of the packed executable. Accepted values are:

* `inherit`: The working directory will be inherited from the runner. This is usually the directory containing the runner or the directory from which the runner was launched.
* `unpack`: The working directory will be set to the unpack directory. This is the top-level directory of the unpacked payload.
* `runner`: The working directory will be set to the directory containing the runner, with all symbolic links resolved.
* `command`: The working directory will be set to the directory containing the unpacked executable. This will either be the unpack directory or a subdirectory within the unpacked payload.

It defaults to `inherit`.

## Compilation

Expand Down
22 changes: 22 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,28 @@ pub fn get_show_console(show_console: &str, runner_name: &str) -> u8 {
}
}

pub fn get_current_dir(current_dir: &str) -> u8 {
match current_dir.to_lowercase().as_str() {
"inherit" => 0,
"unpack" => 1,
"runner" => 2,
"command" => 3,
_ => {
println!(
"{}: {}",
style("not a valid current directory option").red(),
style(current_dir).red(),
);
println!(
"{}: inherit {}, directory, runner, command",
style("available current directory options").blue().bright(),
style("(default)").bold().dim()
);
std::process::exit(-1);
}
}
}

pub fn get_source(source: &Path) -> PathBuf {
let source = Path::new(&std::env::current_dir().unwrap()).join(source);
let source = std::fs::canonicalize(&source).unwrap_or_else(|_| {
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub struct Args {
/// Show or attach to a console window (auto, always, never, attach)
#[arg(short = 'n', long, default_value = "auto")]
console: String,
/// Set the current working directory of the target to the unpack directory
#[arg(short = 'w', long)]
current_dir: bool,
/// Set the working directory of the command (inherit, unpack, runner, command)
#[arg(short = 'w', long, default_value = "inherit")]
current_dir: String,
/// Print available runners
#[arg(short = 'l', long)]
#[allow(dead_code)]
Expand Down Expand Up @@ -97,6 +97,7 @@ fn main() {
let verification = get_verification(&args.verification);
let show_information = get_show_information(&args.show_information);
let arguments = get_arguments(&args.arguments);
let current_dir = get_current_dir(&args.current_dir);

let mut show_console = get_show_console(&args.console, runner_name);

Expand Down Expand Up @@ -285,7 +286,7 @@ fn main() {
let info = StarterInfo {
signature: [0x50, 0x45, 0x33, 0x44, 0x41, 0x54, 0x41, 0x00],
show_console,
current_dir: args.current_dir.into(),
current_dir,
verification,
show_information,
uid: version.as_bytes().try_into().unwrap(),
Expand Down
10 changes: 6 additions & 4 deletions startpe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ fn main() {
}

let launch_dir = std::env::current_dir().unwrap();
let current_dir = if info.current_dir == 1 {
&unpack_dir
} else {
&launch_dir
let current_dir = match info.current_dir {
0 => &launch_dir,
1 => &unpack_dir,
2 => exe.parent().unwrap(),
3 => run_path.parent().unwrap(),
_ => panic!("invalid current directory"),
};
if show_information >= 2 {
println!("current dir: {}", current_dir.display());
Expand Down

0 comments on commit 2c0b09b

Please sign in to comment.