コード例 #1
0
        public FormMain()
        {
            _notifyIcon                  = new NotifyIcon();
            _notifyIcon.Icon             = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            _notifyIcon.Text             = "Buddy";
            _notifyIcon.BalloonTipTitle  = "Buddy";
            _notifyIcon.BalloonTipText   = "Buddy script is running in the background";
            _notifyIcon.ContextMenuStrip = new ContextMenuStrip();
            _notifyIcon.ContextMenuStrip.Items.Add("Exit", null, NotifyIconExit_Click);

            InitializeComponent();

            string[] args = Environment.GetCommandLineArgs();

            if (args.Length == 1)
            {
                MessageBox.Show("Script file not found", "No Script File", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string exePath    = args[0];
                string scriptFile = args[1];

                if (File.Exists(scriptFile))
                {
                    if (Path.GetExtension(scriptFile).Equals(".buddy"))
                    {
                        BuddyRuntimeLibrary.Run(File.ReadAllText(scriptFile));
                    }
                    else
                    {
                        MessageBox.Show("Only files with the *.buddy extensions are executable by this app", "Invalid Executable", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Script file path specified is invalid", "Invalid File Path", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: blapaz/buddy
        public FormMain()
        {
            _notifyIcon                  = new NotifyIcon();
            _notifyIcon.Icon             = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            _notifyIcon.Text             = "Buddy";
            _notifyIcon.BalloonTipTitle  = "Buddy";
            _notifyIcon.BalloonTipText   = "Buddy is running in the background";
            _notifyIcon.ContextMenuStrip = new ContextMenuStrip();
            _notifyIcon.ContextMenuStrip.Items.Add("Exit", null, NotifyIconExit_Click);

            InitializeComponent();

            string[] args = Environment.GetCommandLineArgs();

            if (args.Length == 1)
            {
                MessageBox.Show("Script file not found", "No Script File", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string exePath    = args[0];
                string scriptFile = args[1];

                foreach (string arg in args)
                {
                    if (arg.Equals("-s"))
                    {
                        _shouldSilentStart = true;
                    }
                    else if (arg.Equals("-o"))
                    {
                        _shouldOutputCompiled = true;
                    }
                }

                if (File.Exists(scriptFile))
                {
                    if (Path.GetExtension(scriptFile).Equals(".bud"))
                    {
                        string compiledCode = BuddyCompilerLibrary.Compile(scriptFile);

                        if (_shouldOutputCompiled)
                        {
                            using (FileStream fs = new FileStream(Path.Combine(Path.GetDirectoryName(scriptFile), Path.GetFileNameWithoutExtension(scriptFile) + ".buddy"), FileMode.Create))
                                using (BinaryWriter bw = new BinaryWriter(fs))
                                {
                                    bw.Write(compiledCode);
                                }
                        }

                        BuddyRuntimeLibrary.Run(compiledCode);
                    }
                    else if (Path.GetExtension(scriptFile).Equals(".buddy"))
                    {
                        BuddyRuntimeLibrary.Run(File.ReadAllText(scriptFile));
                    }
                    else
                    {
                        MessageBox.Show("Only files with the *.bud or *.buddy extensions are executable by this app", "Invalid Executable", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Script file path specified is invalid", "Invalid File Path", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }