From ed649cde26ed822913d6eea25cdebe461109b1a9 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Fri, 29 May 2020 16:51:41 -0600 Subject: [PATCH] Added button to settings to clear cache --- Wabbajack.Common/Consts.cs | 2 ++ Wabbajack.Lib/LibCefHelpers/Init.cs | 23 ++++++++++++++++++- Wabbajack.Lib/WebAutomation/WebAutomation.cs | 6 +++++ .../Settings/ModlistGallerySettingsView.xaml | 9 ++++++-- .../ModlistGallerySettingsView.xaml.cs | 3 +++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index c30fe04c..4a072a48 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -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"; diff --git a/Wabbajack.Lib/LibCefHelpers/Init.cs b/Wabbajack.Lib/LibCefHelpers/Init.cs index 9f3c9985..5976b180 100644 --- a/Wabbajack.Lib/LibCefHelpers/Init.cs +++ b/Wabbajack.Lib/LibCefHelpers/Init.cs @@ -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 diff --git a/Wabbajack.Lib/WebAutomation/WebAutomation.cs b/Wabbajack.Lib/WebAutomation/WebAutomation.cs index 34999d22..efbaccc7 100644 --- a/Wabbajack.Lib/WebAutomation/WebAutomation.cs +++ b/Wabbajack.Lib/WebAutomation/WebAutomation.cs @@ -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(); + } } } diff --git a/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml index 3b54797d..dbc6ad8f 100644 --- a/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml +++ b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml @@ -38,11 +38,15 @@ FontFamily="Lucida Sans" FontSize="20" FontWeight="Bold" - Text="Modlist Gallery" /> + Text="Misc Settings" /> + + + + - + + diff --git a/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs index f314727f..d9f16a06 100644 --- a/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs +++ b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs @@ -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();}; }); } }