using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace NPTGUI;

internal static class Program
{
	private const string nptDllName = "SubSysNPT_NET.dll";

	[STAThread]
	private static void Main(string[] args)
	{
		if (args.Length == 0)
		{
			CommandLineParameters commandLineParameters = new CommandLineParameters();
			commandLineParameters.commandLineMode = false;
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(defaultValue: false);
			Application.Run(new MainForm(commandLineParameters));
		}
		else
		{
			CommandLineParameters commandLineObj = PopulateCommandLineObject(args);
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(defaultValue: false);
			Application.Run(new MainForm(commandLineObj));
		}
	}

	private static CommandLineParameters PopulateCommandLineObject(string[] args)
	{
		CommandLineParameters commandLineParameters = new CommandLineParameters();
		commandLineParameters.Initialize();
		foreach (string text in args)
		{
			commandLineParameters.commandLineMode = true;
			if (text.Contains("help"))
			{
				commandLineParameters.helpMode = true;
				commandLineParameters.errorString = Environment.NewLine + "#################COMMAND LINE HELP############################" + Environment.NewLine + " SAMPLE USAGE IS :" + Environment.NewLine + Environment.NewLine + "QDART_NoiseProfilingTool.exe /logfileprefix=LTETest1 /tech=LTE /band=LTE_B1 /txon=false /txpower=15 /run=true /autocloseapp=true /logfolderpath=c:\\temp\\npt5\\Validation /chartymax=-80 /chartymin=-120 " + Environment.NewLine + Environment.NewLine + "Valid arguments are below : " + Environment.NewLine + commandLineParameters.GetAllArguments() + Environment.NewLine + "################################################";
				return commandLineParameters;
			}
			if (text.Contains("version"))
			{
				commandLineParameters.helpMode = true;
				FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo("SubSysNPT_NET.dll");
				string text2 = Assembly.GetExecutingAssembly().GetName().Version.ToString();
				commandLineParameters.errorString = Environment.NewLine + Environment.NewLine + "SubSysNPT_NET.dll [ Version " + versionInfo.FileVersion + "]" + Environment.NewLine + "QDART Noise Profiling Tool (Standalone) Version: [ Version " + text2 + "]" + Environment.NewLine + "Copyright (c) Qualcomm Technologies Incorporated 2015-2017. All rights reserved";
				return commandLineParameters;
			}
		}
		for (int j = 0; j < args.Count(); j++)
		{
			string text3 = "";
			string text4 = "";
			string text5 = "";
			if (args[j].Substring(0, 1) == "/")
			{
				text3 = args[j].Substring(1);
				if (text3.Contains("="))
				{
					string[] array = text3.Split('=');
					if (array.Length > 1)
					{
						text4 = array[0];
						text5 = array[1];
						text4 = text4.ToLower();
						switch (text4)
						{
						case "tech":
							commandLineParameters.tech = text5;
							break;
						case "band":
							commandLineParameters.band = text5;
							break;
						case "rxbw":
							commandLineParameters.rxBW = text5;
							break;
						case "txbw":
							commandLineParameters.txBW = text5;
							break;
						case "txpower":
							commandLineParameters.txPower = text5;
							break;
						case "txon":
							commandLineParameters.txON = text5;
							break;
						case "forcemaxpower":
							commandLineParameters.forceMaxPower = text5;
							break;
						case "run":
							commandLineParameters.run = text5;
							break;
						case "chipid":
							commandLineParameters.chipID = text5;
							break;
						case "autocloseapp":
							commandLineParameters.autoCloseApp = text5;
							break;
						case "samplenum":
							commandLineParameters.sampleNum = text5;
							break;
						case "logfolderpath":
							commandLineParameters.logFolderpath = text5;
							break;
						case "diversity":
							commandLineParameters.diversity = text5;
							break;
						case "targettype":
							commandLineParameters.targetType = text5;
							break;
						case "chartymax":
							commandLineParameters.chartymax = text5;
							break;
						case "chartymin":
							commandLineParameters.chartymin = text5;
							break;
						case "onlineonexit":
							commandLineParameters.onlineOnExit = text5;
							break;
						case "limittesting":
							commandLineParameters.limitTesting = text5;
							break;
						case "parentdatafile":
							commandLineParameters.parentdatafilepath = text5;
							break;
						case "deltalimitrx0":
							commandLineParameters.deltaLimitRX0 = text5;
							break;
						case "deltalimitrx1":
							commandLineParameters.deltaLimitRX1 = text5;
							break;
						case "limitrx0":
							commandLineParameters.limitRX0 = text5;
							break;
						case "limitrx1":
							commandLineParameters.limitRX1 = text5;
							break;
						case "calmode":
							commandLineParameters.calMode = text5;
							break;
						case "siggenlevel":
							commandLineParameters.sigGenLevel = text5;
							break;
						case "siggenoffset":
							commandLineParameters.sigGenOffset = text5;
							break;
						case "chlist1start":
							commandLineParameters.channelStart1 = text5;
							break;
						case "chlist2start":
							commandLineParameters.channelStart2 = text5;
							break;
						case "chlist3start":
							commandLineParameters.channelStart3 = text5;
							break;
						case "chlist4start":
							commandLineParameters.channelStart4 = text5;
							break;
						case "chlist5start":
							commandLineParameters.channelStart5 = text5;
							break;
						case "chlist1stop":
							commandLineParameters.channelStop1 = text5;
							break;
						case "chlist2stop":
							commandLineParameters.channelStop2 = text5;
							break;
						case "chlist3stop":
							commandLineParameters.channelStop3 = text5;
							break;
						case "chlist4stop":
							commandLineParameters.channelStop4 = text5;
							break;
						case "chlist5stop":
							commandLineParameters.channelStep5 = text5;
							break;
						case "chlist1step":
							commandLineParameters.channelStep1 = text5;
							break;
						case "chlist2step":
							commandLineParameters.channelStep2 = text5;
							break;
						case "chlist3step":
							commandLineParameters.channelStep3 = text5;
							break;
						case "chlist4step":
							commandLineParameters.channelStep4 = text5;
							break;
						case "chlist5step":
							commandLineParameters.channelStep5 = text5;
							break;
						case "gnsschan":
							commandLineParameters.gnssChan = text5;
							break;
						case "logfileprefix":
							commandLineParameters.logFilePrefix = text5;
							break;
						case "startdelay":
							commandLineParameters.startDelay = text5;
							break;
						case "startrb":
							commandLineParameters.startRB = text5;
							break;
						case "numrb":
							commandLineParameters.numRB = text5;
							break;
						case "chainsub":
							commandLineParameters.chainsub = text5;
							break;
						case "siggencontrol":
							commandLineParameters.sigGenControl = text5;
							break;
						case "rfmodemtype":
							commandLineParameters.rfModemType = text5;
							break;
						case "wlanmeasmode":
							commandLineParameters.WLANMeasMode = text5;
							break;
						case "antennaswitch":
							commandLineParameters.antennaSwitch = text5;
							break;
						case "ftmdaemon":
							commandLineParameters.ftmDaemon = text5;
							break;
						case "rx2rx3":
							commandLineParameters.Rx2Rx3 = text5;
							break;
						case "deltalmitrx2":
							commandLineParameters.deltaLimitRX2 = text5;
							break;
						case "deltalimitrx3":
							commandLineParameters.deltaLimitRX3 = text5;
							break;
						case "limitrx2":
							commandLineParameters.limitRX2 = text5;
							break;
						case "limitrx3":
							commandLineParameters.limitRX3 = text5;
							break;
						case "averagingtype":
							commandLineParameters.averagingType = text5;
							break;
						case "marktransients":
							commandLineParameters.markTransients = text5;
							break;
						case "beamId":
							commandLineParameters.beamID = text5;
							break;
						default:
							commandLineParameters.errorString = "Invalid command line argument: " + text4 + Environment.NewLine;
							commandLineParameters.errorString = commandLineParameters.GetAllArguments();
							break;
						}
					}
				}
				else
				{
					commandLineParameters.errorString = "Invalid command line argument format: " + text3 + ". Are you missing an = sign ?" + Environment.NewLine;
				}
			}
			else
			{
				commandLineParameters.errorString = "Invalid command line argument format: " + args[j] + ". Are you missing a / prefix ?" + Environment.NewLine;
			}
		}
		return commandLineParameters;
	}
}
