Beispiel #1
0
 public static FontAutoDownloadManager GetInstance()
 {
     if (instance == null)
     {
         instance = new FontAutoDownloadManager();
     }
     return(instance);
 }
        /// <summary>
        /// Select the given laser equipment, change the registry values needed to handle this
        /// </summary>
        /// <param name="equipmentName">Name of the laser equipment</param>
        public void SelectLaserEquipment(string equipmentName)
        {
            List <LaserEquipment> list      = manager.LaserEquipmentList;
            LaserEquipment        equipment = null;

            foreach (LaserEquipment item in list)
            {
                if (item.Name == equipmentName)
                {
                    equipment = item;
                }
            }
            if (equipment != null)
            {
                //Declare objects
                RegistryKey regBase     = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
                RegistryKey globalPrefs = regBase.OpenSubKey(REGISTRY_PATH + GLOBAL_PREFS_REGISTRY_KEY, true);
                try
                {
                    regBase.CreateSubKey(REGISTRY_PATH + DSP_PARAMETERS_REGISTRY_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree);
                }
                catch { }
                RegistryKey dspParam = regBase.OpenSubKey(REGISTRY_PATH + DSP_PARAMETERS_REGISTRY_KEY, true);
                try
                {
                    regBase.CreateSubKey(REGISTRY_PATH + MRU_REGISTRY_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree);
                }
                catch { }
                RegistryKey mru         = regBase.OpenSubKey(REGISTRY_PATH + MRU_REGISTRY_KEY, true);
                RegistryKey fontAuto    = regBase.OpenSubKey(REGISTRY_PATH + FONT_AUTO_DOWNLOAD_REGISTRY_KEY, true);
                RegistryKey scribaKey   = regBase.OpenSubKey(REGISTRY_PATH + SCRIBA_KEY);
                RegistryKey iniFilesKey = regBase.OpenSubKey(REGISTRY_PATH + INI_FILE_LOCATION_KEY, true);
                string      installDir  = scribaKey.GetValue(INSTALL_DIR_KEY).ToString();
                string      markIniFile = iniFilesKey.GetValue(MARK_INI_FILE_KEY).ToString();

                //Close the program if open
                Process[] processes = Process.GetProcessesByName(PROCESS_NAME);
                if (processes.Count() > 0)
                {
                    processes[0].Kill();
                }

                //Copy dsp settings
                if (File.Exists(equipment.DspFile))
                {
                    string[] files = Directory.GetFiles(Path.Combine(installDir, DSP_PARAMETERS_FOLDER));
                    foreach (string file in files)
                    {
                        File.Delete(file);
                    }
                    File.Copy(equipment.DspFile, Path.Combine(installDir, DSP_PARAMETERS_FOLDER, Path.GetFileName(equipment.DspFile)), true);
                }

                //Write values in registry
                globalPrefs.SetValue(ETHERNET_IP_KEY, equipment.Ip);
                globalPrefs.SetValue(COMM_PORT_KEY, 12);
                globalPrefs.SetValue(ETHERNET_PORT_KEY, 4000);
                dspParam.SetValue(LAST_USED_KEY, equipment.Dsp);
                mru.SetValue(MRU_1_KEY, equipment.Mru1);
                mru.SetValue(MRU_2_KEY, equipment.Mru2);
                mru.SetValue(MRU_3_KEY, equipment.Mru3);
                mru.SetValue(MRU_4_KEY, equipment.Mru4);
                mru.SetValue(MRU_5_KEY, equipment.Mru5);
                mru.SetValue(MRU_6_KEY, equipment.Mru6);
                mru.SetValue(MRU_7_KEY, equipment.Mru7);
                mru.SetValue(MRU_8_KEY, equipment.Mru8);
                mru.SetValue(MRU_9_KEY, equipment.Mru9);

                //Update font autodownload settings
                List <string> fonts = FontAutoDownloadManager.GetInstance().Fonts;
                fontAuto.SetValue(NUM_FONTS_KEY, fonts.Count());
                int count = 1;
                foreach (string font in fonts)
                {
                    fontAuto.SetValue(FONT_CHECKED_KEY + count.ToString(), 1);
                    fontAuto.SetValue(FONT_TO_DOWNLOAD_KEY + count.ToString(), font);
                    count++;
                }

                //Update lens setup
                if (File.Exists(settings.MarkerIniFileSource))
                {
                    File.Copy(settings.MarkerIniFileSource, markIniFile, true);
                    MarkerIniFile iniFile = new MarkerIniFile(markIniFile);
                    iniFile.LoadLensSetups();
                    List <LensSetup> lensSetups = iniFile.LensSetups;
                    foreach (LensSetup setup in lensSetups)
                    {
                        if (setup.Name == equipment.Lens)
                        {
                            setup.LensAmplitude = float.Parse(equipment.LensAmp);
                            setup.XCompensation = float.Parse(equipment.XCompensation);
                            setup.YCompensation = float.Parse(equipment.YCompensation);
                            iniFile.SetSetupSelected(setup);
                        }
                    }
                }

                //Open program
                Process.Start(new ProcessStartInfo(Path.Combine(installDir, PROCESS_FILE)));
            }
        }