/// <summary>
        /// Load the English document and cache it in the List of LanguageStrings so it only needs to be read in once.
        /// </summary>
        private static void RefreshStrings()
        {
            if (Utils.IsRunningInVisualStudio())
            {
                return;
            }

            _objDictionary.Clear();
            XmlDocument objEnglishDocument = new XmlDocument();
            string      strFilePath        = Path.Combine(Application.StartupPath, "lang", "en-us.xml");

            if (!File.Exists(strFilePath))
            {
                return;
            }
            objEnglishDocument.Load(strFilePath);
            foreach (XmlNode objNode in objEnglishDocument.SelectNodes("/chummer/strings/string"))
            {
                if (objNode["key"] == null || objNode["text"] == null)
                {
                    continue;
                }
                if (_objDictionary.ContainsKey(objNode["key"].InnerText))
                {
                    Utils.BreakIfDebug();
                }
                _objDictionary.Add(objNode["key"].InnerText, objNode["text"].InnerText);
            }
            _blnLoaded = true;
        }
        static LanguageManager()
        {
#if DEBUG
            string[] strArgs = Environment.GetCommandLineArgs();
            if (strArgs.GetUpperBound(0) > 0)
            {
                if (strArgs[1] == "/debug")
                {
                    _blnDebug = true;
                }
            }
#endif
            if (!Utils.IsRunningInVisualStudio())
            {
                _objDictionary.Clear();
                XmlDocument objEnglishDocument = new XmlDocument();
                string      strFilePath        = Path.Combine(Application.StartupPath, "lang", "en-us.xml");
                if (File.Exists(strFilePath))
                {
                    objEnglishDocument.Load(strFilePath);
                    foreach (XmlNode objNode in objEnglishDocument.SelectNodes("/chummer/strings/string"))
                    {
                        if (objNode["key"] != null && objNode["text"] != null)
                        {
                            if (!_objDictionary.TryAdd(objNode["key"].InnerText, objNode["text"].InnerText))
                            {
                                Utils.BreakIfDebug();
                            }
                        }
                    }
                }
            }
            _blnLoaded = true;
        }
Beispiel #3
0
        /// <summary>
        /// Load the English document and cache it in the List of LanguageStrings so it only needs to be read in once.
        /// </summary>
        private static void RefreshStrings()
        {
            if (Utils.IsRunningInVisualStudio())
            {
                return;
            }

            try
            {
                _objDictionary.Clear();
                XmlDocument objEnglishDocument = new XmlDocument();
                string      strFilePath        = Path.Combine(Application.StartupPath, "lang", "en-us.xml");
                objEnglishDocument.Load(strFilePath);
                foreach (XmlNode objNode in objEnglishDocument.SelectNodes("/chummer/strings/string"))
                {
                    LanguageString objString = new LanguageString();
                    objString.Key  = objNode["key"].InnerText;
                    objString.Text = objNode["text"].InnerText;
                    _objDictionary.Add(objNode["key"].InnerText, objNode["text"].InnerText);
                }
                _blnLoaded = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                //TODO this might f**k stuff up, remove before release, or fix?
                //Had obscure bug where this closed visual studio
                MessageBox.Show("Could not load default language file!" + Path.Combine(Application.StartupPath, "lang", "en-us.xml"), "Default Language Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Application.Exit();
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        static GlobalOptions()
        {
            if (Utils.IsRunningInVisualStudio())
            {
                return;
            }

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

            if (!Directory.Exists(settingsDirectoryPath))
            {
                Directory.CreateDirectory(settingsDirectoryPath);
            }

            // Automatic Update.
            try
            {
                _blnAutomaticUpdate = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("autoupdate").ToString());
            }
            catch
            {
            }

            try
            {
                _lifeModuleEnabled =
                    Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("lifemodule").ToString());
            }
            catch
            {
            }

            // Whether or not the app should only download localised files in the user's selected language.
            try
            {
                _blnLocalisedUpdatesOnly = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("localisedupdatesonly").ToString());
            }
            catch
            {
            }

            // Whether or not the app should use logging.
            try
            {
                _blnUseLogging = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("uselogging").ToString());
            }
            catch
            {
            }

            // Whether or not dates should include the time.
            try
            {
                _blnDatesIncludeTime = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("datesincludetime").ToString());
            }
            catch
            {
            }

            try
            {
                _blnMissionsOnly = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("missionsonly").ToString());
            }
            catch { }

            try
            {
                _blnDronemods = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("dronemods").ToString());
            }
            catch { }


            // 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.
            try
            {
                _blnPrintToFileFirst = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("printtofilefirst").ToString());
            }
            catch
            {
            }

            // Default character sheet.
            try
            {
                _strDefaultCharacterSheet = Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("defaultsheet").ToString();
            }
            catch
            {
            }

            // Omae Settings.
            // Username.
            try
            {
                _strOmaeUserName = Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("omaeusername").ToString();
            }
            catch
            {
            }
            // Password.
            try
            {
                _strOmaePassword = Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("omaepassword").ToString();
            }
            catch
            {
            }
            // AutoLogin.
            try
            {
                _blnOmaeAutoLogin = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("omaeautologin").ToString());
            }
            catch
            {
            }
            // Language.
            try
            {
                _strLanguage = Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("language").ToString();
                if (_strLanguage == "en-us2")
                {
                    _strLanguage = "en-us";
                }
            }
            catch
            {
            }
            // Startup in Fullscreen mode.
            try
            {
                _blnStartupFullscreen = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("startupfullscreen").ToString());
            }
            catch
            {
            }
            // Single instace of the Dice Roller window.
            try
            {
                _blnSingleDiceRoller = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("singlediceroller").ToString());
            }
            catch
            {
            }

            // Open PDFs as URLs. For use with Chrome, Firefox, etc.
            try
            {
                _blnOpenPDFsAsURLs = Convert.ToBoolean(Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("openpdfsasurls").ToString());
            }
            catch
            {
            }

            // PDF application path.
            try
            {
                _strPDFAppPath = Registry.CurrentUser.CreateSubKey("Software\\Chummer5").GetValue("pdfapppath").ToString();
            }
            catch
            {
            }

            // Retrieve the SourcebookInfo objects.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("books.xml");
            XmlNodeList objXmlBookList = objXmlDocument.SelectNodes("/chummer/books/book");

            foreach (XmlNode objXmlBook in objXmlBookList)
            {
                try
                {
                    SourcebookInfo objSource = new SourcebookInfo();
                    string         strTemp   = Registry.CurrentUser.CreateSubKey("Software\\Chummer5\\Sourcebook").GetValue(objXmlBook["code"].InnerText).ToString();
                    string[]       strParts  = strTemp.Split('|');
                    objSource.Code   = objXmlBook["code"].InnerText;
                    objSource.Path   = strParts[0];
                    objSource.Offset = Convert.ToInt32(strParts[1]);

                    _lstSourcebookInfo.Add(objSource);
                }
                catch
                {
                }
            }

            CyberwareGrades.LoadList(Improvement.ImprovementSource.Cyberware);
            BiowareGrades.LoadList(Improvement.ImprovementSource.Bioware);
        }
Beispiel #6
0
        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))
            {
                Directory.CreateDirectory(settingsDirectoryPath);
            }

            // 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 the SourcebookInfo objects.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("books.xml");

            foreach (XmlNode objXmlBook in objXmlDocument.SelectNodes("/chummer/books/book"))
            {
                if (objXmlBook["code"] != 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);
        }