Use TempPath for WebView

This commit is contained in:
2023-08-10 12:57:00 +02:00
parent e1630e9919
commit 8290b57cd4
3 changed files with 15 additions and 3 deletions

View File

@ -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<IScale>();

View File

@ -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}" : ""));

View File

@ -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;
}
}
}