Use TempPath for WebView
This commit is contained in:
@ -17,6 +17,7 @@ namespace Elwig {
|
|||||||
|
|
||||||
public static readonly string DataPath = @"C:\ProgramData\Elwig\";
|
public static readonly string DataPath = @"C:\ProgramData\Elwig\";
|
||||||
public static readonly string ExePath = @"C:\Program Files\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 readonly Config Config = new(DataPath + "config.ini");
|
||||||
|
|
||||||
public static string ZwstId { get; private set; }
|
public static string ZwstId { get; private set; }
|
||||||
@ -35,7 +36,7 @@ namespace Elwig {
|
|||||||
|
|
||||||
public App() : base() {
|
public App() : base() {
|
||||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||||
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "Elwig"));
|
Directory.CreateDirectory(App.TempPath);
|
||||||
Directory.CreateDirectory(DataPath);
|
Directory.CreateDirectory(DataPath);
|
||||||
MainDispatcher = Dispatcher;
|
MainDispatcher = Dispatcher;
|
||||||
Scales = Array.Empty<IScale>();
|
Scales = Array.Empty<IScale>();
|
||||||
|
@ -8,7 +8,7 @@ namespace Elwig.Helpers {
|
|||||||
|
|
||||||
public TempFile() : this(null) { }
|
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) {
|
public TempFile(string dir, string? ext) {
|
||||||
FilePath = Path.Combine(dir, Path.GetRandomFileName().Replace(".", "") + (ext != null ? $".{ext}" : ""));
|
FilePath = Path.Combine(dir, Path.GetRandomFileName().Replace(".", "") + (ext != null ? $".{ext}" : ""));
|
||||||
|
@ -6,11 +6,21 @@ namespace Elwig.Windows {
|
|||||||
public partial class DocumentViewerWindow : Window {
|
public partial class DocumentViewerWindow : Window {
|
||||||
|
|
||||||
private TempFile? PdfFile = null;
|
private TempFile? PdfFile = null;
|
||||||
|
private string? PdfPath = null;
|
||||||
|
|
||||||
public DocumentViewerWindow(string title, string path) {
|
public DocumentViewerWindow(string title, string path) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Title = $"{title} - {Title}";
|
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) {
|
public DocumentViewerWindow(string title, TempFile file) : this(title, file.FilePath) {
|
||||||
@ -22,6 +32,7 @@ namespace Elwig.Windows {
|
|||||||
WebView.Dispose();
|
WebView.Dispose();
|
||||||
PdfFile?.Dispose();
|
PdfFile?.Dispose();
|
||||||
PdfFile = null;
|
PdfFile = null;
|
||||||
|
PdfPath = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user