Skip to content

Commit

Permalink
Prevent opening db with older app version
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Apr 2, 2024
1 parent 0147d31 commit 37fa3b7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
44 changes: 40 additions & 4 deletions Guard/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Guard.Core;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using Guard.Core;
using Guard.Core.Installation;
using Guard.Core.Security;
using Guard.Core.Storage;
using NSec.Cryptography;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using Serilog.Core;
using Windows.ApplicationModel.Activation;

namespace Guard
Expand Down Expand Up @@ -110,6 +111,40 @@ protected override async void OnStartup(StartupEventArgs e)
return;
}

Version currentVersion = InstallationInfo.GetVersion();
if (
SettingsManager.Settings.LastUsedAppVersion.Major == 0
&& SettingsManager.Settings.LastUsedAppVersion.Minor == 0
)
{
SettingsManager.Settings.LastUsedAppVersion = currentVersion;
_ = SettingsManager.Save();
}
int versionCompare = SettingsManager.Settings.LastUsedAppVersion.CompareTo(
currentVersion
);
if (versionCompare < 0)
{
SettingsManager.Settings.LastUsedAppVersion = currentVersion;
_ = SettingsManager.Save();
}
else if (versionCompare > 0)
{
Log.Logger.Error(
"Preventing app start: Current version is older than last used version: {0} < {1}",
currentVersion,
SettingsManager.Settings.LastUsedAppVersion
);
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = I18n.GetString("i.unsupported.olderversion.title"),
Content = I18n.GetString("i.unsupported.olderversion.content"),
CloseButtonText = I18n.GetString("i.unsupported.exit"),
};
await uiMessageBox.ShowDialogAsync();
Shutdown();
}

if (!autostart)
{
autostart = e.Args != null && e.Args.Contains("--autostart");
Expand Down Expand Up @@ -137,6 +172,7 @@ protected override void OnActivated(EventArgs e)
InactivityDetector.OnFocusGained();
base.OnActivated(e);
}

protected override void OnDeactivated(EventArgs e)
{
InactivityDetector.OnFocusLost();
Expand Down
9 changes: 7 additions & 2 deletions Guard/Core/Installation/InstallationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ internal static string GetInstallationTypeString()

internal static string GetVersionString()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString()
?? "????";
return GetVersion().ToString() ?? "????";
}

internal static Version GetVersion()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
?? new Version(0, 0);
}

internal static string GetAppDataFolderPath()
Expand Down
5 changes: 4 additions & 1 deletion Guard/Core/Models/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Guard.Core.Models
using Guard.Core.Installation;

namespace Guard.Core.Models
{
internal enum ThemeSetting
{
Expand Down Expand Up @@ -43,5 +45,6 @@ internal class AppSettings
public bool ShowTokenCardIntro { get; set; } = true;
public bool MinimizeToTray { get; set; } = false;
public LockTimeSetting LockTime { get; set; } = LockTimeSetting.TenMinutes;
public Version LastUsedAppVersion { get; set; } = new(0, 0);
}
}
2 changes: 2 additions & 0 deletions Guard/Resources/Strings.de.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,6 @@
<system:String x:Key="i.unsupported.vcpp.title">Visual C++ Redistributable nicht installiert</system:String>
<system:String x:Key="i.unsupported.vcpp.content">Die Software Microsoft Visual C++ Redistributable 2015-2022 ist nicht installiert. Bitte installiere das Paket, um 2FAGuard verwenden zu können. Falls du den 2FAGuard Installer verwendet hast oder das Paket gerade installiert hast, musst du eventuell dein Gerät neu starten.</system:String>
<system:String x:Key="i.unsupported.vcpp.download">Herunterladen</system:String>
<system:String x:Key="i.unsupported.olderversion.title">Veraltete App-Version</system:String>
<system:String x:Key="i.unsupported.olderversion.content">Du verwendest eine verwendest eine veraltete Version von 2FAGuard. Es können keine Daten geöffnet werden, die bereits mit einer neueren Version der App bearbeitet wurden. Bitte aktualisiere die App, um die Daten zu verwenden.</system:String>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions Guard/Resources/Strings.en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,6 @@
<system:String x:Key="i.unsupported.vcpp.title">Visual C++ Redistributable not installed</system:String>
<system:String x:Key="i.unsupported.vcpp.content">The Microsoft Visual C++ Redistributable 2015-2022 is required to run 2FAGuard. Please install the package to be able to use 2FAGuard. If you have used the 2FAGuard installer or have just installed the package, you may need to restart your device.</system:String>
<system:String x:Key="i.unsupported.vcpp.download">Download</system:String>
<system:String x:Key="i.unsupported.olderversion.title">Outdated app version</system:String>
<system:String x:Key="i.unsupported.olderversion.content">You are using an outdated version of 2FAGuard. Data that has already been edited with a newer version of the app cannot be opened. Please update the app to use the data.</system:String>
</ResourceDictionary>

0 comments on commit 37fa3b7

Please sign in to comment.