Skip to content

Commit 98c68b4

Browse files
committedDec 18, 2024
feat: extractvbs now can write to any vbs path
1 parent 62b0c95 commit 98c68b4

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed
 

‎src/vpx/mod.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,19 @@ fn create_game_storage<F: Read + Write + Seek>(comp: &mut CompoundFile<F>) -> io
400400
comp.create_storage(&game_stg_path)
401401
}
402402

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

@@ -428,12 +427,16 @@ pub fn extractvbs(
428427
}
429428
}
430429

431-
/// Imports the sidecar script into the provided `vpx` file.
430+
/// Imports a script into the provided `vpx` file.
431+
///
432+
/// # Arguments
433+
/// * `vpx_file_path` Path to the VPX file
434+
/// * `vbs_file_path` Optional path to the script file to import. Defaults to the VPX sidecar script location.
432435
///
433436
/// see also [extractvbs]
434-
pub fn importvbs(vpx_file_path: &PathBuf, extension: Option<&str>) -> io::Result<PathBuf> {
435-
let script_path = match extension {
436-
Some(ext) => path_for(vpx_file_path, ext),
437+
pub fn importvbs(vpx_file_path: &PathBuf, vbs_file_path: Option<PathBuf>) -> io::Result<PathBuf> {
438+
let script_path = match vbs_file_path {
439+
Some(vbs_file_path) => vbs_file_path,
437440
None => vbs_path_for(vpx_file_path),
438441
};
439442
if !script_path.exists() {
@@ -1236,7 +1239,7 @@ mod tests {
12361239
let test_vpx_path = dir.join("test.vpx");
12371240
// make an empty file
12381241
File::create(&test_vpx_path).unwrap();
1239-
let result = extractvbs(&test_vpx_path, false, None);
1242+
let result = extractvbs(&test_vpx_path, None, false);
12401243
let script_path = vbs_path_for(&test_vpx_path);
12411244
assert!(result.is_err());
12421245
assert_eq!(

0 commit comments

Comments
 (0)