Example #1
0
        static void Main(string[] args)
        {
            if (Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\CafeHaine\Windmenu", "test", string.Empty) == null)
            {
                Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\CafeHaine\",
                                  "", "");
                Registry.SetValue(
                    @"HKEY_CURRENT_USER\SOFTWARE\CafeHaine\Windmenu\", "",
                    "");
            }
            else
            {
                int pid = (int)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\CafeHaine\Windmenu", "clientid", -1);
                if (pid != -1)
                {
                    string    processName = (string)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\CafeHaine\Windmenu", "clientname", string.Empty);
                    Process[] procs       = Process.GetProcessesByName(processName);
                    foreach (Process proc in procs)
                    {
                        if (proc.Id == pid)
                        {
                            proc.Kill();
                        }
                    }
                }
            }
            Process current = Process.GetCurrentProcess();

            Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\CafeHaine\Windmenu", "clientid", current.Id);
            Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\CafeHaine\Windmenu", "clientname", current.ProcessName);
            current.Dispose();

            #region Argument parsing
            Bar.Position Pos         = Bar.Position.top;
            Color        NormalBack  = Color.Black;
            Color        NormalFore  = Color.White;
            Color        FocusedBack = getModernAccent();

            Color FocusedFore = Color.White;
            Font  Font        = new Font("Courier New", 14);

            int i = 0;
            while (i < args.Length)
            {
                switch (args[i])
                {
                case "-b":
                    Pos = Bar.Position.bottom;
                    break;

                case "-nb":
                    if (i + 1 < args.Length && args[i + 1].StartsWith("#"))
                    {
                        NormalBack = parseHex(args[i + 1], NormalBack);
                        i++;
                    }
                    break;

                case "-nf":
                    if (i + 1 < args.Length && args[i + 1].StartsWith("#"))
                    {
                        NormalFore = parseHex(args[i + 1], NormalFore);
                        i++;
                    }
                    break;

                case "-sb":
                    if (i + 1 < args.Length && args[i + 1].StartsWith("#"))
                    {
                        FocusedBack = parseHex(args[i + 1], FocusedBack);
                        i++;
                    }
                    break;

                case "-sf":
                    if (i + 1 < args.Length && args[i + 1].StartsWith("#"))
                    {
                        FocusedFore = parseHex(args[i + 1], FocusedFore);
                        i++;
                    }
                    break;

                case "-fn":
                    if (i + 1 < args.Length && args[i + 1].Contains(":"))
                    {
                        string[] fnt = args[i + 1].Split(':');
                        float    size;
                        if (float.TryParse(args[1], out size))
                        {
                            Font = new Font(fnt[0], size);
                        }
                        i++;
                    }
                    break;
                }
                i++;
            }
            #endregion

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
#if !DEBUG
            try
            {
                Application.Run(new Bar(Pos, NormalBack, NormalFore,
                                        FocusedBack, FocusedFore, Font));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "windmenu Client");
            }
#else
            Application.Run(new Bar(Pos, NormalBack, NormalFore,
                                    FocusedBack, FocusedFore, Font));
#endif
        }
Example #2
0
        static void Main(string[] args)
        {
            //TODO: check if argument syntax is valid
            #region Argument parsing
            Bar.Position pos    = Bar.Position.bottom;
            Screen       output = Screen.PrimaryScreen;

            Color barFore = Color.White;
            Color barBack = Color.Black;
            Color wsForeF = Color.White;
            Color wsForeN = Color.FromArgb(200, 200, 200);
            Color wsBackF = Color.Firebrick;
            Color wsBackN = Color.FromArgb(25, 25, 25);

            string fontName = "Courier New";
            int    fontSize = 12;
            string command  = Path.GetDirectoryName(Application.ExecutablePath) + "\\TestStatus.exe";

            foreach (string arg in args)
            {
                string[] data = arg.Split('=');
                switch (data[0])
                {
                case "command":
                    if (data[1] != "NotSet")
                    {
                        command = data[1];
                    }
                    break;

                case "pos":
                    if (data[1] == "top")
                    {
                        pos = Bar.Position.top;
                    }
                    break;

                case "colors":
                    string[] colors = data[1].Split(':');
                    barBack = HexColor.HexToColor(colors[0], barBack, false);
                    barFore = HexColor.HexToColor(colors[1], barFore);
                    wsBackN = HexColor.HexToColor(colors[2], wsBackN);
                    wsForeN = HexColor.HexToColor(colors[3], wsForeN);
                    wsBackF = HexColor.HexToColor(colors[4], wsBackF);
                    wsForeF = HexColor.HexToColor(colors[5], wsForeF);
                    break;

                case "font":
                    string[] fontInfo = data[1].Split(':');
                    fontName = fontInfo[0];
                    fontSize = int.Parse(fontInfo[1]);
                    break;

                default:
                    MessageBox.Show("Invalid argument: " + data[0]);
                    break;
                }
            }

            Font font = new Font(fontName, fontSize, GraphicsUnit.Pixel);
            #endregion

            Process statusLine = new Process();
            statusLine.StartInfo.FileName = command;
            statusLine.StartInfo.RedirectStandardOutput = true;
            statusLine.StartInfo.UseShellExecute        = false;
            statusLine.Start();
            StreamReader statusStream = statusLine.StandardOutput;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Bar(pos, output, barBack, barFore,
                                    wsForeF, wsForeN, wsBackF, wsBackN, font, ref statusStream));
            if (!statusLine.HasExited)
            {
                statusLine.Kill();
            }
        }