Update TemporaryFile to be stored in .../Kelwin/

This commit is contained in:
2023-03-10 16:34:16 +01:00
parent 483657911d
commit fa1adf51a1
3 changed files with 8 additions and 6 deletions

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.IO;
namespace WGneu {
public partial class App : Application {
@ -15,6 +16,7 @@ namespace WGneu {
public App() : base() {
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "Kelwin"));
MainDispatcher = Dispatcher;
}

View File

@ -50,8 +50,8 @@ namespace WGneu.Documents {
}
public async Task Generate() {
var pdf = new Utils.TemporaryFile(".pdf");
using (var tmpHtml = new Utils.TemporaryFile(".html")) {
var pdf = new Utils.TemporaryFile("pdf");
using (var tmpHtml = new Utils.TemporaryFile("html")) {
await File.WriteAllTextAsync(tmpHtml.FilePath, await Render());
await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath);
}

View File

@ -60,12 +60,12 @@ namespace WGneu {
private int Usages = 0;
public string FilePath { get; private set; }
public TemporaryFile() : this("") {}
public TemporaryFile() : this(null) {}
public TemporaryFile(string ext) : this(Path.GetTempPath(), ext) {}
public TemporaryFile(string? ext) : this(Path.Combine(Path.GetTempPath(), "Kelwin"), ext) {}
public TemporaryFile(string dir, string ext) {
FilePath = Path.Combine(dir, Path.GetRandomFileName() + ext);
public TemporaryFile(string dir, string? ext) {
FilePath = Path.Combine(dir, Path.GetRandomFileName().Replace(".", "") + (ext != null ? $".{ext}" : ""));
Usages++;
Create();
}