Пример #1
0
        public void GetArgumentsFromString_1StringArgumentWithoutSpecialChars_WillReturn1Arg()
        {
            string commandLine = "/S=helloworld";

            Assert.AreEqual(1, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual("S=helloworld", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
        }
Пример #2
0
        public void RequiredParamsAreBeforeOptional()
        {
            using var sw = new StringWriter();
            Console.SetOut(sw);

            var args   = new[] { "--a", "b", "--b", "b" };
            var parser = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new OptionalCommandlineArgumentRule("a", "Default A", "Optional"),
                new RequiredCommandlineArgumentRule("b", "Required")
            });

            var output = new ConsoleOutputFormatter(parser);
            var l      = $"Usage: {AppName}";

            output.Write();
            var expected =
                $"{l}\r\n" +
                (new string(' ', l.Length + 2)) + "--b\r\n" +
                (new string(' ', l.Length + 2)) + "[--a=<Default A>]\r\n" +
                "\r\n" +
                "a  :Optional\r\n" +
                "b  :Required\r\n";

            Assert.AreEqual(expected, sw.ToString());
        }
Пример #3
0
        public void GetArgumentsFromString_1BoolArgument_WillReturn1Args()
        {
            string commandLine = "/W";

            Assert.AreEqual(1, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual("W", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
        }
Пример #4
0
        static void Main(string[] args)
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            if (!mySingleInstanceMutex.WaitOne(0, false))
            {
                if (DialogResult.Yes != MessageBox.Show("Running MeGUI instance detected!\n\rThere's not really much point in running multiple copies of MeGUI, and it can cause problems.\n\rDo You still want to run yet another MeGUI instance?", "Running MeGUI instance detected", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    return;
                }
            }
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            CommandlineParser parser = new CommandlineParser();

            parser.Parse(args);
            MeGUIInfo info     = new MeGUIInfo();
            MainForm  mainForm = new MainForm();

            mainForm.AttachInfo(info);
            info.handleCommandline(parser);
            if (parser.start)
            {
                Application.Run(mainForm);
            }
        }
Пример #5
0
 public Features(CommandlineParser parser, TextFileAdapter adapter, LineBuffer buffer, Pager pager)
 {
     _parser = parser;
     _adapter = adapter;
     _buffer = buffer;
     _pager = pager;
 }
Пример #6
0
        public void OptionalRuleDefaultValuesAreNotGiven()
        {
            using var sw = new StringWriter();
            Console.SetOut(sw);

            var args   = new[] { "--a", "b", "--b", "b" };
            var parser = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new OptionalCommandlineArgumentRule("a", "Default A", "Optional A"),
                new OptionalCommandlineArgumentRule("b", null, "Optional B")
            });

            var output = new ConsoleOutputFormatter(parser);
            var l      = $"Usage: {AppName}";

            output.Write();
            var expected =
                $"{l}\r\n" +
                (new string(' ', l.Length + 2)) + "[--a=<Default A>]\r\n" +
                (new string(' ', l.Length + 2)) + "[--b]\r\n" +
                "\r\n" +
                "a  :Optional A\r\n" +
                "b  :Optional B\r\n";

            Assert.AreEqual(expected, sw.ToString());
        }
Пример #7
0
        public void GetArgumentsFromString_1StringArgumentContainingBackSlash_WillReturn1Args()
        {
            string commandLine = @"/S=hello\world";

            Assert.AreEqual(1, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual(@"S=hello\world", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
        }
Пример #8
0
        public void GetArgumentsFromString_1StringArgumentContainingDblQuotes_WillReturn1Args()
        {
            string commandLine = @"/S=""hello\""/world""";

            Assert.AreEqual(1, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual(@"S=""hello""/world""", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
        }
Пример #9
0
 public Features(CommandlineParser parser, TextFileAdapter adapter, LineBuffer buffer, Pager pager)
 {
     _parser  = parser;
     _adapter = adapter;
     _buffer  = buffer;
     _pager   = pager;
 }
        public void ToStingWithSpaces()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--c", "Hello World" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual("--a b --c \"Hello World\"", parser.ToString());
        }
Пример #11
0
        public void GetArgumentsFromString_2StringArgumentWithoutSpecialChars_WillReturn2Arg()
        {
            string commandLine = "/S=helloworld /R=howareyou";

            Assert.AreEqual(2, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual("S=helloworld", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
            Assert.AreEqual("R=howareyou", CommandlineParser.GetArgumentsFromString(commandLine)[1]);
        }
        public void TestDefaultValues()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual("d", parser.Get("c", "d"));
        }
        public void GetIntTypeThatIsNotAnInt()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(default(int), parser.Get("a", 12)); //  there is a value, so we will return the default.
        }
        public void GetDoubleTypeReturnTheDefault()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(12.34, parser.Get("c", 12.34)); // return the default value.
        }
        public void TestNoDefaultValueGiven()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(null, parser.Get("c"));
        }
        public void GetDoubleTypeWithNoGivenDefault()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(default(double), parser.Get <double>("c")); //  there is a value, so we will return the default.
        }
        public void GetIntTypeWithNoGivenDefaultReturnTheDefault()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(default(int), parser.Get <int>("c")); // return the default value.
        }
        public void GetDoubleType()
        {
            // the arguments
            var args   = new[] { "--a", "12.34" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(12.34, parser.Get <double>("a", 0)); //  fake default
        }
Пример #19
0
        public void GetArgumentsFromString_2BoolArgumentWithoutSpace_WillReturn2Args()
        {
            string commandLine = "/W/Q";

            Assert.AreEqual(2, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual("W", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
            Assert.AreEqual("Q", CommandlineParser.GetArgumentsFromString(commandLine)[1]);
        }
        public void GetIntType()
        {
            // the arguments
            var args   = new[] { "--a", "12" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(12, parser.Get("a", 0)); //  fake default
        }
Пример #21
0
        public void GetArgumentsFromString_1StringArgumentWithFrontSlashInValue_WillReturn2Args()
        {
            string commandLine = @"/S=hello/world";

            Assert.AreEqual(2, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual("S=hello", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
            Assert.AreEqual("world", CommandlineParser.GetArgumentsFromString(commandLine)[1]);
        }
        public void CloneToStingWithSpacesDoesNotAddExtraQuotes()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--c", "Hello World" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone();

            Assert.AreEqual("--a b --c \"Hello World\"", clone.ToString());
        }
Пример #23
0
        private static unsafe void CreateProcess(byte *str_addr, byte *exec_path, uint priority)
        {
            var sb = new StringBuilder();

            while (*str_addr != '\0')
            {
                sb.Append(*str_addr);
                str_addr++;
            }

            var commandLine = sb.ToString();
            var cmd         = CommandlineParser.Parse(commandLine, Kernel.Variables);

            var path = new StringBuilder();

            while (*exec_path != '\0')
            {
                sb.Append(*exec_path);
                str_addr++;
            }

            var file    = Kernel.FileSystem.GetFile(path.ToString());
            var buffer  = Cosmos.Core.Memory.Heap.Alloc((uint)file.mSize);
            var stream  = file.GetFileStream();
            int tmpByte = stream.ReadByte();

            var bufferPtr = buffer;

            while (tmpByte != -1)
            {
                *bufferPtr = (byte)tmpByte;
                tmpByte = stream.ReadByte();
            }

            var process = new Process.Process(commandLine, cmd.Args, (int)priority);

            process.PCB.Context = new INTs.IRQContext {
                CS         = process.PCB.Context.CS,
                EAX        = process.PCB.Context.EAX,
                EBX        = process.PCB.Context.EBX,
                ECX        = process.PCB.Context.ECX,
                EDX        = process.PCB.Context.EDX,
                EDI        = process.PCB.Context.EDI,
                EFlags     = process.PCB.Context.EFlags,
                EIP        = (uint)buffer,
                ESI        = process.PCB.Context.ESI,
                ESP        = process.PCB.Context.ESP,
                Interrupt  = process.PCB.Context.Interrupt,
                MMXContext = process.PCB.Context.MMXContext,
                Param      = process.PCB.Context.Param,
                UserESP    = process.PCB.Context.UserESP
            };
            // TODO: Setting PC register in process.Context to pointer to the buffer.

            ProcessManager.ProcessList.Add(process);
            ProcessManager.ReadyQueue.Enqueue(process);
        }
Пример #24
0
        public void GetArgumentsFromString_InvalidInput4_UnendingDblQuoteAtEnd()
        {
            string commandLine = @"/S=""hello \""world"" /R=""How are u doing /F=""c:\dellshare.com\*.csproj";

            //Assert.AreEqual(4, ArgumentParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual(@"S=""hello ""world""", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
            Assert.AreEqual(@"R=""How are u doing /F=""", CommandlineParser.GetArgumentsFromString(commandLine)[1]);
            Assert.AreEqual(@"c:\dellshare.com\*.csproj", CommandlineParser.GetArgumentsFromString(commandLine)[2]);
        }
        public void ToStringRemoveNonExistentMultipleValuesWithSomeNoValue()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--e", "--c", "d" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone().Remove("z");

            Assert.AreEqual("--a b --e --c d", clone.ToString());
        }
        public void ToStringMultipleValues()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--c", "d" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone();

            Assert.AreEqual("--a b --c d", clone.ToString());
        }
        public void TestArgumentsCanBeNull()
        {
            // the arguments
            var parser = new CommandlineParser(null);

            // and we can get values.
            Assert.IsFalse(parser.IsSet("a"));
            Assert.IsFalse(parser.IsSet("b"));
        }
        public void CloneValue()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone();

            Assert.AreEqual("b", clone["a"]); //  direct value.
        }
        public void TestFlagsWithNoValueAloneNonDefaultLeadingPattern()
        {
            // the arguments
            var args   = new[] { "-a" };
            var parser = new CommandlineParser(args, null, "-");

            // "a" exist
            Assert.IsTrue(parser.IsSet("a"));
        }
        public void ToStringRecoverLeadingValueMultipleValuesWithSomeNoValue()
        {
            // the arguments
            var args   = new[] { "-a", "b", "-e", "-c", "d" };
            var parser = new CommandlineParser(args, null, "-");
            var clone  = parser.Clone();

            Assert.AreEqual("-a b -e -c d", clone.ToString());
        }
Пример #31
0
        public void GetArgumentsFromString_3StringArgument_WillReturn3Args()
        {
            string commandLine = @"/S=""hello world"" /R=How are u doing /F=""c:\dellshare.com\*.csproj""";

            Assert.AreEqual(3, CommandlineParser.GetArgumentsFromString(commandLine).Count);
            Assert.AreEqual(@"S=""hello world""", CommandlineParser.GetArgumentsFromString(commandLine)[0]);
            Assert.AreEqual(@"R=How are u doing", CommandlineParser.GetArgumentsFromString(commandLine)[1]);
            Assert.AreEqual(@"F=""c:\dellshare.com\*.csproj""", CommandlineParser.GetArgumentsFromString(commandLine)[2]);
        }
Пример #32
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(UnhandledException);

            Manager = new Superscrot.Manager();
            LoadSettings();

            CommandlineParser cmd = new CommandlineParser(args);
            if (startedWithDefaultSettings || cmd["config"] != null)
            {
                ShowConfigEditor();
            }

            bool created = false;
            startupEventHandle = new EventWaitHandle(false,
                EventResetMode.ManualReset,
                Environment.UserName + "SuperscrotStartup", out created);
            if (created)
            {
                if (!Manager.InitializeKeyboardHook())
                {
                    Exit();
                    return;
                }
                Tray.Show();
                Application.Run();
            }
            else
            {
                MessageBox.Show(SR.InstanceAlreadyRunning, Application.ProductName,
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
        }
Пример #33
0
        public void handleCommandline(CommandlineParser parser)
        {
            foreach (string file in parser.failedUpgrades)
                System.Windows.Forms.MessageBox.Show("Failed to upgrade '" + file + "'.", "Upgrade failed", MessageBoxButtons.OK, MessageBoxIcon.Error);

            if (parser.upgradeData.Count > 0)
            {
                UpdateWindow update = new UpdateWindow(this, Settings);
                foreach (string file in parser.upgradeData.Keys)
                    update.UpdateVersionNumber(file, parser.upgradeData[file]);
                update.SaveSettings();
            }
        }
Пример #34
0
 static void Main(string[] args)
 {
     System.Windows.Forms.Application.EnableVisualStyles();
     if (!mySingleInstanceMutex.WaitOne(0, false))
     {
         if (DialogResult.Yes != MessageBox.Show("Running MeGUI instance detected!\n\rThere's not really much point in running multiple copies of MeGUI, and it can cause problems.\n\rDo You still want to run yet another MeGUI instance?", "Running MeGUI instance detected", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
             return;
     }
     Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
     CommandlineParser parser = new CommandlineParser();
     parser.Parse(args);
     MeGUIInfo info = new MeGUIInfo();
     MainForm mainForm = new MainForm();
     mainForm.AttachInfo(info);
     info.handleCommandline(parser);
     if (parser.start)
         Application.Run(mainForm);
 }
 public void SetUp()
 {
     commandlineParser = new CommandlineParser();
 }