diff --git a/VPinballX.starter/App.xaml.cs b/VPinballX.starter/App.xaml.cs index 2b3d0bf..aff8b0f 100644 --- a/VPinballX.starter/App.xaml.cs +++ b/VPinballX.starter/App.xaml.cs @@ -22,6 +22,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the using System.Runtime.InteropServices; using Salaros.Configuration; using System.ComponentModel; +using System; namespace VPinballX.starter @@ -233,7 +234,7 @@ private void Application_Startup(object sender, StartupEventArgs eventArgs) } try { - string strSettingsIniFilePath = Path.Combine(strExeFilePath, $"{strIniConfigFilename}"); + string strSettingsIniFilePath = Path.Combine(strExeFilePath, strIniConfigFilename); if (!FileOrDirectoryExists(strSettingsIniFilePath)) { @@ -262,9 +263,10 @@ private void Application_Startup(object sender, StartupEventArgs eventArgs) 10.80=VPinballX85.exe 10.80x32=VPinballX85x32.exe 10.80GL=VPinballX85_GL.exe -;cmd files to run before and after a table has been started, uncomment to activate. -;PREcmd=${tablename}.pre.cmd -;POSTcmd=${tablename}.post.cmd"; +;cmd files to run before and after a table has been started. Activate here +PREPOSTactive=false +PREcmd=${tablename}.pre.cmd +POSTcmd=${tablename}.post.cmd"; string strWelcomeString = $@"Welcome new VPinballX.starter user! @@ -272,11 +274,8 @@ private void Application_Startup(object sender, StartupEventArgs eventArgs) We could not find a ""{strIniConfigFilename}"" next to ""{strExeFileName}"". The file should look like this: - X-----X-----X-----X----X-----X-----X-----X-----X - {strDefaultIniConfig} - X-----X-----X-----X----X-----X-----X-----X-----X VPinballX.starter can therefore be used as a VPinballX.exe replacement. @@ -284,9 +283,7 @@ VPinballX.starter can therefore be used as a VPinballX.exe replacement. It works like this: VPinballX.starter is started with exactly the same parameters as VPinballX.exe. First it loads the table file and finds out what version it was saved with. Then it takes that information and looks in the [VPinballX] table above to find out which version of VPinballX.xxx.exe you want to start with. It will then run the VPinballX.xxx.exe that you have configured using exactly the same parameters. - If it cannot find a version in the table the default entry under [VPinballX] will be used. If you simply double-click the VPinballX.starter without any table, the Default under [VPinballx.starter] is used. - This way the correct table version or the version you have chosen will always be used. Each time you start VPinballX, a log entry will be added to VPinballX.starter.log, telling which version was used. This can be turned of in the ini file. Do you want to create this file now?"; @@ -305,9 +302,10 @@ VPinballX.starter can therefore be used as a VPinballX.exe replacement. throw new FileNotFoundException($"Configuration \"{strSettingsIniFilePath}\" cannot be found!\n\nExiting"); } } + string[] AllTrue = new string[] { "true", "1", "yes" }; var configFileFromPath = new ConfigParser(strSettingsIniFilePath); - bool logVersions = (configFileFromPath["VPinballX.starter"]["LogVersions"] ?? "0").Equals("1"); + bool logVersions = AllTrue.Any((configFileFromPath["VPinballX.starter"]["LogVersions"] ?? "false").Trim().ToLower().Contains); string tableFilename = ""; @@ -342,7 +340,7 @@ VPinballX.starter can therefore be used as a VPinballX.exe replacement. if (!FileOrDirectoryExists(tableFilename)) { - if (logVersions) LogToFile($"Table file \"{tableFilename}\" cannot be found! Please check your frontend software!"); + LogToFile($"Table file \"{tableFilename}\" cannot be found! Please check your frontend software!"); throw new FileNotFoundException($"Table file\n\n{tableFilename}\n\n cannot be found!\nPlease check your frontend software!"); } @@ -398,31 +396,17 @@ VPinballX.starter can therefore be used as a VPinballX.exe replacement. LogToFile($"Using default version {strFileVersion} mapped to \"{vpxCommand}\""); } - string tableName = Path.GetFileNameWithoutExtension(Path.GetFileName(tableFilename)); - string preCommand = configFileFromPath["VPinballX"]["PREcmd"] ?? ""; - if (!preCommand.Equals("")) + bool PREPOSTactive = AllTrue.Any((configFileFromPath["VPinballX"]["PREPOSTactive"] ?? "false").Trim().ToLower().Contains); + if(PREPOSTactive) { - LogToFile($"Calling found PREcmd: {preCommand}"); - preCommand = preCommand.Replace("${tablename}", tableName); - preCommand = $"{Directory.GetCurrentDirectory()}\\{preCommand}"; - if (File.Exists(preCommand)) - { - LogToFile($"Calling found PREcmd: {preCommand}"); - StartAnotherProgram(preCommand, mArgs, false); - } + StartPrePostCommands("${tablename}.pre.cmd", strSettingsIniFilePath); + StartPrePostCommands(configFileFromPath["VPinballX"]["PREcmd"] ?? "", tableFilename); } StartAnotherProgram(vpxCommand, mArgs); - string postCommand = configFileFromPath["VPinballX"]["POSTcmd"] ?? ""; - if (!postCommand.Equals("")) - { - postCommand = postCommand.Replace("${tablename}", tableName); - postCommand = $"{Directory.GetCurrentDirectory()}\\{postCommand}"; - - if (File.Exists(postCommand)) - { - LogToFile($"Calling found POSTcmd: {postCommand}"); - StartAnotherProgram(postCommand, mArgs, false); - } + if (PREPOSTactive) + { + StartPrePostCommands(configFileFromPath["VPinballX"]["POSTcmd"] ?? "", tableFilename); + StartPrePostCommands("${tablename}.post.cmd", strSettingsIniFilePath); } Environment.Exit(0); @@ -442,7 +426,20 @@ VPinballX.starter can therefore be used as a VPinballX.exe replacement. Environment.Exit(1); } + void StartPrePostCommands(string prepostTemplate, string scriptBasedFilename) + { + if (!prepostTemplate.Equals("")) + { + string prepostCommand = prepostTemplate.Replace("${tablename}", Path.GetFileNameWithoutExtension(scriptBasedFilename)); + if (File.Exists(prepostCommand)) + { + LogToFile($"Calling found POSTcmd: {prepostCommand}"); + StartAnotherProgram(prepostCommand, mArgs, false); + } + } + + } void LogToFile(string logText) { using (var sw = File.AppendText(strLogFilename))