Пример #1
0
        public KTUserContext GetUpdatedContext()
        {
            if (NeedsUpdate())
            {
                // creates new UDB, clobbers any old or unfinished updates
                var newUdbPath = DBPath + ".new";
                if (File.Exists(newUdbPath))
                {
                    File.Delete(newUdbPath);
                }
                var newUdb = new KTUserContext(newUdbPath);

                IKTContext backup = GetBackupContext();

                // import the rules and user data to the new db
                newUdb.ImportRules(Provider);
                if (backup != null)
                {
                    var replacements = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(Provider.GetReplacementsJSON());
                    Sauvegarde.SetSerializedData(newUdb, Sauvegarde.GetSerializedData(backup), false, replacements);
                }

                // clobber the old db with the new one
                newUdb.Database.CloseConnection();
                OldUdb?.Database?.CloseConnection();
                File.Copy(newUdbPath, DBPath, true);
                File.Delete(newUdbPath);
            }

            return(new KTUserContext(DBPath));
        }
Пример #2
0
        public KTUserContext GetUpdatedContext()
        {
            Log("Checking if Database needs update");
            if (NeedsUpdate())
            {
                Log($"Updating Database to {Provider.GetVersion()}");
                // creates new UDB, clobbers any old or unfinished updates
                var newUdbPath = DBPath + ".new";
                if (File.Exists(newUdbPath))
                {
                    File.Delete(newUdbPath);
                }
                var newUdb = new KTUserContext(newUdbPath);

                IKTContext backup = GetBackupContext();

                Log($"Importing rules to new database");
                // import the rules and user data to the new db
                newUdb.ImportRules(Provider);
                if (backup != null)
                {
                    string legacy = (backup is KTLegacyContext ? "legacy " : "");
                    Log($"Backing up old {legacy}Database");
                    var replacements = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(Provider.GetReplacementsJSON());
                    Log($"Applying {legacy}backup to new Database");
                    Sauvegarde.SetSerializedData(
                        newUdb,
                        Sauvegarde.GetSerializedData(backup),
                        false,
                        replacements,
                        (float?p, string s) => Log(null, p, s)
                        );
                }

                Log($"Applying New Database");
                // clobber the old db with the new one
                newUdb.Database.CloseConnection();
                OldUdb?.Database?.CloseConnection();
                File.Copy(newUdbPath, DBPath, true);
                File.Delete(newUdbPath);
            }

            Log($"Loading Database");
            return(new KTUserContext(DBPath));
        }