Exemple #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MainWindow()
        {
            // Get the application settings
            this.m_Settings = SettingsManager.read();
            if (!this.m_Settings.IsValid)
            {
                // Inform the user
                MessageBox.Show("ImarisSelector was not configured on this machine!\n" +
                    "Please contact your administrator.",
                    "Process Info",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                // Exit
                Environment.Exit(1);
            }

            // Instantiate the module manager
            this.m_ModuleManager = new ModuleManager(this.m_Settings);

            // Initialize the window components
            InitializeComponent();

            // Make window unresizable
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
        }
        /// <summary>
        /// Constructor.
        /// <param name="settings">Application settings (read from disk).</param>
        /// </summary>
        public ApplicationManager(Settings settings)
        {
            // Store the settings
            this.m_Settings = settings;

            // Initialize the Registry Manager
            this.m_RegistryManager = new RegistryManager(this.m_Settings.ImarisVersion);
        }
Exemple #3
0
        /// <summary>
        /// Constructor.
        /// <param name="settings">Application settings (read from disk).</param>
        /// </summary>
        public ModuleManager(Settings settings)
        {
            // Store the settings
            this.m_Settings = settings;

            // Build the catalog
            Build();

            // Initialize the Registry Manager
            this.m_RegistryManager = new RegistryManager(this.m_Settings.ImarisVersion);

            // Make sure the Imaris product is enabled
            EnableProducts(new List<String> { "Imaris" });
        }
Exemple #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MainWindow()
        {
            // Initialize the UI
            InitializeComponent();

            // Make window unresizable
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;

            // Get the application settings from the settings file.
            this.m_Settings = SettingsManager.read();
            if (this.m_Settings.isValid)
            {
                buttonImarisPath.Text = this.m_Settings.ImarisPath;

                // Fill in the list of products
                checkedListBoxProducts.Items.Clear();
                foreach (String productName in this.m_Settings.ProductsWithEnabledState.Keys)
                {
                    bool state;
                    if (this.m_Settings.ProductsWithEnabledState.ContainsKey(productName))
                    {
                        if (!this.m_Settings.ProductsWithEnabledState.TryGetValue(productName, out state))
                        {
                            state = true;
                        }
                    }
                    else
                    {
                        state = true;
                    }

                    // Add the product with the state read from the application settings
                    checkedListBoxProducts.Items.Add(productName, state);
                }

                // Enable save button
                this.buttonSave.Enabled = true;
            }
        }
Exemple #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MainWindow()
        {
            // Initialize the UI
            InitializeComponent();

            // Initialize timer for handling the state of the save button
            timer = new Timer();
            timer.Tick += new EventHandler(resetSaveButtonText);
            timer.Interval = 500;

            // Make window unresizable
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;

            // Get the application settings from the settings file.
            this.m_Settings = SettingsManager.read();
            if (this.m_Settings.IsValid)
            {
                // Check that the Imaris version stored in the file exists in
                // the registry. Otherwise inform the admin.
                RegistryManager manager = new RegistryManager(this.m_Settings.ImarisVersion);
                if (!manager.ImarisKeyExists())
                {
                    // Inform the user
                    MessageBox.Show(
                        "The Imaris version stored in the settings file does not have " +
                        "the corresponding registry entries. This probably means that " +
                        "the settings file is obsolete.\n\n" +
                        "It is highly recommended to choose current Imaris executable " +
                        "to manage and, if needed, reconfigure it.",
                        "Warning",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                // Display the Imaris path on the button
                buttonImarisPath.Text = this.m_Settings.ImarisPath;

                // Fill in the list of products
                checkedListBoxProducts.Items.Clear();
                foreach (String productName in this.m_Settings.ProductsWithEnabledState.Keys)
                {
                    bool state;
                    if (this.m_Settings.ProductsWithEnabledState.ContainsKey(productName))
                    {
                        if (!this.m_Settings.ProductsWithEnabledState.TryGetValue(productName, out state))
                        {
                            state = true;
                        }
                    }
                    else
                    {
                        state = true;
                    }

                    // Add the product with the state read from the application settings
                    checkedListBoxProducts.Items.Add(productName, state);
                }

                // Now set all other settings
                // TODO: Add all necessary checks

                // Texture cache
                if (this.m_Settings.TextureCache == -1)
                {
                    numericTextureCache.Text = "";
                }
                else
                {
                    numericTextureCache.Value = this.m_Settings.TextureCache;
                }

                // Data cache
                if (this.m_Settings.DataCache == -1)
                {
                    numericDataCache.Text = "";
                }
                else
                {
                    numericDataCache.Value = this.m_Settings.DataCache;
                }

                // Data cache file paths
                if (!this.m_Settings.DataBlockCachingFilePath.Equals(""))
                {
                    String[] dataBlockCachingFilePathArray = this.m_Settings.DataBlockCachingFilePath.Split(';');
                    listCLFileCachePaths.Items.Clear();
                    foreach (String d in dataBlockCachingFilePathArray)
                    {
                        if (!d.Equals(""))
                        {
                            listCLFileCachePaths.Items.Add(d);
                        }
                    }
                }

                // XT folder paths
                if (!this.m_Settings.XTFolderPath.Equals(""))
                {
                    String[] xtFolderPathArray = this.m_Settings.XTFolderPath.Split(';');
                    listCTXTPaths.Items.Clear();
                    foreach (String x in xtFolderPathArray)
                    {
                        if (!x.Equals(""))
                        {
                            listCTXTPaths.Items.Add(x);
                        }
                    }
                }

                // Python path
                if (!this.m_Settings.PythonPath.Equals(""))
                {
                    buttonCTAddPythonPath.Text = this.m_Settings.PythonPath;
                }

                // Fiji path
                if (!this.m_Settings.FijiPath.Equals(""))
                {
                    buttonCTAddFijiPath.Text = this.m_Settings.FijiPath;
                }

                // Enable save button
                this.buttonSave.Enabled = true;
            }
        }
        /// <summary>
        /// Set the application settings to the settings file.
        /// </summary>
        /// <param name="settings">A Settings object with the settings to write to disk.</param>
        /// <returns>True if the settings could be saved to disk, false otherwise.</returns>
        public static bool write(Settings settings)
        {
            // We put the whole writing block in a try...catch block
            try
            {

                // Make sure the settings directory exists
                CreateSettingsDirIfNeeded(SettingsDirectoryName());

                // Write the settings to file
                StreamWriter file = new StreamWriter(settingsFullFileName());
                if (file != null)
                {
                    file.WriteLine("FileVersion=ImarisSelector Settings File version 2");
                    file.WriteLine("ImarisVersion=" + settings.ImarisVersion);
                    file.WriteLine("ImarisPath=" + settings.ImarisPath);
                    file.WriteLine("TextureCache=" + settings.TextureCache);
                    file.WriteLine("DataCache=" + settings.DataCache);
                    file.WriteLine("DataBlockCachingFilePath=" + settings.DataBlockCachingFilePath);
                    file.WriteLine("XTFolderPath=" + settings.XTFolderPath);
                    file.WriteLine("PythonPath=" + settings.PythonPath);
                    file.WriteLine("FijiPath=" + settings.FijiPath);
                    foreach (KeyValuePair<String, bool> entry in settings.ProductsWithEnabledState)
                    {
                        String state = "false";
                        if (entry.Value == true)
                        {
                            state = "true";
                        }
                        file.WriteLine(entry.Key + "=" + state);
                    }
                    file.Close();

                    // Success
                    return true;
                }
                else
                {
                    // Failure
                    return false;
                }
            }
            catch
            {
                // Could not write to disk!
                return false;
            }
        }
        /// <summary>
        /// Get the ImarisSelector settings from the settings file.
        /// </summary>
        /// <returns>A Settings object with the loaded settings.</returns>
        public static Settings read()
        {
            // Initialize output
            Settings settings = new Settings();

            // Does the settings file exist?
            if (File.Exists(settingsFullFileName()))
            {
                // Read the settings file
                // First line is the header, the second is ImarisVersion, the third is ImarisPath
                StreamReader file = new System.IO.StreamReader(settingsFullFileName());
                if (file != null)
                {
                    String line;
                    while ((line = file.ReadLine()) != null)
                    {
                        // Get the line key and value
                        String[] parts = line.Split('=');

                        if (parts.Length != 2)
                        {
                            continue;
                        }

                        // FileVersion is the first entry in the file
                        if (parts[0].Equals("FileVersion"))
                        {
                            String fileVersion = parts[1];
                            bool isNewest = false;
                            bool isCompatible = false;
                            IsNewestVersion(fileVersion, out isNewest, out isCompatible);

                            if (!isNewest & !isCompatible)
                            {
                                // Invalid settings file version - ignore the file
                                return new Settings();
                            }
                        }
                        else if (parts[0].Equals("ImarisVersion"))
                        {
                            // Make sure the Imaris version is supported. This is some additional safety
                            // for those administrators who tried ImarisSelector 1.0.0 on Imaris 8 and
                            //  managed to create a settings file. This is no longer possible.
                            Match match = Regex.Match(parts[1],
                                @"(Imaris)\s*(x64)*\s*(\d{1,2}).(\d{1,2})(.\d{1,2})*",
                                RegexOptions.IgnoreCase);

                            int major = -1;
                            if (!match.Success)
                            {
                                // Set ImarisVersion to an invalid entry
                                settings.ImarisVersion = "";

                            }
                            else
                            {
                                // Get the major version as an integer
                                major = Convert.ToInt32(match.Groups[3].Value);

                                // Test for support
                                if (major > 7)
                                {
                                    // Set ImarisVersion to an invalid entry
                                    settings.ImarisVersion = "";
                                }
                                else
                                {
                                    // This is valid
                                    settings.ImarisVersion = parts[1];
                                }
                            }
                        }
                        else if (parts[0].Equals("ImarisPath"))
                        {
                            settings.ImarisPath = parts[1];
                        }
                        else if (parts[0].Equals("TextureCache"))
                        {
                            settings.TextureCache = int.Parse(parts[1]);
                        }
                        else if (parts[0].Equals("DataCache"))
                        {
                            settings.DataCache = int.Parse(parts[1]);
                        }
                        else if (parts[0].Equals("DataBlockCachingFilePath"))
                        {
                            settings.DataBlockCachingFilePath = parts[1];
                        }
                        else if (parts[0].Equals("XTFolderPath"))
                        {
                            settings.XTFolderPath = parts[1];
                        }
                        else if (parts[0].Equals("PythonPath"))
                        {
                            settings.PythonPath = parts[1];
                        }
                        else if (parts[0].Equals("FijiPath"))
                        {
                            settings.FijiPath = parts[1];
                        }
                        else
                        {
                            settings.ProductsWithEnabledState.Add(parts[0], parts[1].Equals("true"));
                        }
                    }
                    file.Close();
                }
            }

            // Now check (not all settings are mandatory)
            if (!settings.ImarisVersion.Equals("") && !settings.ImarisPath.Equals("") &&
                settings.ProductsWithEnabledState.Count > 0)
            {
                settings.IsValid = true;
            }
            else
            {
                settings.IsValid = false;
            }

            // Return the settings
            return settings;
        }
        /// <summary>
        /// Get the ImarisSelector settings from the settings file.
        /// </summary>
        /// <returns>A Settings object with the loaded settings.</returns>
        public static Settings read()
        {
            // Initialize output
            Settings settings = new Settings();

            // Does the settings file exist?
            if (File.Exists(settingsFullFileName()))
            {
                // Read the settings file
                // First line is the header, the second is ImarisVersion, the third is ImarisPath
                StreamReader file = new System.IO.StreamReader(settingsFullFileName());
                if (file != null)
                {
                    String line;
                    while ((line = file.ReadLine()) != null)
                    {
                        // Get the line key and value
                        String[] parts = line.Split('=');

                        if (parts.Length != 2)
                        {
                            continue;
                        }

                        if (parts[0].Equals("FileVersion"))
                        {
                            if (!parts[1].Equals("ImarisSelector Settings File version 1.0.0"))
                            {
                                // Invalid settings file version - ignore the file
                                return new Settings();
                            }
                        }
                        else if (parts[0].Equals("ImarisVersion"))
                        {
                            settings.ImarisVersion = parts[1];
                        }
                        else if (parts[0].Equals("ImarisPath"))
                        {
                            settings.ImarisPath = parts[1];
                        }
                        else
                        {
                            settings.ProductsWithEnabledState.Add(parts[0], parts[1].Equals("true"));
                        }
                    }
                    file.Close();
                }
            }

            // Now check
            if (!settings.ImarisVersion.Equals("") && !settings.ImarisPath.Equals("") &&
                settings.ProductsWithEnabledState.Count > 0)
            {
                settings.isValid = true;
            }
            else
            {
                settings.isValid = false;
            }

            // Return the settings
            return settings;
        }