AriDEVParser.Util.CommandLine.GetValue C# (CSharp) Method

GetValue() public method

public GetValue ( string param ) : string
param string
return string
        public string GetValue(string param)
        {
            for (var i = 0; i < Arguments.Length; i++)
            {
                var str = Arguments[i];

                if (str != param)
                    continue;

                if (Arguments.Length > i)
                    return Arguments[i + 1];
            }

            return string.Empty;
        }

Usage Example

Beispiel #1
0
        private static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            CmdLine = new CommandLine(args);

            string file;
            string loader;
            string filters;
            string format;
            string nodump;

            try
            {
                file = CmdLine.GetValue("-file");
                loader = CmdLine.GetValue("-loader");
                filters = CmdLine.GetValue("-filters");
                format = CmdLine.GetValue("-sql");
                nodump = CmdLine.GetValue("-nodump");
            }
            catch (IndexOutOfRangeException)
            {
                PrintUsage("All command line options require an argument.");
                return;
            }

            try
            {
                var packets = Reader.Read(loader, file);
                if (packets == null)
                {
                    PrintUsage("Could not open file " + file + " for reading.");
                    return;
                }

                if (packets.Count() > 0)
                {
                    var fullPath = Utilities.GetPathFromFullPath(file);
                    Handler.InitializeLogFile(Path.Combine(fullPath, file + ".txt"), nodump);
                    SQLOutput.SQLOutput.Initialize(Path.Combine(fullPath, file + ".sql"), format);

                    var appliedFilters = filters.Split(',');

                    foreach (var packet in packets)
                    {
                        var opcode = packet.GetOpcode().ToString();
                        if (!string.IsNullOrEmpty(filters))
                        {
                            foreach (var opc in appliedFilters)
                            {
                                if (!opcode.Contains(opc))
                                    continue;

                                Handler.Parse(packet);
                                break;
                            }
                        }
                        else
                            Handler.Parse(packet);
                    }

                    SQLOutput.SQLOutput.WriteToFile();
                    Handler.WriteToFile();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType());
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            Console.ResetColor();
        }