Esempio n. 1
0
        private void Execute_Load(object sender, EventArgs e)
        {
            SaveData.loadData();

            int maxActions = SaveData.data.Descendants("action").Count();

            ExecuteProgress.Maximum = maxActions;
            ExecuteProgress.Value   = 0;

            File.WriteAllText("log.txt", "Begin execution (" + DateTime.Now + ")" + Environment.NewLine);

            foreach (var action in SaveData.data.Descendants("action"))
            {
                ExecuteProgress.Value++;
                ExecuteText.Text = "Executing... " + ExecuteProgress.Value.ToString() + "/" + ExecuteProgress.Maximum.ToString();

                bool run = false;
                foreach (var enabledProp in action.Descendants("run"))
                {
                    if (enabledProp.Value == "True")
                    {
                        run = true;
                    }
                    else
                    {
                        log("Skipping disabled action " + (string)action.Attribute("id"));
                    }
                }

                if (run)
                {
                    if ((string)action.Attribute("type") == "program")
                    {
                        string path = "";

                        foreach (var pathProp in action.Descendants("path"))
                        {
                            path = pathProp.Value;
                        }

                        if (safePath(path))
                        {
                            Process.Start(path);
                        }
                        else
                        {
                            log("Failed to execute program at path " + path);
                        }
                    }
                    else if ((string)action.Attribute("type") == "command")
                    {
                        List <string> commands = new List <string>();

                        foreach (var commandProp in action.Descendants("command"))
                        {
                            commands.Add(commandProp.Value);
                        }

                        Process shellProcess = new Process();
                        shellProcess.StartInfo.FileName = "cmd.exe";
                        shellProcess.StartInfo.RedirectStandardInput = true;
                        shellProcess.StartInfo.UseShellExecute       = false;

                        shellProcess.Start();

                        using (StreamWriter input = shellProcess.StandardInput)
                        {
                            if (input.BaseStream.CanWrite)
                            {
                                foreach (string command in commands)
                                {
                                    input.WriteLine(command);
                                }
                            }
                        }
                    }
                    else if ((string)action.Attribute("type") == "file")
                    {
                        string path = "";

                        foreach (var pathProp in action.Descendants("path"))
                        {
                            path = pathProp.Value;
                        }

                        if (safePath(path))
                        {
                            string handler = "(default)";

                            foreach (var handlerProp in action.Descendants("handler"))
                            {
                                handler = handlerProp.Value;
                            }

                            if (handler == "(default)")
                            {
                                Process.Start(path);
                            }
                            else
                            {
                                Process.Start(handler, path);
                            }
                        }
                        else
                        {
                            log("Failed to load file at path " + path);
                        }
                    }
                    else
                    {
                        log("Could not execute action with unrecognized type (check launch.xml to troubleshoot)");
                    }
                }
            }

            log("Complete (" + DateTime.Now + ")");

            if (File.ReadAllLines("log.txt").Length > 2) //something noteworthy happened
            {
                ExecuteText.Font = new Font(ExecuteText.Font, FontStyle.Italic);
                ExecuteText.Text = "Completed " + maxActions.ToString() + " with messages (click to view log)";
            }
            else
            {
                ExecuteText.Text = "Completed " + maxActions.ToString() + " (click to view log)";
            }

            if (Properties.Settings.Default.AutoCloseDialog)
            {
                closeTimer.Interval = 3000;
                closeTimer.Start();
                closeTimer.Tick += CloseTimer_Tick;
            }
        }
Esempio n. 2
0
        public void reloadList()
        {
            SaveData.loadData();

            ItemPanel.Controls.Clear();

            foreach (var action in SaveData.data.Descendants("action"))
            {
                ExecutionItem newItem = new ExecutionItem();
                string        title   = "";
                string        path    = "";
                bool          enabled = false;
                string        handler = "";

                string type = (string)action.Attribute("type");
                foreach (var titleProp in action.Descendants("title"))
                {
                    title = titleProp.Value;
                }
                foreach (var pathProp in action.Descendants("path"))
                {
                    path = pathProp.Value;
                }
                foreach (var runProp in action.Descendants("run"))
                {
                    if (runProp.Value == "True")
                    {
                        enabled = true;
                    }
                }
                foreach (var handlerProp in action.Descendants("handler"))
                {
                    handler = handlerProp.Value;
                }

                if (path.Contains("\\"))
                {
                    path = path.Split('\\')[path.Split('\\').Count() - 1];
                }

                if (handler.Contains("\\"))
                {
                    handler = handler.Split('\\')[handler.Split('\\').Count() - 1];
                }

                if (handler != "")
                {
                    if (handler == "(default)")
                    {
                        handler = "default"; //so it looks right
                    }
                    path += " (" + handler + ")";
                }

                newItem.SetProperties(title, path, enabled, type);
                newItem.manager = this;
                newItem.id      = (string)action.Attribute("id");

                ItemPanel.Controls.Add(newItem);
            }
        }