コード例 #1
0
ファイル: clsOptions.cs プロジェクト: squall255/chummer5a
        static GlobalOptions()
        {
            if (Utils.IsRunningInVisualStudio())
            {
                return;
            }

            _objBaseChummerKey = Registry.CurrentUser.CreateSubKey("Software\\Chummer5");
            if (_objBaseChummerKey == null)
            {
                return;
            }

            string settingsDirectoryPath = Path.Combine(Application.StartupPath, "settings");

            if (!Directory.Exists(settingsDirectoryPath))
            {
                try
                {
                    Directory.CreateDirectory(settingsDirectoryPath);
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_Insufficient_Permissions_Warning"));
                }
            }

            // Automatic Update.
            LoadBoolFromRegistry(ref _blnAutomaticUpdate, "autoupdate");

            LoadBoolFromRegistry(ref _blnLiveCustomData, "livecustomdata");

            LoadBoolFromRegistry(ref _lifeModuleEnabled, "lifemodule");

            LoadBoolFromRegistry(ref _omaeEnabled, "omaeenabled");

            // Whether or not the app should only download localised files in the user's selected language.
            LoadBoolFromRegistry(ref _blnLocalisedUpdatesOnly, "localisedupdatesonly");

            // Whether or not the app should use logging.
            LoadBoolFromRegistry(ref _blnUseLogging, "uselogging");

            // Whether or not dates should include the time.
            LoadBoolFromRegistry(ref _blnDatesIncludeTime, "datesincludetime");

            LoadBoolFromRegistry(ref _blnMissionsOnly, "missionsonly");

            LoadBoolFromRegistry(ref _blnDronemods, "dronemods");

            LoadBoolFromRegistry(ref _blnDronemodsMaximumPilot, "dronemodsPilot");

            // Whether or not printouts should be sent to a file before loading them in the browser. This is a fix for getting printing to work properly on Linux using Wine.
            LoadBoolFromRegistry(ref _blnPrintToFileFirst, "printtofilefirst");

            // Default character sheet.
            LoadStringFromRegistry(ref _strDefaultCharacterSheet, "defaultsheet");

            // Omae Settings.
            // Username.
            LoadStringFromRegistry(ref _strOmaeUserName, "omaeusername");
            // Password.
            LoadStringFromRegistry(ref _strOmaePassword, "omaepassword");
            // AutoLogin.
            LoadBoolFromRegistry(ref _blnOmaeAutoLogin, "omaeautologin");
            // Language.
            LoadStringFromRegistry(ref _strLanguage, "language");
            if (_strLanguage == "en-us2")
            {
                _strLanguage = "en-us";
            }
            // Startup in Fullscreen mode.
            LoadBoolFromRegistry(ref _blnStartupFullscreen, "startupfullscreen");
            // Single instace of the Dice Roller window.
            LoadBoolFromRegistry(ref _blnSingleDiceRoller, "singlediceroller");

            // Open PDFs as URLs. For use with Chrome, Firefox, etc.
            LoadStringFromRegistry(ref _strPDFParameters, "pdfparameters");

            // PDF application path.
            LoadStringFromRegistry(ref _strPDFAppPath, "pdfapppath");

            // Folder path to check for characters.
            LoadStringFromRegistry(ref _strCharacterRosterPath, "characterrosterpath");

            // Prefer Nightly Updates.
            LoadBoolFromRegistry(ref _blnPreferNightlyUpdates, "prefernightlybuilds");

            // Retrieve CustomDataDirectoryInfo objects
            bool        blnPopulatefromCustomDataFolder = true;
            RegistryKey objCustomDataDirectoryKey       = _objBaseChummerKey.OpenSubKey("CustomDataDirectory");

            if (objCustomDataDirectoryKey != null)
            {
                // If the subkey is empty and not just filled with invalid paths, do not re-check customdata folder
                blnPopulatefromCustomDataFolder = objCustomDataDirectoryKey.SubKeyCount > 0;
                List <KeyValuePair <CustomDataDirectoryInfo, int> > lstUnorderedCustomDataDirectories = new List <KeyValuePair <CustomDataDirectoryInfo, int> > (objCustomDataDirectoryKey.SubKeyCount);

                string[] astrCustomDataDirectoryNames = objCustomDataDirectoryKey.GetSubKeyNames();
                int      intMinLoadOrderValue         = int.MaxValue;
                int      intMaxLoadOrderValue         = int.MinValue;
                for (int i = 0; i < astrCustomDataDirectoryNames.Count(); ++i)
                {
                    RegistryKey objLoopKey        = objCustomDataDirectoryKey.OpenSubKey(astrCustomDataDirectoryNames[i]);
                    string      strPath           = string.Empty;
                    object      objRegistryResult = objLoopKey.GetValue("Path");
                    if (objRegistryResult != null)
                    {
                        strPath = objRegistryResult.ToString();
                    }
                    if (!string.IsNullOrEmpty(strPath) && Directory.Exists(strPath))
                    {
                        CustomDataDirectoryInfo objCustomDataDirectory = new CustomDataDirectoryInfo();
                        objCustomDataDirectory.Name = astrCustomDataDirectoryNames[i];
                        objCustomDataDirectory.Path = strPath;
                        objRegistryResult           = objLoopKey.GetValue("Enabled");
                        if (objRegistryResult != null)
                        {
                            bool blnTemp;
                            if (bool.TryParse(objRegistryResult.ToString(), out blnTemp))
                            {
                                objCustomDataDirectory.Enabled = blnTemp;
                            }
                        }
                        int intLoadOrder = 0;
                        objRegistryResult = objLoopKey.GetValue("LoadOrder");
                        if (objRegistryResult != null && int.TryParse(objRegistryResult.ToString(), out intLoadOrder))
                        {
                            // First load the infos alongside their load orders into a list whose order we don't care about
                            intMaxLoadOrderValue = Math.Max(intMaxLoadOrderValue, intLoadOrder);
                            intMinLoadOrderValue = Math.Min(intMinLoadOrderValue, intLoadOrder);
                            lstUnorderedCustomDataDirectories.Add(new KeyValuePair <CustomDataDirectoryInfo, int>(objCustomDataDirectory, intLoadOrder));
                        }
                        else
                        {
                            lstUnorderedCustomDataDirectories.Add(new KeyValuePair <CustomDataDirectoryInfo, int>(objCustomDataDirectory, int.MinValue));
                        }
                        blnPopulatefromCustomDataFolder = false;
                    }
                }

                // Now translate the list of infos whose order we don't care about into the list where we do care about the order of infos
                for (int i = intMinLoadOrderValue; i <= intMaxLoadOrderValue; ++i)
                {
                    KeyValuePair <CustomDataDirectoryInfo, int> objLoopPair = lstUnorderedCustomDataDirectories.FirstOrDefault(x => x.Value == i);
                    if (!objLoopPair.Equals(default(KeyValuePair <CustomDataDirectoryInfo, int>)))
                    {
                        _lstCustomDataDirectoryInfo.Add(objLoopPair.Key);
                    }
                }
                foreach (KeyValuePair <CustomDataDirectoryInfo, int> objLoopPair in lstUnorderedCustomDataDirectories.Where(x => x.Value == int.MinValue))
                {
                    _lstCustomDataDirectoryInfo.Add(objLoopPair.Key);
                }
            }
            // First run of Chummer5 with custom data directory info, populate based on folders in customdata
            if (blnPopulatefromCustomDataFolder)
            {
                string strCustomDataRootPath = Path.Combine(Application.StartupPath, "customdata");
                if (Directory.Exists(strCustomDataRootPath))
                {
                    foreach (string strLoopDirectoryPath in Directory.GetDirectories(strCustomDataRootPath))
                    {
                        CustomDataDirectoryInfo objCustomDataDirectory = new CustomDataDirectoryInfo();
                        objCustomDataDirectory.Name = Path.GetFileName(strLoopDirectoryPath);
                        objCustomDataDirectory.Path = strLoopDirectoryPath;
                        _lstCustomDataDirectoryInfo.Add(objCustomDataDirectory);
                    }
                }
            }

            // Retrieve the SourcebookInfo objects.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("books.xml");

            foreach (XmlNode objXmlBook in objXmlDocument.SelectNodes("/chummer/books/book"))
            {
                if (objXmlBook["code"] != null && objXmlBook["hide"] == null)
                {
                    SourcebookInfo objSource = new SourcebookInfo();
                    objSource.Code = objXmlBook["code"].InnerText;
                    string strTemp = string.Empty;

                    try
                    {
                        LoadStringFromRegistry(ref strTemp, objXmlBook["code"].InnerText, "Sourcebook");
                        if (!string.IsNullOrEmpty(strTemp))
                        {
                            string[] strParts = strTemp.Split('|');
                            objSource.Path = strParts[0];
                            if (strParts.Length > 1)
                            {
                                int intTmp;
                                if (int.TryParse(strParts[1], out intTmp))
                                {
                                    objSource.Offset = intTmp;
                                }
                            }
                        }
                        _lstSourcebookInfo.Add(objSource);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            CyberwareGrades.LoadList(Improvement.ImprovementSource.Cyberware);
            BiowareGrades.LoadList(Improvement.ImprovementSource.Bioware);
        }
コード例 #2
0
        static GlobalOptions()
        {
            if (Utils.IsRunningInVisualStudio)
            {
                return;
            }

            _objBaseChummerKey = Registry.CurrentUser.CreateSubKey("Software\\Chummer5");
            if (_objBaseChummerKey == null)
            {
                return;
            }
            _objBaseChummerKey.CreateSubKey("Sourcebook");

            string settingsDirectoryPath = Path.Combine(Application.StartupPath, "settings");

            if (!Directory.Exists(settingsDirectoryPath))
            {
                try
                {
                    Directory.CreateDirectory(settingsDirectoryPath);
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show(LanguageManager.GetString("Message_Insufficient_Permissions_Warning", GlobalOptions.Language));
                }
            }

            // Automatic Update.
            LoadBoolFromRegistry(ref _blnAutomaticUpdate, "autoupdate");

            LoadBoolFromRegistry(ref _blnLiveCustomData, "livecustomdata");

            LoadBoolFromRegistry(ref _blnLiveUpdateCleanCharacterFiles, "liveupdatecleancharacterfiles");

            LoadBoolFromRegistry(ref _lifeModuleEnabled, "lifemodule");

            LoadBoolFromRegistry(ref _omaeEnabled, "omaeenabled");

            // Whether or not the app should only download localised files in the user's selected language.
            LoadBoolFromRegistry(ref _blnLocalisedUpdatesOnly, "localisedupdatesonly");

            // Whether or not the app should use logging.
            LoadBoolFromRegistry(ref _blnUseLogging, "uselogging");

            // Whether or not dates should include the time.
            LoadBoolFromRegistry(ref _blnDatesIncludeTime, "datesincludetime");

            LoadBoolFromRegistry(ref _blnDronemods, "dronemods");

            LoadBoolFromRegistry(ref _blnDronemodsMaximumPilot, "dronemodsPilot");

            // Whether or not printouts should be sent to a file before loading them in the browser. This is a fix for getting printing to work properly on Linux using Wine.
            LoadBoolFromRegistry(ref _blnPrintToFileFirst, "printtofilefirst");

            // Default character sheet.
            LoadStringFromRegistry(ref _strDefaultCharacterSheet, "defaultsheet");

            // Omae Settings.
            // Username.
            LoadStringFromRegistry(ref _strOmaeUserName, "omaeusername");
            // Password.
            LoadStringFromRegistry(ref _strOmaePassword, "omaepassword");
            // AutoLogin.
            LoadBoolFromRegistry(ref _blnOmaeAutoLogin, "omaeautologin");
            // Language.
            string strLanguage = _strLanguage;

            if (LoadStringFromRegistry(ref strLanguage, "language"))
            {
                switch (_strLanguage)
                {
                case "en-us2":
                    _strLanguage = DefaultLanguage;
                    break;

                case "de":
                    _strLanguage = "de-de";
                    break;

                case "fr":
                    _strLanguage = "fr-fr";
                    break;

                case "jp":
                    _strLanguage = "ja-jp";
                    break;

                case "zh":
                    _strLanguage = "zh-cn";
                    break;
                }
                Language = strLanguage;
            }
            // Startup in Fullscreen mode.
            LoadBoolFromRegistry(ref _blnStartupFullscreen, "startupfullscreen");
            // Single instace of the Dice Roller window.
            LoadBoolFromRegistry(ref _blnSingleDiceRoller, "singlediceroller");

            // Open PDFs as URLs. For use with Chrome, Firefox, etc.
            LoadStringFromRegistry(ref _strPDFParameters, "pdfparameters");

            // PDF application path.
            LoadStringFromRegistry(ref _strPDFAppPath, "pdfapppath");

            // Folder path to check for characters.
            LoadStringFromRegistry(ref _strCharacterRosterPath, "characterrosterpath");

            // Prefer Nightly Updates.
            LoadBoolFromRegistry(ref _blnPreferNightlyUpdates, "prefernightlybuilds");

            // Retrieve CustomDataDirectoryInfo objects from registry
            RegistryKey objCustomDataDirectoryKey = _objBaseChummerKey.OpenSubKey("CustomDataDirectory");

            if (objCustomDataDirectoryKey != null)
            {
                List <KeyValuePair <CustomDataDirectoryInfo, int> > lstUnorderedCustomDataDirectories = new List <KeyValuePair <CustomDataDirectoryInfo, int> > (objCustomDataDirectoryKey.SubKeyCount);

                string[] astrCustomDataDirectoryNames = objCustomDataDirectoryKey.GetSubKeyNames();
                int      intMinLoadOrderValue         = int.MaxValue;
                int      intMaxLoadOrderValue         = int.MinValue;
                for (int i = 0; i < astrCustomDataDirectoryNames.Length; ++i)
                {
                    RegistryKey objLoopKey        = objCustomDataDirectoryKey.OpenSubKey(astrCustomDataDirectoryNames[i]);
                    string      strPath           = string.Empty;
                    object      objRegistryResult = objLoopKey.GetValue("Path");
                    if (objRegistryResult != null)
                    {
                        strPath = objRegistryResult.ToString().Replace("$CHUMMER", Application.StartupPath);
                    }
                    if (!string.IsNullOrEmpty(strPath) && Directory.Exists(strPath))
                    {
                        CustomDataDirectoryInfo objCustomDataDirectory = new CustomDataDirectoryInfo
                        {
                            Name = astrCustomDataDirectoryNames[i],
                            Path = strPath
                        };
                        objRegistryResult = objLoopKey.GetValue("Enabled");
                        if (objRegistryResult != null)
                        {
                            if (bool.TryParse(objRegistryResult.ToString(), out bool blnTemp))
                            {
                                objCustomDataDirectory.Enabled = blnTemp;
                            }
                        }
                        objRegistryResult = objLoopKey.GetValue("LoadOrder");
                        if (objRegistryResult != null && int.TryParse(objRegistryResult.ToString(), out int intLoadOrder))
                        {
                            // First load the infos alongside their load orders into a list whose order we don't care about
                            intMaxLoadOrderValue = Math.Max(intMaxLoadOrderValue, intLoadOrder);
                            intMinLoadOrderValue = Math.Min(intMinLoadOrderValue, intLoadOrder);
                            lstUnorderedCustomDataDirectories.Add(new KeyValuePair <CustomDataDirectoryInfo, int>(objCustomDataDirectory, intLoadOrder));
                        }
                        else
                        {
                            lstUnorderedCustomDataDirectories.Add(new KeyValuePair <CustomDataDirectoryInfo, int>(objCustomDataDirectory, int.MinValue));
                        }
                    }
                }

                // Now translate the list of infos whose order we don't care about into the list where we do care about the order of infos
                for (int i = intMinLoadOrderValue; i <= intMaxLoadOrderValue; ++i)
                {
                    KeyValuePair <CustomDataDirectoryInfo, int> objLoopPair = lstUnorderedCustomDataDirectories.FirstOrDefault(x => x.Value == i);
                    if (!objLoopPair.Equals(default(KeyValuePair <CustomDataDirectoryInfo, int>)))
                    {
                        _lstCustomDataDirectoryInfo.Add(objLoopPair.Key);
                    }
                }
                foreach (KeyValuePair <CustomDataDirectoryInfo, int> objLoopPair in lstUnorderedCustomDataDirectories.Where(x => x.Value == int.MinValue))
                {
                    _lstCustomDataDirectoryInfo.Add(objLoopPair.Key);
                }
            }
            // Auto-populate the rest of the list from customdata
            string strCustomDataRootPath = Path.Combine(Application.StartupPath, "customdata");

            if (Directory.Exists(strCustomDataRootPath))
            {
                foreach (string strLoopDirectoryPath in Directory.GetDirectories(strCustomDataRootPath))
                {
                    // Only add directories for which we don't already have entries loaded from registry
                    if (!_lstCustomDataDirectoryInfo.Any(x => x.Path == strLoopDirectoryPath))
                    {
                        CustomDataDirectoryInfo objCustomDataDirectory = new CustomDataDirectoryInfo
                        {
                            Name = Path.GetFileName(strLoopDirectoryPath),
                            Path = strLoopDirectoryPath
                        };
                        _lstCustomDataDirectoryInfo.Add(objCustomDataDirectory);
                    }
                }
            }
        }