mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Removed unused anti corruption code
This commit is contained in:
@@ -125,7 +125,7 @@ namespace ModernKeePass
|
|||||||
Window.Current.Activate();
|
Window.Current.Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnResuming(object sender, object e)
|
private void OnResuming(object sender, object e)
|
||||||
{
|
{
|
||||||
var currentFrame = Window.Current.Content as Frame;
|
var currentFrame = Window.Current.Content as Frame;
|
||||||
var database = DatabaseService.Instance;
|
var database = DatabaseService.Instance;
|
||||||
@@ -138,7 +138,7 @@ namespace ModernKeePass
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (database.CompositeKey != null) await database.ReOpen();
|
if (database.CompositeKey != null) database.ReOpen();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -167,14 +167,14 @@ namespace ModernKeePass
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender">The source of the suspend request.</param>
|
/// <param name="sender">The source of the suspend request.</param>
|
||||||
/// <param name="e">Details about the suspend request.</param>
|
/// <param name="e">Details about the suspend request.</param>
|
||||||
private async void OnSuspending(object sender, SuspendingEventArgs e)
|
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||||
{
|
{
|
||||||
var deferral = e.SuspendingOperation.GetDeferral();
|
var deferral = e.SuspendingOperation.GetDeferral();
|
||||||
var database = DatabaseService.Instance;
|
var database = DatabaseService.Instance;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (SettingsService.Instance.GetSetting("SaveSuspend", true)) database.Save();
|
if (SettingsService.Instance.GetSetting("SaveSuspend", true)) database.Save();
|
||||||
await database.Close(false);
|
database.Close(false);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@@ -23,12 +23,12 @@ namespace ModernKeePass.Interfaces
|
|||||||
bool IsClosed { get; }
|
bool IsClosed { get; }
|
||||||
bool HasChanged { get; set; }
|
bool HasChanged { get; set; }
|
||||||
|
|
||||||
Task Open(CompositeKey key, bool createNew = false);
|
void Open(CompositeKey key, bool createNew = false);
|
||||||
Task ReOpen();
|
void ReOpen();
|
||||||
void Save();
|
void Save();
|
||||||
void Save(StorageFile file);
|
void Save(StorageFile file);
|
||||||
void CreateRecycleBin(string title);
|
void CreateRecycleBin(string title);
|
||||||
void AddDeletedItem(PwUuid id);
|
void AddDeletedItem(PwUuid id);
|
||||||
Task Close(bool releaseFile = true);
|
void Close(bool releaseFile = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using Microsoft.HockeyApp;
|
using Microsoft.HockeyApp;
|
||||||
using ModernKeePass.Exceptions;
|
using ModernKeePass.Exceptions;
|
||||||
@@ -19,7 +18,6 @@ namespace ModernKeePass.Services
|
|||||||
{
|
{
|
||||||
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
||||||
private readonly ISettingsService _settings;
|
private readonly ISettingsService _settings;
|
||||||
private StorageFile _realDatabaseFile;
|
|
||||||
private StorageFile _databaseFile;
|
private StorageFile _databaseFile;
|
||||||
private GroupVm _recycleBin;
|
private GroupVm _recycleBin;
|
||||||
|
|
||||||
@@ -97,9 +95,8 @@ namespace ModernKeePass.Services
|
|||||||
/// <param name="key">The database composite key</param>
|
/// <param name="key">The database composite key</param>
|
||||||
/// <param name="createNew">True to create a new database before opening it</param>
|
/// <param name="createNew">True to create a new database before opening it</param>
|
||||||
/// <returns>An error message, if any</returns>
|
/// <returns>An error message, if any</returns>
|
||||||
public async Task Open(CompositeKey key, bool createNew = false)
|
public void Open(CompositeKey key, bool createNew = false)
|
||||||
{
|
{
|
||||||
// TODO: Check if there is an existing backup file
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (key == null)
|
if (key == null)
|
||||||
@@ -125,18 +122,6 @@ namespace ModernKeePass.Services
|
|||||||
}
|
}
|
||||||
else _pwDatabase.Open(ioConnection, key, new NullStatusLogger());
|
else _pwDatabase.Open(ioConnection, key, new NullStatusLogger());
|
||||||
|
|
||||||
//if (!_pwDatabase.IsOpen) return;
|
|
||||||
|
|
||||||
// Copy database in temp directory and use this file for operations
|
|
||||||
if (_settings.GetSetting<bool>("AntiCorruption"))
|
|
||||||
{
|
|
||||||
_realDatabaseFile = _databaseFile;
|
|
||||||
var backupFile =
|
|
||||||
await ApplicationData.Current.RoamingFolder.CreateFileAsync(Name,
|
|
||||||
CreationCollisionOption.FailIfExists);
|
|
||||||
Save(backupFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
RootGroup = new GroupVm(_pwDatabase.RootGroup, null, RecycleBinEnabled ? _pwDatabase.RecycleBinUuid : null);
|
RootGroup = new GroupVm(_pwDatabase.RootGroup, null, RecycleBinEnabled ? _pwDatabase.RecycleBinUuid : null);
|
||||||
}
|
}
|
||||||
catch (InvalidCompositeKeyException ex)
|
catch (InvalidCompositeKeyException ex)
|
||||||
@@ -146,9 +131,9 @@ namespace ModernKeePass.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ReOpen()
|
public void ReOpen()
|
||||||
{
|
{
|
||||||
await Open(CompositeKey);
|
Open(CompositeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -160,12 +145,6 @@ namespace ModernKeePass.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_pwDatabase.Save(new NullStatusLogger());
|
_pwDatabase.Save(new NullStatusLogger());
|
||||||
|
|
||||||
// Test if save worked correctly
|
|
||||||
if (_settings.GetSetting<bool>("AntiCorruption"))
|
|
||||||
{
|
|
||||||
_pwDatabase.Open(_pwDatabase.IOConnectionInfo, _pwDatabase.MasterKey, new NullStatusLogger());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -195,17 +174,9 @@ namespace ModernKeePass.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Close the currently opened database
|
/// Close the currently opened database
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task Close(bool releaseFile = true)
|
public void Close(bool releaseFile = true)
|
||||||
{
|
{
|
||||||
_pwDatabase?.Close();
|
_pwDatabase?.Close();
|
||||||
|
|
||||||
// Restore the backup DB to the original one
|
|
||||||
if (_settings.GetSetting<bool>("AntiCorruption"))
|
|
||||||
{
|
|
||||||
if (_pwDatabase != null && _pwDatabase.Modified)
|
|
||||||
Save(_realDatabaseFile);
|
|
||||||
await DatabaseFile.DeleteAsync();
|
|
||||||
}
|
|
||||||
if (releaseFile) DatabaseFile = null;
|
if (releaseFile) DatabaseFile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ namespace ModernKeePass.Services
|
|||||||
case ProductPurchaseStatus.AlreadyPurchased:
|
case ProductPurchaseStatus.AlreadyPurchased:
|
||||||
return (int) PurchaseResult.AlreadyPurchased;
|
return (int) PurchaseResult.AlreadyPurchased;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(purchaseResults.Status));
|
throw new IndexOutOfRangeException("Purchase results status does not have a valid value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -125,7 +125,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_isOpening = true;
|
_isOpening = true;
|
||||||
await Database.Open(CreateCompositeKey(), createNew);
|
Database.Open(CreateCompositeKey(), createNew);
|
||||||
await Task.Run(() => RootGroup = Database.RootGroup);
|
await Task.Run(() => RootGroup = Database.RootGroup);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
using System.Threading.Tasks;
|
using Windows.Storage;
|
||||||
using Windows.Storage;
|
|
||||||
using ModernKeePass.Interfaces;
|
using ModernKeePass.Interfaces;
|
||||||
using ModernKeePass.Services;
|
using ModernKeePass.Services;
|
||||||
|
|
||||||
@@ -15,11 +14,10 @@ namespace ModernKeePass.ViewModels
|
|||||||
_database = database;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Save(bool close = true)
|
public void Save(bool close = true)
|
||||||
{
|
{
|
||||||
_database.Save();
|
_database.Save();
|
||||||
if (close)
|
if (close) _database.Close();
|
||||||
await _database.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save(StorageFile file)
|
public void Save(StorageFile file)
|
||||||
|
@@ -62,9 +62,6 @@ namespace ModernKeePass.Views.BasePages
|
|||||||
/// session. The state will be null the first time a page is visited.</param>
|
/// session. The state will be null the first time a page is visited.</param>
|
||||||
protected void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
|
protected void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
|
||||||
{
|
{
|
||||||
// TODO: Assign a bindable group to Me.DefaultViewModel("Group")
|
|
||||||
// TODO: Assign a collection of bindable items to Me.DefaultViewModel("Items")
|
|
||||||
|
|
||||||
if (e.PageState == null)
|
if (e.PageState == null)
|
||||||
{
|
{
|
||||||
// When this is a new page, select the first item automatically unless logical page
|
// When this is a new page, select the first item automatically unless logical page
|
||||||
|
@@ -28,9 +28,9 @@ namespace ModernKeePass.Views
|
|||||||
_mainFrame = e.Parameter as Frame;
|
_mainFrame = e.Parameter as Frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
await Model.Save();
|
Model.Save();
|
||||||
_mainFrame.Navigate(typeof(MainPage));
|
_mainFrame.Navigate(typeof(MainPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ModernKeePass.Interfaces;
|
using ModernKeePass.Interfaces;
|
||||||
using ModernKeePass.ViewModels;
|
using ModernKeePass.ViewModels;
|
||||||
using ModernKeePassLib;
|
using ModernKeePassLib;
|
||||||
@@ -50,13 +49,10 @@ namespace ModernKeePassApp.Test.Mock
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Close(bool releaseFile = true)
|
public void Close(bool releaseFile = true)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
_isClosed = true;
|
||||||
{
|
_isOpen = false;
|
||||||
_isClosed = true;
|
|
||||||
_isOpen = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateRecycleBin(string title)
|
public void CreateRecycleBin(string title)
|
||||||
@@ -64,19 +60,16 @@ namespace ModernKeePassApp.Test.Mock
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Open(CompositeKey key, bool createNew = false)
|
public void Open(CompositeKey key, bool createNew = false)
|
||||||
{
|
{
|
||||||
_compositeKey = key;
|
_compositeKey = key;
|
||||||
return Task.Run(() =>
|
_isOpen = true;
|
||||||
{
|
_isClosed = false;
|
||||||
_isOpen = true;
|
|
||||||
_isClosed = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ReOpen()
|
public void ReOpen()
|
||||||
{
|
{
|
||||||
await Open(_compositeKey);
|
Open(_compositeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
|
Reference in New Issue
Block a user