private static bool SetOptionsUsingCommandLineParameters(PRISM.clsParseCommandLine commandLineParser) { // Returns True if no problems; otherwise, returns false var lstValidParameters = new List <string> { "F", "L" }; try { // Make sure no invalid parameters are present if (commandLineParser.InvalidParametersPresent(lstValidParameters)) { var badArguments = new List <string>(); foreach (var item in commandLineParser.InvalidParameters(lstValidParameters)) { badArguments.Add("/" + item); } ShowErrorMessage("Invalid command line parameters", badArguments); return(false); } // Query commandLineParser to see if various parameters are present if (commandLineParser.NonSwitchParameterCount > 0) { mDanteFilePath = commandLineParser.RetrieveNonSwitchParameter(0); } if (!ParseParameter(commandLineParser, "F", "a session file path", ref mDanteFilePath)) { return(false); } if (!ParseParameter(commandLineParser, "L", "a log file path", ref mLogFilePath)) { return(false); } return(true); } catch (Exception ex) { ShowErrorMessage("Error parsing the command line parameters: " + Environment.NewLine + ex.Message); } return(false); }
private static bool ParseParameter( PRISM.clsParseCommandLine commandLineParser, string parameterName, string description, ref string targetVariable) { string value; if (commandLineParser.RetrieveValueForParameter(parameterName, out value)) { if (string.IsNullOrWhiteSpace(value)) { ShowErrorMessage("/" + parameterName + " does not have " + description); return(false); } targetVariable = string.Copy(value); } return(true); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //if (AppUpdatesAvailableInternal()) //{ // MessageBox.Show("New version of Inferno available.", // "New version!", MessageBoxButtons.OK, MessageBoxIcon.Information); //} //Splasher.Show(typeof(frmSplash)); mDanteFilePath = string.Empty; mLogFilePath = string.Empty; try { var commandLineParser = new PRISM.clsParseCommandLine(); var success = false; if (commandLineParser.ParseCommandLine()) { if (SetOptionsUsingCommandLineParameters(commandLineParser)) { success = true; } } else { if (commandLineParser.ParameterCount + commandLineParser.NonSwitchParameterCount == 0 && !commandLineParser.NeedToShowHelp) { success = true; } } if (!success || commandLineParser.NeedToShowHelp) { var syntaxMessage = "Supported command line switches are /F and /L \n" + "Use '/F FilePath.dnt' to load a data file \n" + "Use '/L LogFilePath' to specify a custom log file path"; MessageBox.Show(syntaxMessage, "InfernoRDN Syntax", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (Exception ex) { MessageBox.Show("Exception parsing the command line arguments: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } var danteMDI = new frmDAnTEmdi(mDanteFilePath, mLogFilePath); if (!danteMDI.IsDisposed) { Application.Run(danteMDI); } }