Skip to content

Commit

Permalink
Add project
Browse files Browse the repository at this point in the history
  • Loading branch information
lempface committed Jul 3, 2022
1 parent 5da3086 commit bff2e8d
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 0 deletions.
6 changes: 6 additions & 0 deletions App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
76 changes: 76 additions & 0 deletions Program.cs
@@ -0,0 +1,76 @@
using System;
using CommandLine;
using System.Threading;
using System.IO;
using System.Diagnostics;

namespace VPX_VBS_Extractor
{
class Program
{
static void Main(string[] args)
{
ParserResult<Options> options = Parser.Default.ParseArguments<Options>(args);

ManualResetEvent resetEvent = new ManualResetEvent(false);

string[] tablePaths = Directory.GetFiles(options.Value.PathToTables, "*.vpx");

foreach (string tablePath in tablePaths)
{
string tableFile = (new FileInfo(tablePath)).Name;
string vbsFile = tableFile.Replace(".vpx", ".vbs");
string vbsPath = Path.Combine(options.Value.PathToTables, vbsFile);

if (!options.Value.Overwrite && File.Exists(vbsPath))
{
Console.WriteLine($"SKIP: Script already exists for {tableFile}");
continue;
}

string commandString = $"-minimized -extractvbs \"{tablePath}\"";

ProcessStartInfo startInfo = new ProcessStartInfo(options.Value.PathToVPinballXExecutable, commandString);
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = true;

Process process = new Process();
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
process.Exited += (s, e) => { resetEvent.Set(); };

process.Start();

if (resetEvent.WaitOne(options.Value.TimeoutSeconds * 1000)) {
Console.WriteLine($"CREATE: {vbsFile}");
}
else
{
Console.WriteLine($"TIMEOUT: {vbsFile} - Unsure if script was extracted correctly.");
}

resetEvent.Reset();

if (options.Value.TestMode) return;
}
}
}

public class Options
{
[Option('o', "overwrite", Default = false, HelpText = "Will overwrite existing .vbs files if true, will skip the table file if false.")]
public bool Overwrite { get; set; }

[Option('w', "timeout", Default = 60, HelpText = "Number of seconds to wait for VPX to exit before continuing to the next table.")]
public int TimeoutSeconds { get; set; }

[Option('t', "pathToTables", HelpText = "The path to the vpx tables, e.g. C:\\VisualPinball\\Tables", Required = true)]
public string PathToTables { get; set; }

[Option('p', "pathToVPinballX", HelpText = "The path to VPinballX.exe, e.g. C:\\VisualPinball\\VPinballX.exe", Required = true)]
public string PathToVPinballXExecutable { get; set; }

[Option('s', "testMode", Default = false, HelpText = "If true, stops after extracting the first script. Useful to tune timeout length.")]
public bool TestMode { get; set; }
}
}
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VPX-VBS-Extractor")]
[assembly: AssemblyDescription("Console utility to extract vbs scripts from Visual Pinball X tables.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VPX-VBS-Extractor")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9b62778b-23fd-4cb6-bae1-c62464f1c00e")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
43 changes: 43 additions & 0 deletions README.md
@@ -0,0 +1,43 @@


# VPX-VBS-Extractor
A utility for bulk extracting .VBS scripts from Visual Pinball X table files (.VPX)
.VBS files are saved in the same directory as the table files. The default behavior is to extract .VBS scripts from tables where a matching .VBS file does not already exist. Extraction is handled by Visual Pinball X, this utility just provides the means to extract .VBS files from a folder of table files.

### Usage
-o, --overwrite (Default: false) Will overwrite existing .vbs files if true, will skip the table file if
false.

-w, --timeout (Default: 60) Number of seconds to wait for VPX to exit before continuing to the next table.

-t, --pathToTables Required. The path to the vpx tables, e.g. C:\VisualPinball\Tables

-p, --pathToVPinballX Required. The path to VPinballX.exe, e.g. C:\VisualPinball\VPinballX.exe

-s, --testMode (Default: false) If true, stops after extracting the first script. Useful to tune timeout
length.

--help Display this help screen.

--version Display version information.

### Output
The console will write CREATE, SKIP, or TIMEOUT to based on the result of the
e.g.
CREATE: Freddy A Nightmare On Elm Street (Gottlieb 1994).vbs
SKIP: Script already exists for Avengers LE (Stern 2012).vpx
TIMEOUT: Hurricane (Williams 1991).vbs - Unsure if script was extracted correctly.

### Examples

- Standard Usage
VPX-VBS-Extractor.exe --pathToTables "D:\vPinball\VisualPinball\Tables" -pathToVPinballX "D:\vPinball\VisualPinball\VPinballX.exe"

- Test Mode
VPX-VBS-Extractor.exe --pathToTables "D:\vPinball\VisualPinball\Tables" -pathToVPinballX "D:\vPinball\VisualPinball\VPinballX.exe" -s

- Slow Computer - Increase timeout before starting the next extraction (120 seconds)
VPX-VBS-Extractor.exe --pathToTables "D:\vPinball\VisualPinball\Tables" -pathToVPinballX "D:\vPinball\VisualPinball\VPinballX.exe" -w 120

- Overwrite existing .VBS files
VPX-VBS-Extractor.exe --pathToTables "D:\vPinball\VisualPinball\Tables" -pathToVPinballX "D:\vPinball\VisualPinball\VPinballX.exe" -o
58 changes: 58 additions & 0 deletions VPX-VBS-Extractor.csproj
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9B62778B-23FD-4CB6-BAE1-C62464F1C00E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>VPX_VBS_Extractor</RootNamespace>
<AssemblyName>VPX-VBS-Extractor</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=2.9.1.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
<HintPath>packages\CommandLineParser.2.9.1\lib\net461\CommandLine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions VPX-VBS-Extractor.sln
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29418.71
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VPX-VBS-Extractor", "VPX-VBS-Extractor.csproj", "{9B62778B-23FD-4CB6-BAE1-C62464F1C00E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9B62778B-23FD-4CB6-BAE1-C62464F1C00E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B62778B-23FD-4CB6-BAE1-C62464F1C00E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B62778B-23FD-4CB6-BAE1-C62464F1C00E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B62778B-23FD-4CB6-BAE1-C62464F1C00E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4A673BA5-A546-4790-8682-43D8718770C8}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions packages.config
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineParser" version="2.9.1" targetFramework="net472" />
</packages>

0 comments on commit bff2e8d

Please sign in to comment.