コード例 #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
ファイル: frmOptions.cs プロジェクト: Vanatrix/chummer5a
        private void nudPDFOffset_ValueChanged(object sender, EventArgs e)
        {
            if (_skipRefresh)
                return;

            int offset = Convert.ToInt32(nudPDFOffset.Value);
            string tag = treSourcebook.SelectedNode.Tag.ToString();
            SourcebookInfo foundSource = GlobalOptions.Instance.SourcebookInfo.FirstOrDefault(x => x.Code == tag);

            if (foundSource != null)
            {
                foundSource.Offset = offset;
            }
            else
            {
                // If the Sourcebook was not found in the options, add it.
                var newSource = new SourcebookInfo();
                newSource.Code = tag;
                newSource.Offset = offset;
                GlobalOptions.Instance.SourcebookInfo.Add(newSource);
            }
        }
コード例 #3
0
ファイル: clsOptions.cs プロジェクト: ltdouthit/chummer5a
        static GlobalOptions()
        {
            if (!Directory.Exists(Path.Combine(Application.StartupPath, "settings")))
                Directory.CreateDirectory(Path.Combine(Application.StartupPath, "settings"));

            // 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
            {
            }

            // 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();
            }
            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);
        }
コード例 #4
0
        static GlobalOptions()
        {
            string settingsDirectoryPath = Path.Combine(Environment.CurrentDirectory, "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);
        }
コード例 #5
0
ファイル: frmOptions.cs プロジェクト: Vanatrix/chummer5a
        private void UpdateSourcebookInfoPath(string path)
        {
            string tag = treSourcebook.SelectedNode.Tag.ToString();
            SourcebookInfo foundSource = GlobalOptions.Instance.SourcebookInfo.FirstOrDefault(x => x.Code == tag);

            if (foundSource != null)
            {
                foundSource.Path = path;
            }
            else
            {
                // If the Sourcebook was not found in the options, add it.
                var newSource = new SourcebookInfo();
                newSource.Code = tag;
                newSource.Path = path;
                GlobalOptions.Instance.SourcebookInfo.Add(newSource);
            }
        }
コード例 #6
0
ファイル: frmOptions.cs プロジェクト: JoshwaSaville/chummer5a
        private void nudPDFOffset_ValueChanged(object sender, EventArgs e)
        {
            if (_blnSkipRefresh)
                return;

            SourcebookInfo objFoundSource = new SourcebookInfo();
            bool blnFound = false;

            // Find the selected item in the Sourcebook List.
            foreach (SourcebookInfo objSource in GlobalOptions.Instance.SourcebookInfo)
            {
                if (objSource.Code == treSourcebook.SelectedNode.Tag.ToString())
                {
                    objFoundSource = objSource;
                    blnFound = true;
                    break;
                }
            }

            objFoundSource.Offset = Convert.ToInt32(nudPDFOffset.Value);

            // If the Sourcebook was not found in the options, add it.
            if (!blnFound)
            {
                objFoundSource.Code = treSourcebook.SelectedNode.Tag.ToString();
                GlobalOptions.Instance.SourcebookInfo.Add(objFoundSource);
            }
        }
コード例 #7
0
ファイル: frmOptions.cs プロジェクト: JoshwaSaville/chummer5a
        private void cmdPDFLocation_Click(object sender, EventArgs e)
        {
            // Prompt the user to select a save file to associate with this Contact.
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf|All Files (*.*)|*.*";

            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                SourcebookInfo objFoundSource = new SourcebookInfo();
                bool blnFound = false;

                // Find the selected item in the Sourcebook List.
                foreach (SourcebookInfo objSource in GlobalOptions.Instance.SourcebookInfo)
                {
                    if (objSource.Code == treSourcebook.SelectedNode.Tag.ToString())
                    {
                        objFoundSource = objSource;
                        blnFound = true;
                        break;
                    }
                }

                txtPDFLocation.Text = openFileDialog.FileName;
                objFoundSource.Path = openFileDialog.FileName;

                // If the Sourcebook was not found in the options, add it.
                if (!blnFound)
                {
                    objFoundSource.Code = treSourcebook.SelectedNode.Tag.ToString();
                    GlobalOptions.Instance.SourcebookInfo.Add(objFoundSource);
                }
            }
        }
コード例 #8
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);
        }
コード例 #9
0
        /// <summary>
        /// Gets a textblock from a given PDF document.
        /// </summary>
        /// <param name="strSource">Formatted Source to search, ie SR5 70</param>
        /// <param name="strText">String to search for as an opener</param>
        /// <returns></returns>
        public static string GetTextFromPDF(string strSource, string strText)
        {
            if (string.IsNullOrEmpty(strText))
            {
                return(strText);
            }

            string[] strTemp = strSource.Split(' ');
            if (strTemp.Length < 2)
            {
                return(string.Empty);
            }
            if (!int.TryParse(strTemp[1], out int intPage))
            {
                return(string.Empty);
            }

            // Make sure the page is actually a number that we can use as well as being 1 or higher.
            if (intPage < 1)
            {
                return(string.Empty);
            }

            // Revert the sourcebook code to the one from the XML file if necessary.
            string strBook = LanguageBookCodeFromAltCode(strTemp[0], GlobalOptions.Language);

            // Retrieve the sourcebook information including page offset and PDF application name.
            SourcebookInfo objBookInfo = GlobalOptions.SourcebookInfo.FirstOrDefault(objInfo => objInfo.Code == strBook && !string.IsNullOrEmpty(objInfo.Path));

            // If the sourcebook was not found, we can't open anything.
            if (objBookInfo == null)
            {
                return(string.Empty);
            }

            Uri uriPath = new Uri(objBookInfo.Path);

            // Check if the file actually exists.
            if (!File.Exists(uriPath.LocalPath))
            {
                return(string.Empty);
            }
            intPage += objBookInfo.Offset;

            // due to the tag <nameonpage> for the qualities those variants are no longer needed,
            // as such the code would run at most half of the comparisons with the variants
            // but to be sure we find everything still strip unnecessary stuff after the ':' and any number in it.
            // PS: does any qualities have numbers on them? Or is that a chummer thing?
            string strTextToSearch = strText;
            int    intPos          = strTextToSearch.IndexOf(':');

            if (intPos != -1)
            {
                strTextToSearch = strTextToSearch.Substring(0, intPos);
            }
            strTextToSearch = strTextToSearch.Trim().TrimEndOnce(" I", " II", " III", " IV");

            PdfReader     reader              = objBookInfo.CachedPdfReader;
            List <string> lstStringFromPDF    = new List <string>();
            int           intTitleIndex       = -1;
            int           intBlockEndIndex    = -1;
            int           intExtraAllCapsInfo = 0;
            bool          blnTitleWithColon   = false; // it is either an uppercase title or title in a paragraph with a colon
            int           intMaxPagesToRead   = 3;     // parse at most 3 pages of content

            // Loop through each page, starting at the listed page + offset.
            for (; intPage <= reader.NumberOfPages; ++intPage)
            {
                // failsafe if something goes wrong, I guess no descrition takes more than two full pages?
                if (intMaxPagesToRead-- == 0)
                {
                    break;
                }

                int intProcessedStrings = lstStringFromPDF.Count;
                // each page should have its own text extraction strategy for it to work properly
                // this way we don't need to check for previous page appearing in the current page
                // https://stackoverflow.com/questions/35911062/why-are-gettextfrompage-from-itextsharp-returning-longer-and-longer-strings
                string strPageText = PdfTextExtractor.GetTextFromPage(reader, intPage, new SimpleTextExtractionStrategy());

                // don't trust it to be correct, trim all whitespace and remove empty strings before we even start
                lstStringFromPDF.AddRange(strPageText.Split('\n', StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)));

                for (int i = intProcessedStrings; i < lstStringFromPDF.Count; i++)
                {
                    // failsafe for languages that doesn't have case distincion (chinese, japanese, etc)
                    // there not much to be done for those languages, so stop after 10 continuous lines of uppercase text after our title
                    if (intExtraAllCapsInfo > 10)
                    {
                        break;
                    }

                    string strCurrentLine = lstStringFromPDF[i];
                    // we still haven't found anything
                    if (intTitleIndex == -1)
                    {
                        int intTextToSearchLength = strTextToSearch.Length;
                        int intTitleExtraLines    = 0;
                        if (strCurrentLine.Length < intTextToSearchLength)
                        {
                            // if the line is smaller first check if it contains the start of the text, before parsing the rest
                            if (strTextToSearch.StartsWith(strCurrentLine, StringComparison.OrdinalIgnoreCase))
                            {
                                // now just add more lines to it until it is enough
                                while (strCurrentLine.Length < intTextToSearchLength && (i + intTitleExtraLines + 1) < lstStringFromPDF.Count)
                                {
                                    intTitleExtraLines++;
                                    // add the content plus a space
                                    strCurrentLine += ' ' + lstStringFromPDF[i + intTitleExtraLines];
                                }
                            }
                            else
                            {
                                // just go to the next line
                                continue;
                            }
                        }
                        // now either we have enough text to search or the page doesn't have anymore stuff and must give up
                        if (strCurrentLine.Length < intTextToSearchLength)
                        {
                            break;
                        }

                        if (strCurrentLine.StartsWith(strTextToSearch, StringComparison.OrdinalIgnoreCase))
                        {
                            // WE FOUND SOMETHING! lets check what kind block we have
                            // if it is bigger it must have a ':' after the name otherwise it is probably the wrong stuff
                            if (strCurrentLine.Length > intTextToSearchLength)
                            {
                                if (strCurrentLine[intTextToSearchLength] == ':')
                                {
                                    intTitleIndex     = i;
                                    blnTitleWithColon = true;
                                }
                            }
                            else // if it is not bigger it is the same lenght
                            {
                                // this must be an upper case title
                                if (strCurrentLine.ToUpperInvariant() == strCurrentLine)
                                {
                                    intTitleIndex     = i;
                                    blnTitleWithColon = false;
                                }
                            }
                            // if we found the tile lets finish some things before finding the text block
                            if (intTitleIndex != -1)
                            {
                                // if we had to concatenate stuff lets fix the list of strings before continuing
                                if (intTitleExtraLines > 0)
                                {
                                    lstStringFromPDF[i] = strCurrentLine;
                                    lstStringFromPDF.RemoveRange(i + 1, intTitleExtraLines);
                                }
                            }
                        }
                    }
                    else // we already found our title, just go to the end of the block
                    {
                        // it is something in all caps we need to verify what it is
                        if (strCurrentLine.ToUpperInvariant() == strCurrentLine)
                        {
                            // if it is header or footer information just remove it
                            // do we also include lines with just numbers as probably page numbers??
                            if (strCurrentLine.All(char.IsDigit) || strCurrentLine.Contains(">>") || strCurrentLine.Contains("<<"))
                            {
                                lstStringFromPDF.RemoveAt(i);
                                // rewind and go again
                                i--;
                                continue;
                            }
                            // if it is a line in all caps following the all caps title just skip it
                            if (!blnTitleWithColon && i == intTitleIndex + intExtraAllCapsInfo + 1)
                            {
                                intExtraAllCapsInfo++;
                                continue;
                            }
                            // if we are here it is the end of the block we found our end, mark it and be done
                            intBlockEndIndex = i;
                            break;
                        }
                        // if it is a title with colon we stop in the next line that has a colon
                        // this is not perfect, if we had bold information we could do more about that
                        if (blnTitleWithColon && strCurrentLine.Contains(':'))
                        {
                            intBlockEndIndex = i;
                            break;
                        }
                    }
                }
                // we scanned the first page and found nothing, just give up
                if (intTitleIndex == -1)
                {
                    return(string.Empty);
                }
                // already have our end, quit searching here
                if (intBlockEndIndex != -1)
                {
                    break;
                }
            }

            // we have our textblock, lets format it and be done with it
            if (intBlockEndIndex != -1)
            {
                string[] strArray = lstStringFromPDF.ToArray();
                // if it is a "paragraph title" just concatenate everything
                if (blnTitleWithColon)
                {
                    return(string.Join(" ", strArray, intTitleIndex, intBlockEndIndex - intTitleIndex));
                }
                // add the title
                string strResultContent = strArray[intTitleIndex] + Environment.NewLine;
                // if we have extra info add it keeping the line breaks
                if (intExtraAllCapsInfo > 0)
                {
                    strResultContent += string.Join(Environment.NewLine, strArray, intTitleIndex + 1, intExtraAllCapsInfo) + Environment.NewLine;
                }
                int intContentStartIndex = intTitleIndex + intExtraAllCapsInfo + 1;
                // this is the best we can do for now, it will still mangle spell blocks a bit
                for (int i = intContentStartIndex; i < intBlockEndIndex; i++)
                {
                    string strContentString = strArray[i];
                    if (strContentString.Length > 0)
                    {
                        char chrLastChar = strContentString[strContentString.Length - 1];
                        if (char.IsPunctuation(chrLastChar))
                        {
                            if (chrLastChar == '-')
                            {
                                strResultContent += strContentString.Substring(0, strContentString.Length - 1);
                            }
                            else
                            {
                                strResultContent += strContentString + Environment.NewLine;
                            }
                        }
                        else
                        {
                            strResultContent += strContentString + ' ';
                        }
                    }
                }
                return(strResultContent);
            }
            return(string.Empty);
        }
コード例 #10
0
        /// <summary>
        /// Opens a PDF file using the provided source information.
        /// </summary>
        /// <param name="strSource">Book coode and page number to open.</param>
        /// <param name="strPDFParamaters">PDF parameters to use. If empty, use GlobalOptions.PDFParameters.</param>
        /// <param name="strPDFAppPath">PDF parameters to use. If empty, use GlobalOptions.PDFAppPath.</param>
        public static void OpenPDF(string strSource, string strPDFParamaters = "", string strPDFAppPath = "")
        {
            if (string.IsNullOrEmpty(strPDFParamaters))
            {
                strPDFParamaters = GlobalOptions.PDFParameters;
            }
            // The user must have specified the arguments of their PDF application in order to use this functionality.
            if (string.IsNullOrWhiteSpace(strPDFParamaters))
            {
                return;
            }

            if (string.IsNullOrEmpty(strPDFAppPath))
            {
                strPDFAppPath = GlobalOptions.PDFAppPath;
            }
            // The user must have specified the arguments of their PDF application in order to use this functionality.
            if (string.IsNullOrWhiteSpace(strPDFAppPath))
            {
                return;
            }

            string[] strTemp = strSource.Split(' ');
            if (strTemp.Length < 2)
            {
                return;
            }
            if (!int.TryParse(strTemp[1], out int intPage))
            {
                return;
            }

            // Make sure the page is actually a number that we can use as well as being 1 or higher.
            if (intPage < 1)
            {
                return;
            }

            // Revert the sourcebook code to the one from the XML file if necessary.
            string strBook = LanguageBookCodeFromAltCode(strTemp[0], GlobalOptions.Language);

            // Retrieve the sourcebook information including page offset and PDF application name.
            SourcebookInfo objBookInfo = GlobalOptions.SourcebookInfo.FirstOrDefault(objInfo => objInfo.Code == strBook && !string.IsNullOrEmpty(objInfo.Path));

            // If the sourcebook was not found, we can't open anything.
            if (objBookInfo == null)
            {
                return;
            }

            Uri uriPath = new Uri(objBookInfo.Path);

            // Check if the file actually exists.
            if (!File.Exists(uriPath.LocalPath))
            {
                return;
            }
            intPage += objBookInfo.Offset;

            string strParams = strPDFParamaters;

            strParams = strParams.Replace("{page}", intPage.ToString());
            strParams = strParams.Replace("{localpath}", uriPath.LocalPath);
            strParams = strParams.Replace("{absolutepath}", uriPath.AbsolutePath);
            ProcessStartInfo objProgress = new ProcessStartInfo
            {
                FileName  = strPDFAppPath,
                Arguments = strParams
            };

            Process.Start(objProgress);
        }