Esempio n. 1
0
        private async Task <SQLiteAsyncConnection> GetConnectionAsync()
        {
            if (Connection == null)
            {
                var dbPassword = GetDBPassword();
                var connString = new SQLiteConnectionString(DbFile.FullName, true, key: GetDBPassword());
                Connection = new SQLiteAsyncConnection(connString);
                try
                {
                    await Connection.CreateTableAsync <OTPGenerator>();
                }
                catch (SQLiteException e) when(e.Result == SQLite3.Result.NonDBFile)
                {
                    //Encryption password does not match anymore. Most likely due to roaming.
                    //Notify user and delete database file. Hope they had backup.
                    await Connection.CloseAsync();

                    Connection = null;
                    DbFile.Delete();
                    ErrorOccurred?.Invoke(this, new ErrorEventArgs(e));
                    return(null);
                }

                await MigrateOldDb(Connection);
            }

            return(Connection);
        }
Esempio n. 2
0
        public static bool CheckForUpdates()
        {
            if (!Settings.Version.IsNullOrWhitespace())
            {
                string  newVersion = Settings.Version = typeof(ClientData).Assembly.GetName().Version.ToString();
                Version version    = new Version(Settings.Version);

                if (version < new Version(0, 13, 1))
                {
                    Settings.TextToSpeech = "Gablarski.SpeechNotifier.EventSpeech, Gablarski.SpeechNotifier";
                    Settings.Version      = newVersion;
                    Settings.Save();

                    return(true);
                }

                if (version < new Version(0, 13, 4))
                {
                    Settings.PlaybackDevice = "Default";
                    Settings.VoiceDevice    = "Default";
                    Settings.Version        = newVersion;
                    Settings.Save();

                    return(true);
                }

                return(false);
            }

            db.Close();
            DbFile.Delete();
            Settings.Clear();

            DbFile.Refresh();

            db.Open();
            CreateDbs();

            return(true);
        }