Skip to content

Commit

Permalink
Implements #5 Cache databases for disconnected (offline) usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrodan committed Oct 17, 2016
1 parent ca0c5ee commit bd58120
Show file tree
Hide file tree
Showing 21 changed files with 610 additions and 74 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### New

- \#5 Cache databases for disconnected (offline) usage

### Fixed

- \#58 Amazon S3: Cannot save/write database file to root of bucket
Expand Down
10 changes: 10 additions & 0 deletions KeeAnywhere/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using KeePass.App.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

Expand All @@ -11,6 +13,14 @@ public class PluginConfiguration
[DataMember]
public bool IsOfflineCacheEnabled { get; set; }

public string OfflineCacheFolder
{
get
{
return Path.Combine(AppConfigSerializer.LocalAppDataDirectory, "KeeAnywhereOfflineCache");
}
}

[DataMember]
[JsonConverter(typeof(StringEnumConverter))]
public AccountStorageLocation AccountStorageLocation { get; set; }
Expand Down
67 changes: 55 additions & 12 deletions KeeAnywhere/Forms/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 49 additions & 4 deletions KeeAnywhere/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
Expand All @@ -19,8 +20,6 @@ public partial class SettingsForm : Form
public SettingsForm()
{
InitializeComponent();

m_tcSettings.TabPages.Remove(m_tabGeneral);
}

public void InitEx(ConfigurationService configService, UIService uiService)
Expand All @@ -40,7 +39,7 @@ private void OnBtnCancelClick(object sender, EventArgs e)
private void OnBtnOkClick(object sender, EventArgs e)
{
// General Settings
m_configService.PluginConfiguration.IsOfflineCacheEnabled = m_cbOfflineCache.Checked;
m_configService.PluginConfiguration.IsOfflineCacheEnabled = m_chkOfflineCache.Checked;

if (m_rbStorageLocation_LocalUserSecureStore.Checked)
m_configService.PluginConfiguration.AccountStorageLocation = AccountStorageLocation.LocalUserSecureStore;
Expand Down Expand Up @@ -170,7 +169,8 @@ private void UpdateAccountList()

private void InitGeneralTab()
{
m_cbOfflineCache.Checked = m_configService.PluginConfiguration.IsOfflineCacheEnabled;
m_chkOfflineCache.Checked = m_configService.PluginConfiguration.IsOfflineCacheEnabled;
UpdateCacheButtonState();
}

private async void OnAccountAdd(object sender, EventArgs e)
Expand Down Expand Up @@ -307,6 +307,51 @@ private async void OnAccountCheck(object sender, EventArgs e)
this.UseWaitCursor = false;
}

private void OnClearCache(object sender, EventArgs e)
{
var isOk = MessageService.AskYesNo("Do you really want to clear Offline Cache Folder?\r\nMaybe your unsynced changes get lost!", "Clear Offline Cache", false);

if (isOk)
ClearCache();
}

private void ClearCache()
{
var path = m_configService.PluginConfiguration.OfflineCacheFolder;

if (!Directory.Exists(path))
return;

Directory.Delete(path, true);
}

private void OnOpenCacheFolder(object sender, EventArgs e)
{
var path = m_configService.PluginConfiguration.OfflineCacheFolder;
if (Directory.Exists(path))
Process.Start(path);
else
MessageService.ShowInfo("Offline Cache Folder does not exist:", path);
}

private void OnOfflineCacheChanged(object sender, EventArgs e)
{
UpdateCacheButtonState();

var path = m_configService.PluginConfiguration.OfflineCacheFolder;
if (m_chkOfflineCache.Checked || !Directory.Exists(path)) return;

var isOk = MessageService.AskYesNo("You are disabeling Offline Cache.\r\nDo you want to clear Offline Cache Folder?\r\nMaybe your unsynced changes get lost!", "Clear Offline Cache", false);

if (isOk)
ClearCache();
}

private void UpdateCacheButtonState()
{
var isEnabled = m_chkOfflineCache.Checked;
m_btnOpenCacheFolder.Enabled = isEnabled;
m_btnClearCache.Enabled = isEnabled;
}
}
}
5 changes: 4 additions & 1 deletion KeeAnywhere/KeeAnywhere.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@
<DependentUpon>OAuth2Form.cs</DependentUpon>
</Compile>
<Compile Include="OAuth2\OAuth2Token.cs" />
<Compile Include="Offline\CacheManagerService.cs" />
<Compile Include="Offline\ICacheSupervisor.cs" />
<Compile Include="PluginResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -299,7 +301,7 @@
<Compile Include="UIService.cs" />
<Compile Include="WebRequest\KeeAnywhereWebResponse.cs" />
<Compile Include="WebRequest\KeeAnywhereWebRequest.cs" />
<Compile Include="WebRequest\KeeAnywhereWebRequestCreator.cs" />
<Compile Include="Offline\CacheProvider.cs" />
<Compile Include="WebRequest\RequestStream.cs" />
<Compile Include="WebRequest\WrapperStream.cs" />
</ItemGroup>
Expand Down Expand Up @@ -362,6 +364,7 @@
<ItemGroup>
<Analyzer Include="..\packages\AWSSDK.S3.3.1.9.0\analyzers\dotnet\cs\AWSSDK.S3.CodeAnalysis.dll" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
14 changes: 11 additions & 3 deletions KeeAnywhere/KeeAnywhereExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows.Forms;
using KeeAnywhere.Configuration;
using KeeAnywhere.Forms;
using KeeAnywhere.Offline;
using KeeAnywhere.StorageProviders;
using KeePass.Plugins;
using KeePass.UI;
Expand All @@ -29,6 +30,7 @@ public class KeeAnywhereExt : Plugin

private ToolStripMenuItem _tsShowSettings;
private UIService _uiService;
private CacheManagerService _cacheManagerService;


/// <summary>
Expand All @@ -50,7 +52,7 @@ public override bool Initialize(IPluginHost pluginHost)
if (NativeLib.IsUnix()) return false;

_host = pluginHost;

//_host.MainWindow.FileOpened;
// Some binding redirection fixes for Google Drive API
FixGoogleApiDependencyLoading();

Expand All @@ -61,9 +63,13 @@ public override bool Initialize(IPluginHost pluginHost)
_configService = new ConfigurationService(pluginHost);
_configService.Load();

// Initialize CacheManager
_cacheManagerService = new CacheManagerService(_configService, _host);
_cacheManagerService.RegisterEvents();

// Initialize storage providers
_storageService = new StorageService(_configService);
_storageService.Register();
_storageService = new StorageService(_configService, _cacheManagerService);
_storageService.RegisterPrefixes();

// Initialize UIService
_uiService = new UIService(_configService, _storageService);
Expand Down Expand Up @@ -230,6 +236,8 @@ public override void Terminate()
if (_host == null) return;

_configService.Save();
_cacheManagerService.UnRegisterEvents();


_host.MainWindow.ToolsMenu.DropDownItems.Remove(_tsShowSettings);

Expand Down
Loading

0 comments on commit bd58120

Please sign in to comment.