Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extractvbs provide script path #118

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions src/vpx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,20 +400,19 @@ fn create_game_storage<F: Read + Write + Seek>(comp: &mut CompoundFile<F>) -> io
comp.create_storage(&game_stg_path)
}

/// Extracts the vbs script from an existing `vpx` file and writes it next to the file as sidecar script.
/// Extracts the script from an existing `vpx` file.
///
/// @param vpx_file_path Path to the VPX file
/// @param overwrite If true, the script will be extracted even if it already exists
/// @param extension If set, the script will be written to a file with that extension instead of `vbs`
///
/// *When Visual Pinball finds this script it will use that instead of the one embedded in the file.*
/// # Arguments
/// * `vpx_file_path` Path to the VPX file
/// * `vbs_file_path` Optional path to the script file to write. Defaults to the VPX sidecar script location.
/// * `overwrite` If true, the script will be extracted even if it already exists
pub fn extractvbs(
vpx_file_path: &PathBuf,
vbs_file_path: Option<PathBuf>,
overwrite: bool,
extension: Option<&str>,
) -> io::Result<ExtractResult> {
let script_path = match extension {
Some(ext) => path_for(vpx_file_path, ext),
let script_path = match vbs_file_path {
Some(vbs_file_path) => vbs_file_path,
None => vbs_path_for(vpx_file_path),
};

Expand All @@ -428,12 +427,16 @@ pub fn extractvbs(
}
}

/// Imports the sidecar script into the provided `vpx` file.
/// Imports a script into the provided `vpx` file.
///
/// # Arguments
/// * `vpx_file_path` Path to the VPX file
/// * `vbs_file_path` Optional path to the script file to import. Defaults to the VPX sidecar script location.
///
/// see also [extractvbs]
pub fn importvbs(vpx_file_path: &PathBuf, extension: Option<&str>) -> io::Result<PathBuf> {
let script_path = match extension {
Some(ext) => path_for(vpx_file_path, ext),
pub fn importvbs(vpx_file_path: &PathBuf, vbs_file_path: Option<PathBuf>) -> io::Result<PathBuf> {
let script_path = match vbs_file_path {
Some(vbs_file_path) => vbs_file_path,
None => vbs_path_for(vpx_file_path),
};
if !script_path.exists() {
Expand Down Expand Up @@ -1236,7 +1239,7 @@ mod tests {
let test_vpx_path = dir.join("test.vpx");
// make an empty file
File::create(&test_vpx_path).unwrap();
let result = extractvbs(&test_vpx_path, false, None);
let result = extractvbs(&test_vpx_path, None, false);
let script_path = vbs_path_for(&test_vpx_path);
assert!(result.is_err());
assert_eq!(
Expand Down
Loading