Пример #1
0
        public void OpenDatabase(string openDatabaseFilename)
        {
            if (File.Exists(openDatabaseFilename) == false)
            {
                throw new ApplicationException("File does not exist.");
            }

            // Close the existing one, if applicable
            CloseDatabase();

            databaseFilename         = openDatabaseFilename;
            databaseConnectionString = string.Format("Data Source={0}", databaseFilename);

            Properties.Settings.Default.Properties["KPDatabaseConnectionString"].DefaultValue = databaseConnectionString;

            CreateConnections();


            // Default parsed culture value.
            string parsedCulture = "";

            if (localDB.Version.Rows.Count > 0)
            {
                // Get the parser version from the database.
                string parserVersion = localDB.Version[0].ParserVersion;

                if (string.IsNullOrEmpty(parserVersion) == false)
                {
                    // Parser version string is assembly version number (eg: 1.4)
                    // plus an optional culture language tag (eg: "fr", "de", "ja").

                    Match parsedLangMatch = Regex.Match(parserVersion, @"(?<dbVer>\d\.\d+)(?<lang>fr-FR|de-DE|ja-JP)?");
                    if (parsedLangMatch.Success)
                    {
                        DatabaseParseVersion = parsedLangMatch.Groups["dbVer"].Value;

                        parsedCulture = parsedLangMatch.Groups["lang"].Value;

                        if (parsedCulture == null)
                        {
                            parsedCulture = string.Empty;
                        }
                    }
                }
            }

            Resources.ParsedStrings.Culture = new System.Globalization.CultureInfo(parsedCulture);
            DatabaseParseCulture            = parsedCulture;

            // Reset the static string classes to get the properly translated
            // version of the resource strings.
            JobAbilities.Reset();
            ParseExpressions.Reset(parsedCulture);
        }
Пример #2
0
        /// <summary>
        /// Inserts a couple required pieces of information into newly-created databases.
        /// </summary>
        private void InitializeNewDatabase()
        {
            Properties.Settings appSettings = new WaywardGamers.KParser.Properties.Settings();

            string parsedCulture = appSettings.ParsingCulture;

            if (parsedCulture == null)
            {
                parsedCulture = string.Empty;
            }

            if ((parsedCulture != "fr-FR") &&
                (parsedCulture != "de-DE") &&
                (parsedCulture != "ja-JP"))
            {
                parsedCulture = string.Empty;
            }

            string parserVersionString = string.Format("{0}{1}", assemblyVersionString, parsedCulture);

            // Insert version information
            if (localDB.Version.Rows.Count == 0)
            {
                localDB.Version.AddVersionRow(databaseVersion, parserVersionString);
            }

            // Insert default battle row
            if (localDB.Battles.Rows.Count == 0)
            {
                localDB.Battles.AddBattlesRow(null, DateTime.Now.ToUniversalTime(),
                                              DateTime.Now.ToUniversalTime(), false, null, 0, 0, 0, 0, true);
            }

            UpdateDatabase();

            // Make sure we're using the proper translated strings when we start parsing.
            Resources.ParsedStrings.Culture = new System.Globalization.CultureInfo(parsedCulture);
            DatabaseParseCulture            = parsedCulture;

            // Reset the static string classes to get the properly translated
            // version of the resource strings.
            JobAbilities.Reset();
            ParseExpressions.Reset(parsedCulture);
        }