Added button to settings to clear cache

This commit is contained in:
Timothy Baldridge 2020-05-29 16:51:41 -06:00
parent 2d457ad12d
commit ed649cde26
5 changed files with 40 additions and 3 deletions

View File

@ -127,6 +127,8 @@ namespace Wabbajack.Common
public static AbsolutePath SettingsFile => LocalAppDataPath.Combine("settings.json");
public static RelativePath SettingsIni = (RelativePath)"settings.ini";
public static byte SettingsVersion => 2;
public static AbsolutePath CefCacheLocation = @"CEF".RelativeTo(LocalAppDataPath);
public static Extension SeqExtension = new Extension(".seq");
public static RelativePath SettingsJson = (RelativePath)"settings.json";

View File

@ -12,6 +12,7 @@ using CefSharp;
using CefSharp.OffScreen;
using Wabbajack.Common;
using Wabbajack.Common.Serialization.Json;
using Cookie = CefSharp.Cookie;
namespace Wabbajack.Lib.LibCefHelpers
{
@ -89,11 +90,31 @@ namespace Wabbajack.Lib.LibCefHelpers
if (Inited) return;
Inited = true;
CefSettings settings = new CefSettings();
settings.CachePath = Path.Combine(Consts.LocalAppDataPath + @"\CEF");
settings.CachePath = Consts.CefCacheLocation.ToString();
Cef.Initialize(settings);
}
public static bool Inited { get; set; }
public static void ClearCookies()
{
var manager = Cef.GetGlobalCookieManager();
var visitor = new CookieDeleter();
manager.VisitAllCookies(visitor);
}
}
class CookieDeleter : ICookieVisitor
{
public void Dispose()
{
}
public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
{
deleteCookie = true;
return true;
}
}
public static class ModuleInitializer

View File

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using System.Windows;
using CefSharp;
using CefSharp.OffScreen;
using Wabbajack.Lib.LibCefHelpers;
namespace Wabbajack.Lib.WebAutomation
{
@ -53,5 +54,10 @@ namespace Wabbajack.Lib.WebAutomation
{
_browser.Dispose();
}
public static void ClearCache()
{
Helpers.ClearCookies();
}
}
}

View File

@ -38,11 +38,15 @@
FontFamily="Lucida Sans"
FontSize="20"
FontWeight="Bold"
Text="Modlist Gallery" />
Text="Misc Settings" />
<Grid
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="3">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.Resources>
<Style BasedOn="{StaticResource MainButtonStyle}" TargetType="Button">
<Style.Triggers>
@ -54,11 +58,12 @@
</Style.Triggers>
</Style>
</Grid.Resources>
<CheckBox Name="FilterPersistCheckBox" Content="Filters are saved on exit" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top">
<CheckBox Name="FilterPersistCheckBox" Content="Gallery filters are saved on exit" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" Grid.Row = "0">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1.2" ScaleY="1.2" />
</CheckBox.LayoutTransform>
</CheckBox>
<Button Name="ClearCefCache" Content="Clear In-App Browser Cache" Margin="0,5,0,0" Grid.Row="1"></Button>
</Grid>
</Grid>
</Border>

View File

@ -16,6 +16,7 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
using ReactiveUI;
using Wabbajack.Common;
using Wabbajack.Lib.WebAutomation;
namespace Wabbajack
{
@ -33,6 +34,8 @@ namespace Wabbajack
// Bind Values
this.Bind(this.ViewModel, x => x.IsPersistent, x => x.FilterPersistCheckBox.IsChecked)
.DisposeWith(disposable);
this.ClearCefCache.Click += (sender, args) => {Driver.ClearCache();};
});
}
}