示例#1
0
        private void AccecptSettings(bool closeForm)
        {
            StoredPreferences.Instance.ExecuteExpandSelection     = m_chkExpandSelection.Checked;
            StoredPreferences.Instance.ShowToolTips               = m_chkShowToolTips.Checked;
            StoredPreferences.Instance.PrintSelectionResourceInfo = m_chkPrintSelectionResourceInfo.Checked;
            StoredPreferences.Instance.ConsoleGUIShare            = (double)m_numDropDownConsoleGUIShare.Value;
            StoredPreferences.Instance.RectangleWidth             = (float)m_numDropDownRectangleWidth.Value;
            StoredPreferences.SavePrefernces();

            if (m_chkPrintWrappedCommands.Checked)
            {
                CommandExecuter.Instance.Execute(new PrintWrappedCommands());
            }
            else
            {
                CommandExecuter.Instance.Execute(new StopToPrintWrappedCommands());
            }

            m_parentForm.Invalidate();

            if (closeForm)
            {
                Close();
            }
        }
示例#2
0
        private void m_menuFileExit_Click(object sender, EventArgs e)
        {
            // save settings
            StoredPreferences.SavePrefernces();

            Environment.Exit(0);
        }
        private void CreateBackupAndDelete()
        {
            string prefFile = StoredPreferences.GetPreferenceFileName();

            if (!File.Exists(prefFile))
            {
                return;
            }
            // create backup (overwrite existing bcakup)
            string backup = Path.GetFileNameWithoutExtension(prefFile) + ".backup";

            if (File.Exists(backup))
            {
                File.Delete(backup);
            }
            File.Copy(prefFile, backup);
            File.Delete(prefFile);
        }
示例#4
0
        static void Main(string[] args)
        {
            // TCL API init
            //TclAPI.Initialize();
            mainInterpreter = new TclInterpreter();
            unsafe
            {
                ExecuteGOAcmd = TclProcs.ExecuteGOACommand;
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "cs", TclProcs.Cs);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "cshelp", TclProcs.CsHelp);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "cslist", TclProcs.CsList);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "clear", TclProcs.Clear);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "clearcontext", TclProcs.ClearContext);
                //TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "test", TclProcs.Test);
            }
            //int rc = mainInterpreter.EvalScript("puts [testproc Tile]");
            //Console.WriteLine("rc=" + rc + " Interp.Result = " + mainInterpreter.Result);

            // restore settings
            StoredPreferences.LoadPrefernces();

            // check vars
            StringBuilder errorList;

            if (!EnvChecker.CheckEnv(out errorList))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(errorList.ToString());
                Console.ResetColor();
            }

            // detect commands without default constructor
            foreach (Type type in CommandStringParser.GetAllCommandTypes())
            {
                try
                {
                    Command cmd = (Command)Activator.CreateInstance(type);
                    TclDLL.Helper_RegisterProc(mainInterpreter.ptr, type.Name, ExecuteGOAcmd);
                    unsafe
                    {
                        //string[] parts = cmd.ToString().Split(' ');
                        //if (parts[0].EndsWith(";")) parts[0] = parts[0].Substring(0, parts[0].Length - 1);
                        TclDLL.Helper_RegisterProc(mainInterpreter.ptr, type.Name, ExecuteGOAcmd);
                    }
                }
                catch (Exception)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Warning: No default constructor found for command " + type.Name);
                    Console.ResetColor();
                }
            }



            // register console hook
            // first hook print progress to clean the % output
            CommandExecuter.Instance.AddHook(new PrintProgressToConsoleHook());
            // the profiling hook must be added before the output hook hooks as it produces output
            CommandExecuter.Instance.AddHook(new ProfilingHook());
            CommandExecuter.Instance.AddHook(new ConsoleCommandHook());
            CommandExecuter.Instance.AddHook(new PrintOutputHook());

            // check if init.goa is found in binary of the current assembly
            string dir      = AssemblyDirectory;
            string initFile = dir + Path.DirectorySeparatorChar + "init.goa";

            // if so, execute init.goa
            if (File.Exists(initFile))
            {
                RunScript runInitCmd = new RunScript();
                runInitCmd.FileName = initFile;
                CommandExecuter.Instance.Execute(runInitCmd);
                //FileInfo fi = new FileInfo(initFile);
                //CommandExecuter.Instance.Execute(fi);
            }
            else
            {
                Console.WriteLine("GoAhead did not find the init file: " + initFile);
            }

            bool   showGUIOnly = false;
            bool   execScript  = false;
            string scriptFile  = "";
            bool   shellMode   = false;
            bool   serverMode  = false;
            int    portNumber  = 0;
            bool   commandMode = false;

            if (args.Length == 0)
            {
                showGUIOnly = true;
            }
            else
            {
                int i = 0;
                while (i < args.Length)
                {
                    switch (args[i])
                    {
                    case "-gui":
                        showGUIOnly = true;
                        break;

                    case "-exec":
                        execScript = true;
                        scriptFile = GetScriptFileName(args, i + 1);
                        i++;
                        break;

                    case "-shell":
                        shellMode = true;
                        break;

                    case "-command":
                    case "-commands":
                        commandMode = true;
                        break;

                    case "-server":
                        portNumber = int.Parse(args[i + 1]);
                        i++;
                        break;

                    default:
                        if (args[i].EndsWith(".goa") && File.Exists(args[i]))
                        {
                            execScript = true;
                            scriptFile = GetScriptFileName(args, i);
                        }
                        break;
                    }
                    i++;
                }
            }
            if (showGUIOnly)
            {
                // open gui
                CommandExecuter.Instance.Execute(new Commands.GUI.ShowGUI());
            }
            else if (execScript)
            {
                if (!File.Exists(scriptFile))
                {
                    string errorMessage = "Error: File " + scriptFile + " not found";
                    // allow the test scripts to catch this string (goahead -exec script.goa | tee.goa)
                    Console.WriteLine(errorMessage);
                    throw new ArgumentException(errorMessage);
                }

                // command file mode
                FileInfo fi = new FileInfo(scriptFile);
                CommandExecuter.Instance.Execute(fi);
            }
            else if (shellMode)
            {
                Objects.CommandShell shell = new Objects.CommandShell();
                shell.Run();
            }
            else if (serverMode)
            {
                Objects.CommandServer server = new Objects.CommandServer();
                server.Run(portNumber);
            }
            else if (commandMode)
            {
                string cmdString = "";
                if (args.Length > 1)
                {
                    for (int i = 1; i < args.Length; i++)
                    {
                        cmdString += args[i] + " ";
                    }
                }
                if (string.IsNullOrEmpty(cmdString))
                {
                    Console.WriteLine("GoAhead was started with -commands, but no command was given");
                }
                Command             cmd;
                string              errorDescr;
                CommandStringParser parser = new CommandStringParser(cmdString);
                foreach (string subCommandString in parser.Parse())
                {
                    bool valid = parser.ParseCommand(subCommandString, true, out cmd, out errorDescr);
                    if (!valid)
                    {
                        Console.WriteLine(errorDescr);
                    }
                    CommandExecuter.Instance.Execute(cmd);
                }
            }
            else
            {
                Console.WriteLine("No switch found. Start GoAhead with one of the following options:");
                Console.WriteLine("GoAhead -gui             : Open GoAhead in GUI-Mode");
                Console.WriteLine("GoAhead -exec script.goa : Execute script.goa");
                Console.WriteLine("GoAhead script.goa       : Execute script.goa");
                Console.WriteLine("GoAhead -shell           : Start GoAhead shell (interactive Command mode)");
                Console.WriteLine("GoAhead -command(s)      : Execute GoAhead commands (e.g GoAhead -command \"FixS6XDLBug XDLInFile=in.xdl XDLOutFile=out.xdl;\"");
            }

            // save settings
            StoredPreferences.SavePrefernces();
        }
        protected override void DoCommandAction()
        {
            string filePath = Process.GetCurrentProcess().MainModule.FileName;

            string dir      = Program.AssemblyDirectory;
            string hashFile = dir + Path.DirectorySeparatorChar + "GOA.hash";

            string oldHash = "";

            if (File.Exists(hashFile))
            {
                TextReader tr = new StreamReader(hashFile);
                oldHash = tr.ReadToEnd();
                tr.Close();
            }

            FileStream fs          = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            string     currentHash = HashFile(fs);

            fs.Close();

            TextWriter tw = new StreamWriter(hashFile, false);

            tw.Write(currentHash);
            tw.Close();

            string question = "You switched to a new GoAhead version. Delete the preferences " + StoredPreferences.GetPreferenceFileName() + "?";

            if (!oldHash.Equals(currentHash) || true)
            {
                switch (Action.ToUpper())
                {
                case "WARN":
                {
                    OutputManager.WriteOutput("Warning: You switched to a new GoAhead version. Make sure you delete your preferences file.");
                    break;
                }

                case "DEL":
                {
                    CreateBackupAndDelete();
                    break;
                }

                case "ASK":
                {
                    bool delete = false;
                    if (CommandExecuter.Instance.GUIActive)
                    {
                        DialogResult result = MessageBox.Show(question, "New version detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            delete = true;
                        }
                        else
                        {
                            delete = false;
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            Console.WriteLine(question + " (yes|no)");
                            string value = Console.ReadLine();
                            if (value.ToUpper().Equals("YES"))
                            {
                                delete = true;
                                break;
                            }
                            else if (value.ToUpper().Equals("NO"))
                            {
                                delete = false;
                                break;
                            }
                        }
                        ;
                    }
                    if (delete)
                    {
                        CreateBackupAndDelete();
                    }
                    break;
                }

                default:
                {
                    throw new ArgumentException("Invalid action specified. See parameter Action for valied values");
                }
                }
            }

            // reload settings
            StoredPreferences.LoadPrefernces();
        }