Esempio n. 1
0
 private void RegistryInit()
 {
     theKey               = Registry.LocalMachine.CreateSubKey(@"Software\EarLab");
     theRunfileName       = new RegistryString(theKey, "RunfileName", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), @"EarLab\runfile.xml"));
     mApplicationKey      = Registry.CurrentUser.CreateSubKey(@"Software\EarLab\EarLab GUI");
     mEnableSuperuserMode = new RegistryBool(mApplicationKey, "SuperuserMode", false);
 }
Esempio n. 2
0
        public Form1(string [] args)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            mModuleKey           = Registry.LocalMachine.CreateSubKey(@"Software\EarLab");
            mApplicationKey      = Registry.CurrentUser.CreateSubKey(@"Software\EarLab\EarLab GUI");
            mLogCallback         = new LogCallback(LogCallback);
            mModuleDirectory     = new RegistryString(mModuleKey, "ModulesPath", @"C:\Program Files\EarLab\Modules");
            mInputDirectory      = new RegistryString(mApplicationKey, "InputDirectory", System.Environment.ExpandEnvironmentVariables("%USERPROFILE%") + @"\My Documents\EarLab\Signals");
            mOutputDirectory     = new RegistryString(mApplicationKey, "OutputDirectory", System.Environment.ExpandEnvironmentVariables("%USERPROFILE%") + @"\My Documents\EarLab\Output");
            mDiagramFile         = new RegistryString(mApplicationKey, "RunParameterFile", null);
            mParameterFile       = new RegistryString(mApplicationKey, "ModuleParameterFile", null);
            mFrameCount          = new RegistryInt(mApplicationKey, "FrameCount", 0);
            mEnableSuperuserMode = new RegistryBool(mApplicationKey, "SuperuserMode", false);
            udFrameCount.Value   = mFrameCount.Value;

            mWindowState     = new RegistryFormWindowState(mApplicationKey, "WindowState", FormWindowState.Normal);
            mWindowLocation  = new RegistryPoint(mApplicationKey, "WindowLocation", this.Location);
            mWindowSize      = new RegistrySize(mApplicationKey, "WindowSize", this.MinimumSize);
            this.Location    = mWindowLocation.Value;
            this.Size        = mWindowSize.Value;
            this.WindowState = mWindowState.Value;

            if (mEnableSuperuserMode.Value)
            {
                menuEnvironment.Enabled        = true;
                menuEnvironment.Visible        = true;
                menuFileOpenDiagram.Enabled    = true;
                menuFileOpenDiagram.Visible    = true;
                menuFileOpenParameters.Enabled = true;
                menuFileOpenParameters.Visible = true;
                menuFileSeparator.Enabled      = true;
                menuFileSeparator.Visible      = true;
            }

            if (args.Length > 0)
            {
                bool dashN = false;                     // -n <FrameCount>
                bool dashI = false;                     // -i <InputDirectory>
                bool dashO = false;                     // -o <OutputDirectory>
                bool DiagramFileSpecified   = false;
                bool ParameterFileSpecified = false;
                RunningFromCommandLineInput = false;
                try
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        switch (args[i])
                        {
                        case "-n":
                            try
                            {
                                FrameCount = int.Parse(args[++i]);
                                dashN      = true;
                            }
                            catch (FormatException)
                            {
                                throw new ApplicationException("Frame count (-n) must be a non-zero positive integer.  \"" + args[i] + "\" is invalid");
                            }
                            break;

                        case "-m":
                            ModuleDirectory = args[++i];
                            break;

                        case "-i":
                            InputDirectory = args[++i];
                            dashI          = true;
                            break;

                        case "-o":
                            OutputDirectory = args[++i];
                            dashO           = true;
                            break;

                        case "-l":
                            LoadAndWait = true;
                            break;

                        default:
                            if (!DiagramFileSpecified)
                            {
                                DiagramFile          = args[i];
                                DiagramFileSpecified = true;
                            }
                            else
                            {
                                if (!ParameterFileSpecified)
                                {
                                    ParameterFile          = args[i];
                                    ParameterFileSpecified = true;
                                }
                                else
                                {
                                    throw new ApplicationException("Too many parameters specified");
                                }
                            }
                            break;
                        }                 // switch
                    }                     // for
                    if (dashN && dashI && dashO && DiagramFileSpecified && ParameterFileSpecified)
                    {
                        RunningFromCommandLineInput = true;
                    }
                }                 // try
                catch (ApplicationException e)
                {
                    string Message;
                    Message  = e.Message + "\n";
                    Message += "Usage: EarLabGUI -n <NumFrames> [-m <ModuleDirectory>] [-i <InputDirectory>] [-o <OutputDirectory>]\n";
                    Message += "                                        <DiagramFile> <ParameterFile>\n";
                    Message += "\n";
                    Message += "Where: <NumFrames> is a positive integer which is the number of frames over\n";
                    Message += "                   which the simulation will be run\n";
                    Message += "       <ModuleDirectory> is a directory path that contains the module executables\n";
                    Message += "                       that will be used for this simulation.  If this option is not provided,\n";
                    Message += "                       the module directory defaults to the directory into which EarLab was installed.\n";
                    Message += "       <InputDirectory> is a directory path that contains the input files for the model.\n";
                    Message += "       <OutputDirectory> is a directory path that will contain the output files produced by the model.\n";
                    Message += "       <DiagramFile> is a file that describes an Earlab model\n";
                    Message += "       <ParameterFile> is a parameter file that contains parameter definitions\n";
                    Message += "                       for all modules specified by the <DiagramFile>.\n";
                    System.Windows.Forms.MessageBox.Show(Message);
                }
            }
            else
            {
                RunningFromCommandLineInput = false;
            }

            if (LoadAndWait)
            {
                RunningFromCommandLineInput = false;
            }

            udFrameCount.Focus();

            UpdateStatusDisplay();
            if (RunningFromCommandLineInput)
            {
                timerCommandlineRun.Enabled = true;
            }
        }
Esempio n. 3
0
        public Form1(string [] args)
        {
            try
            {
                mMainForm        = this;
                mModuleKey       = Registry.CurrentUser.CreateSubKey(@"Software\EarLab");
                mApplicationKey  = Registry.CurrentUser.CreateSubKey(@"Software\EarLab\EarLab GUI");
                mLogCallback     = new LogCallback(LogCallback);
                mModuleDirectory = new RegistryString(mModuleKey, "ModulesPath", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"EarLab\Modules"));
                if (!Directory.Exists(mModuleDirectory.Value))
                {
                    mModuleDirectory.Value = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"EarLab\Modules");
                    if (!Directory.Exists(mModuleDirectory.Value))
                    {
                        MessageBox.Show(@"Module directory not found", @"Simulator error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                mInputDirectory  = new RegistryString(mApplicationKey, "InputDirectory", System.Environment.ExpandEnvironmentVariables("%USERPROFILE%") + @"\My Documents\EarLab\Signals");
                mOutputDirectory = new RegistryString(mApplicationKey, "OutputDirectory", System.Environment.ExpandEnvironmentVariables("%USERPROFILE%") + @"\My Documents\EarLab\Output");
                mDiagramFile     = new RegistryString(mApplicationKey, "RunParameterFile", null);
                mParameterFile   = new RegistryString(mApplicationKey, "ModuleParameterFile", null);
                mFrameCount      = new RegistryInt(mApplicationKey, "FrameCount", 1);
#if DEBUG
                mEnableSuperuserMode = new RegistryBool(mApplicationKey, "SuperuserMode", true);
#else
                mEnableSuperuserMode = new RegistryBool(mApplicationKey, "SuperuserMode", false);
#endif
                mWindowState    = new RegistryFormWindowState(mApplicationKey, "WindowState", FormWindowState.Normal);
                mWindowLocation = new RegistryPoint(mApplicationKey, "WindowLocation", this.Location);
                mWindowSize     = new RegistrySize(mApplicationKey, "WindowSize", this.MinimumSize);
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception caught while creating application registry keys: " + e.ToString());
            }

            try
            {
                InitializeComponent();
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception caught during call to InitializeComponent: " + e.ToString());
            }

            udFrameCount.Value = mFrameCount.Value;

            this.Location    = mWindowLocation.Value;
            this.Size        = mWindowSize.Value;
            this.WindowState = mWindowState.Value;
            CheckForIllegalCrossThreadCalls = false;

            if (mEnableSuperuserMode.Value)
            {
                menuEnvironment.Enabled        = true;
                menuEnvironment.Visible        = true;
                menuFileOpenDiagram.Enabled    = true;
                menuFileOpenDiagram.Visible    = true;
                menuFileOpenParameters.Enabled = true;
                menuFileOpenParameters.Visible = true;
                menuFileSeparator.Enabled      = true;
                menuFileSeparator.Visible      = true;
            }
            else
            {
                menuEnvironment.Enabled        = false;
                menuEnvironment.Visible        = false;
                menuFileOpenDiagram.Enabled    = false;
                menuFileOpenDiagram.Visible    = false;
                menuFileOpenParameters.Enabled = false;
                menuFileOpenParameters.Visible = false;
                menuFileSeparator.Enabled      = false;
                menuFileSeparator.Visible      = false;
            }

            if ((args != null) && (args.Length > 0))
            {
                if (args.Length == 1)
                {
                    // This should be a file name for us to open and parse
                    ReadSimulationFile(args[0]);
                }
                else
                {
                    bool dashN = false; // -n <FrameCount>
                    bool dashI = false; // -i <InputDirectory>
                    bool dashO = false; // -o <OutputDirectory>
                    bool DiagramFileSpecified   = false;
                    bool ParameterFileSpecified = false;
                    RunningFromCommandLineInput = false;
                    try
                    {
                        for (int i = 0; i < args.Length; i++)
                        {
                            switch (args[i])
                            {
                            case "-n":
                                try
                                {
                                    FrameCount = int.Parse(args[++i]);
                                    dashN      = true;
                                }
                                catch (FormatException)
                                {
                                    throw new ApplicationException("Frame count (-n) must be a non-zero positive integer.  \"" + args[i] + "\" is invalid");
                                }
                                break;

                            case "-m":
                                ModuleDirectory = args[++i];
                                break;

                            case "-i":
                                InputDirectory = args[++i];
                                dashI          = true;
                                break;

                            case "-o":
                                OutputDirectory = args[++i];
                                dashO           = true;
                                break;

                            case "-l":
                                LoadAndWait = true;
                                break;

                            default:
                                if (!DiagramFileSpecified)
                                {
                                    DiagramFile          = args[i];
                                    DiagramFileSpecified = true;
                                }
                                else
                                {
                                    if (!ParameterFileSpecified)
                                    {
                                        ParameterFile          = args[i];
                                        ParameterFileSpecified = true;
                                    }
                                    else
                                    {
                                        throw new ApplicationException("Too many parameters specified");
                                    }
                                }
                                break;
                            } // switch
                        }     // for
                        if (dashN && dashI && dashO && DiagramFileSpecified && ParameterFileSpecified)
                        {
                            RunningFromCommandLineInput = true;
                        }
                    } // try
                    catch (ApplicationException e)
                    {
                        string Message;
                        Message  = e.Message + "\n";
                        Message += "Usage: EarLabGUI -n <NumFrames> [-m <ModuleDirectory>] [-i <InputDirectory>] [-o <OutputDirectory>]\n";
                        Message += "                                        <DiagramFile> <ParameterFile>\n";
                        Message += "\n";
                        Message += "Where: <NumFrames> is a positive integer which is the number of frames over\n";
                        Message += "                   which the simulation will be run\n";
                        Message += "       <ModuleDirectory> is a directory path that contains the module executables\n";
                        Message += "                       that will be used for this simulation.  If this option is not provided,\n";
                        Message += "                       the module directory defaults to the directory into which EarLab was installed.\n";
                        Message += "       <InputDirectory> is a directory path that contains the input files for the model.\n";
                        Message += "       <OutputDirectory> is a directory path that will contain the output files produced by the model.\n";
                        Message += "       <DiagramFile> is a file that describes an Earlab model\n";
                        Message += "       <ParameterFile> is a parameter file that contains parameter definitions\n";
                        Message += "                       for all modules specified by the <DiagramFile>.\n";
                        System.Windows.Forms.MessageBox.Show(Message);
                    }
                }
            }
            else
            {
                RunningFromCommandLineInput = false;
            }

            if (LoadAndWait)
            {
                RunningFromCommandLineInput = false;
            }

            udFrameCount.Focus();

            UpdateStatusDisplay();
            if (RunningFromCommandLineInput)
            {
                timerCommandlineRun.Enabled = true;
            }
        }
Esempio n. 4
0
        private void RegistryInit()
        {
            try
            {
                theKey               = null;
                theRunfileName       = null;
                mApplicationKey      = null;
                mEnableSuperuserMode = null;
                theKey               = Registry.CurrentUser.CreateSubKey(@"Software\EarLab");
                theRunfileName       = new RegistryString(theKey, "RunfileName", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"EarLab\runfile.xml"));
                mApplicationKey      = Registry.CurrentUser.CreateSubKey(@"Software\EarLab\EarLab GUI");
                mEnableSuperuserMode = new RegistryBool(mApplicationKey, "SuperuserMode", false);
            }
            catch
            {
            }
            if ((theRunfileName == null) || (theRunfileName.Value == null) || (theRunfileName.Value.Length == 0))
            {
                RunFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"EarLab\runfile.xml");
            }
            else
            {
                RunFileName = theRunfileName.Value;
            }

            if (!File.Exists(RunFileName))
            {
                xDirectory Copier = new xDirectory();
                string     source = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"EarLab\Models");
                string     dest   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"EarLab");

                if (!Directory.Exists(source))
                {
                    MessageBox.Show("Cannot locate common sample experiment source in \"" + source + "\".  Exiting.");
                    Application.Exit();
                    return;
                }
                if (!Directory.Exists(dest))
                {
                    Directory.CreateDirectory(dest);
                }

                Copier.Source       = new DirectoryInfo(source);
                Copier.Destination  = new DirectoryInfo(dest);
                Copier.Overwrite    = true;
                Copier.FolderFilter = "*";
                Copier.FileFilters.Add("*.*");
                bCopyCompleted = false;
                Copier.StartCopy();
                Copier.CopyComplete += new CopyCompleteEventHandler(Copier_CopyComplete);
                while (!bCopyCompleted)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
            if (!File.Exists(RunFileName))
            {
                MessageBox.Show("Required ExperimentManager run file \"" + RunFile + "\" not found.  It may be necessary to reinstall EarLab before continuing.");
                Application.Exit();
                return;
            }
            RunFile = RunFileName;
        }