From 8290b57cd469b6fe6436cfe2578aa4b6336f720a Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 10 Aug 2023 12:57:00 +0200 Subject: [PATCH] Use TempPath for WebView --- Elwig/App.xaml.cs | 3 ++- Elwig/Helpers/TempFile.cs | 2 +- Elwig/Windows/DocumentViewerWindow.xaml.cs | 13 ++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Elwig/App.xaml.cs b/Elwig/App.xaml.cs index 88bf04d..ad4b03a 100644 --- a/Elwig/App.xaml.cs +++ b/Elwig/App.xaml.cs @@ -17,6 +17,7 @@ namespace Elwig { public static readonly string DataPath = @"C:\ProgramData\Elwig\"; public static readonly string ExePath = @"C:\Program Files\Elwig\"; + public static readonly string TempPath = Path.Combine(Path.GetTempPath(), "Elwig"); public static readonly Config Config = new(DataPath + "config.ini"); public static string ZwstId { get; private set; } @@ -35,7 +36,7 @@ namespace Elwig { public App() : base() { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); - Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "Elwig")); + Directory.CreateDirectory(App.TempPath); Directory.CreateDirectory(DataPath); MainDispatcher = Dispatcher; Scales = Array.Empty(); diff --git a/Elwig/Helpers/TempFile.cs b/Elwig/Helpers/TempFile.cs index 4874c98..484540f 100644 --- a/Elwig/Helpers/TempFile.cs +++ b/Elwig/Helpers/TempFile.cs @@ -8,7 +8,7 @@ namespace Elwig.Helpers { public TempFile() : this(null) { } - public TempFile(string? ext) : this(Path.Combine(Path.GetTempPath(), "Elwig"), ext) { } + public TempFile(string? ext) : this(App.TempPath, ext) { } public TempFile(string dir, string? ext) { FilePath = Path.Combine(dir, Path.GetRandomFileName().Replace(".", "") + (ext != null ? $".{ext}" : "")); diff --git a/Elwig/Windows/DocumentViewerWindow.xaml.cs b/Elwig/Windows/DocumentViewerWindow.xaml.cs index 3ed5990..c300e66 100644 --- a/Elwig/Windows/DocumentViewerWindow.xaml.cs +++ b/Elwig/Windows/DocumentViewerWindow.xaml.cs @@ -6,11 +6,21 @@ namespace Elwig.Windows { public partial class DocumentViewerWindow : Window { private TempFile? PdfFile = null; + private string? PdfPath = null; public DocumentViewerWindow(string title, string path) { InitializeComponent(); Title = $"{title} - {Title}"; - WebView.Source = new($"file://{path}#view=FitH"); + PdfPath = path; + InitializeWebView(); + } + + public async void InitializeWebView() { + WebView.CreationProperties = new() { + UserDataFolder = App.TempPath, + }; + await WebView.EnsureCoreWebView2Async(); + WebView.Source = new($"file://{PdfPath}#view=FitH"); } public DocumentViewerWindow(string title, TempFile file) : this(title, file.FilePath) { @@ -22,6 +32,7 @@ namespace Elwig.Windows { WebView.Dispose(); PdfFile?.Dispose(); PdfFile = null; + PdfPath = null; } } }