Exemple #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));
        }
Exemple #2
0
        public DBUpdater(string dbpath, RulesProviders.RulesProvider provider)
        {
            DBPath   = dbpath;
            Provider = provider;

            if (File.Exists(dbpath))
            {
                OldUdb = new KTUserContext(dbpath);
            }
        }
Exemple #3
0
        public DBUpdater(string dbpath, RulesProviders.RulesProvider provider, EventHandler <UpdateEventArgs> callback = null)
        {
            DBPath   = dbpath;
            Provider = provider;
            Callback = callback;

            if (File.Exists(dbpath))
            {
                OldUdb = new KTUserContext(dbpath);
            }
        }
Exemple #4
0
        public static bool ShouldShowLegacyImportModal()
        {
            if (Device.RuntimePlatform != Device.iOS)
            {
                return(false);
            }

            if (!File.Exists(DBPath) || !File.Exists(KTLegacyContext.DBPath))
            {
                return(false);
            }

            var oldDB = new KTUserContext(DBPath);

            return(oldDB.GetCurrentVersion().RulesVersion == "1.1.1-c3a06fceb2f395c3f188ecd9bbfcd86781b8face5e29032b969b3a97b72c84c7");
        }
Exemple #5
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));
        }