//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- /// <summary> /// Gets called on App start and performs update task e.g. migrate the DB to a new format. /// </summary> public static async Task OnAppStartAsync() { PackageVersion versionLastStart = GetLastStartedVersion(); // Check if version != 0.0.0.0 => first ever start of the app: if (!(versionLastStart.Major == versionLastStart.Minor && versionLastStart.Build == versionLastStart.Revision && versionLastStart.Minor == versionLastStart.Build && versionLastStart.Major == 0) || Settings.getSettingBoolean(SettingsConsts.INITIALLY_STARTED)) { if (!Compare(versionLastStart, GetPackageVersion())) { // Large DB changes in version 0.2.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 2) { try { Logger.Info("Started updating DB to version 0.2.0.0."); AbstractDBManager.dB.RecreateTable <ChatTable>(); Logger.Info("Finished updating DB to version 0.2.0.0."); } catch (Exception e) { Logger.Error("Error during updating DB to version 0.2.0.0", e); } } // Accounts got reset in version 0.4.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 4) { try { Logger.Info("Started all vaults..."); Vault.deleteAllVaults(); Logger.Info("Finished deleting all vaults. Update to version 0.4.0.0 done."); } catch (Exception e) { Logger.Error("Error during deleting all vaults for version 0.4.0.0!", e); } } // Generate OMEMO keys and device id for each account created before version 0.9.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 9) { Logger.Info("Started generating OMEMO keys for accounts..."); foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { Logger.Info("Generating OMEMO keys for: " + account.getBareJid()); account.generateOmemoKeys(); AccountDBManager.INSTANCE.setAccount(account, false); } Logger.Info("Finished generating OMEMO keys for accounts. Update to version 0.9.0.0 done."); } // Drop all OMEMO tables since they have drastically changed in 0.11.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 11) { Logger.Info("Started dropping OMEMO tables..."); AbstractDBManager.dB.RecreateTable <OmemoDeviceTable>(); AbstractDBManager.dB.RecreateTable <OmemoDeviceListSubscriptionTable>(); AbstractDBManager.dB.RecreateTable <OmemoPreKeyTable>(); AbstractDBManager.dB.RecreateTable <OmemoIdentityKeyTable>(); AbstractDBManager.dB.RecreateTable <OmemoSessionStoreTable>(); AbstractDBManager.dB.RecreateTable <OmemoSignedPreKeyTable>(); foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { Logger.Info("Reseting OMEMO keys for: " + account.getBareJid()); account.omemoBundleInfoAnnounced = false; account.omemoDeviceId = 0; account.omemoKeysGenerated = false; account.omemoSignedPreKeyId = 0; AccountDBManager.INSTANCE.setAccount(account, false); } Logger.Info("Finished dropping OMEMO tables. Update to version 0.11.0.0 done."); } // Set the default theme to dark in 0.14.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 14) { Logger.Info("Started setting the default theme to dark..."); UiUtils.RootTheme = Windows.UI.Xaml.ElementTheme.Dark; Logger.Info("Finished setting the default theme to dark. Update to version 0.14.0.0 done."); } // Reset all OMEMO sessions, OMEMO subscriptions and delete all SENDING/TO_ENCRYPT messages for 0.15.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 15) { Logger.Info("Started the 0.15.0.0 update..."); AbstractDBManager.dB.RecreateTable <OmemoSessionStoreTable>(); AbstractDBManager.dB.RecreateTable <OmemoDeviceListSubscriptionTable>(); foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { IList <ChatMessageTable> msgs = ChatDBManager.INSTANCE.getChatMessages(account.getBareJid(), MessageState.TO_ENCRYPT); foreach (ChatMessageTable msg in msgs) { await ChatDBManager.INSTANCE.deleteChatMessageAsync(msg, false); } msgs = ChatDBManager.INSTANCE.getChatMessages(account.getBareJid(), MessageState.SENDING); foreach (ChatMessageTable msg in msgs) { await ChatDBManager.INSTANCE.deleteChatMessageAsync(msg, false); } } // By default enable the emoji button for all devices that run in mouse interaction mode since the touch keyboard already adds an emoji keyboard: Settings.setSetting(SettingsConsts.CHAT_ENABLE_EMOJI_BUTTON, !DeviceFamilyHelper.IsMouseInteractionMode()); Logger.Info("Update to version 0.15.0.0 done."); } } } SetVersion(GetPackageVersion()); }
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- /// <summary> /// Gets called on App start and performs update task e.g. migrate the DB to a new format. /// </summary> public static async Task OnAppStartAsync() { PackageVersion versionLastStart = GetLastStartedVersion(); // Check if version != 0.0.0.0 => first ever start of the app: if (!(versionLastStart.Major == 0 && versionLastStart.Major == versionLastStart.Minor && versionLastStart.Minor == versionLastStart.Revision && versionLastStart.Revision == versionLastStart.Build) || Settings.getSettingBoolean(SettingsConsts.INITIALLY_STARTED)) { if (!Compare(versionLastStart, GetPackageVersion())) { // Large DB changes in version 0.2.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 2) { try { Logger.Info("Started updating DB to version 0.2.0.0."); AbstractDBManager.dB.RecreateTable <ChatTable>(); Logger.Info("Finished updating DB to version 0.2.0.0."); } catch (Exception e) { Logger.Error("Error during updating DB to version 0.2.0.0", e); } } // Accounts got reset in version 0.4.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 4) { try { Logger.Info("Started all vaults..."); Vault.deleteAllVaults(); Logger.Info("Finished deleting all vaults. Update to version 0.4.0.0 done."); } catch (Exception e) { Logger.Error("Error during deleting all vaults for version 0.4.0.0!", e); } } // Generate OMEMO keys and device id for each account created before version 0.9.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 9) { Logger.Info("Started generating OMEMO keys for accounts..."); foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { Logger.Info("Generating OMEMO keys for: " + account.getBareJid()); account.generateOmemoKeys(); AccountDBManager.INSTANCE.setAccount(account, true, false); } Logger.Info("Finished generating OMEMO keys for accounts. Update to version 0.9.0.0 done."); } // Drop all OMEMO tables since they have drastically changed in 0.11.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 11) { Logger.Info("Started dropping OMEMO tables..."); AbstractDBManager.dB.RecreateTable <OmemoDeviceTable>(); AbstractDBManager.dB.RecreateTable <OmemoDeviceListSubscriptionTable>(); AbstractDBManager.dB.RecreateTable <OmemoPreKeyTable>(); AbstractDBManager.dB.RecreateTable <OmemoIdentityKeyTable>(); AbstractDBManager.dB.RecreateTable <OmemoSessionStoreTable>(); AbstractDBManager.dB.RecreateTable <OmemoSignedPreKeyTable>(); foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { Logger.Info("Reseting OMEMO keys for: " + account.getBareJid()); account.omemoBundleInfoAnnounced = false; account.omemoDeviceId = 0; account.omemoKeysGenerated = false; account.omemoSignedPreKeyId = 0; AccountDBManager.INSTANCE.setAccount(account, true, false); } Logger.Info("Finished dropping OMEMO tables. Update to version 0.11.0.0 done."); } // Set the default theme to dark in 0.14.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 14) { Logger.Info("Started setting the default theme to dark..."); ThemeUtils.RootTheme = Windows.UI.Xaml.ElementTheme.Dark; Logger.Info("Finished setting the default theme to dark. Update to version 0.14.0.0 done."); } // Reset all OMEMO sessions, OMEMO subscriptions and delete all SENDING/TO_ENCRYPT messages for 0.15.0.0: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 15) { Logger.Info("Started the 0.15.0.0 update..."); AbstractDBManager.dB.RecreateTable <OmemoSessionStoreTable>(); AbstractDBManager.dB.RecreateTable <OmemoDeviceListSubscriptionTable>(); foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { IList <ChatMessageTable> msgs = ChatDBManager.INSTANCE.getChatMessages(account.getBareJid(), MessageState.TO_ENCRYPT); foreach (ChatMessageTable msg in msgs) { await ChatDBManager.INSTANCE.deleteChatMessageAsync(msg, false); } msgs = ChatDBManager.INSTANCE.getChatMessages(account.getBareJid(), MessageState.SENDING); foreach (ChatMessageTable msg in msgs) { await ChatDBManager.INSTANCE.deleteChatMessageAsync(msg, false); } } // By default enable the emoji button for all devices that run in mouse interaction mode since the touch keyboard already adds an emoji keyboard: Settings.setSetting(SettingsConsts.CHAT_ENABLE_EMOJI_BUTTON, !DeviceFamilyHelper.IsMouseInteractionMode()); Logger.Info("Update to version 0.15.0.0 done."); } // Since v.0.16.0.0 we only show chats that have at least one chat message or have been started by the user: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 17) { Logger.Info("Started the 0.16.0.0 update..."); // Set the default theme to default again since in v.14 we set it to dark: Logger.Info("Started setting the default theme to default..."); ThemeUtils.RootTheme = Windows.UI.Xaml.ElementTheme.Default; foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { Logger.Info("Updating chats for: " + account.getBareJid()); IList <ChatTable> chats = ChatDBManager.INSTANCE.getAllChatsForClient(account.getBareJid()); foreach (ChatTable chat in chats) { chat.isChatActive = ChatDBManager.INSTANCE.getNextNChatMessages(chat.id, 1).Count > 0; ChatDBManager.INSTANCE.setChat(chat, false, false); } Logger.Info("Done updating chats for: " + account.getBareJid()); } Logger.Info("Update to version 0.16.0.0 done."); } // There was a bug in the way OMEMO session were created for own devices in versions pre v.0.19.0.0 so we need to reset the session table: if (versionLastStart.Major <= 0 && versionLastStart.Minor < 19) { Logger.Info("Started the 0.19.0.0 update..."); AbstractDBManager.dB.RecreateTable <OmemoSessionStoreTable>(); Logger.Info("Update to version 0.19.0.0 done."); } // SQLite got an update which should fix the DB loosing OMEMO keys. // To fix all accounts we recreate all OMEMO keys and sessions. if (versionLastStart.Major <= 0 && versionLastStart.Minor < 20) { Logger.Info("Started the 0.20.0.0 update..."); Logger.Info("Recreating all OMEMO tables..."); AbstractDBManager.dB.RecreateTable <OmemoSessionStoreTable>(); AbstractDBManager.dB.RecreateTable <OmemoDeviceTable>(); AbstractDBManager.dB.RecreateTable <OmemoDeviceListSubscriptionTable>(); AbstractDBManager.dB.RecreateTable <OmemoFingerprintTable>(); AbstractDBManager.dB.RecreateTable <OmemoIdentityKeyTable>(); AbstractDBManager.dB.RecreateTable <OmemoPreKeyTable>(); AbstractDBManager.dB.RecreateTable <OmemoSignedPreKeyTable>(); Logger.Info("All OMEMO tables recreated."); Logger.Info("Generating new OMEMO keys..."); foreach (XMPPAccount account in AccountDBManager.INSTANCE.loadAllAccounts()) { Logger.Info("Generating new OMEMO keys for: " + account.getBareJid()); account.omemoBundleInfoAnnounced = false; account.omemoDeviceId = 0; account.omemoKeysGenerated = false; account.omemoSignedPreKeyId = 0; AccountDBManager.INSTANCE.setAccount(account, true, false); Logger.Info("Finished generating new OMEMO keys for: " + account.getBareJid()); } Logger.Info("Finished generating new OMEMO keys."); Logger.Info("Update to version 0.20.0.0 done."); } if (versionLastStart.Major <= 0 && versionLastStart.Minor < 24) { Logger.Info("Started the 0.24.0.0 update..."); Settings.setSetting(SettingsConsts.ENTER_TO_SEND_MESSAGES, true); Logger.Info("Update to version 0.24.0.0 done."); } // The new stableId attribute for chat messages has been introduced. // We need to generate it based on the message id. if (versionLastStart.Major <= 0 && versionLastStart.Minor < 29) { Logger.Info("Started the 0.29.0.0 update..."); List <ChatTable> chats = ChatDBManager.INSTANCE.getAllChats(); Logger.Info("Generating chat message stableIds for " + chats.Count + " chats..."); foreach (ChatTable chat in chats) { IList <ChatMessageTable> msgs = ChatDBManager.INSTANCE.getChatMessages(chat.id); Logger.Info("Generating " + msgs.Count + " stableIds for \"" + chat.chatJabberId + "\"."); foreach (ChatMessageTable msg in msgs) { if (!string.Equals(msg.type, MessageMessage.TYPE_ERROR)) { // Reverse the process of ChatMessageTable.generateId(): msg.stableId = msg.id.Replace('_' + chat.id, ""); } else { // Reverse the process of ChatMessageTable.generateErrorMessageId(): msg.stableId = msg.id.Replace('_' + chat.id + "_error", ""); } await ChatDBManager.INSTANCE.setChatMessageAsync(msg, false, false); } } Logger.Info("Chat message stableIds generated."); Logger.Info("Update to version 0.29.0.0 done."); } } } SetVersion(GetPackageVersion()); }