Utils: Add UTF8 encoding without BOM

This commit is contained in:
2023-09-07 16:39:49 +02:00
parent de53bfdd2b
commit 8a678509c5
3 changed files with 5 additions and 5 deletions

View File

@ -2,7 +2,6 @@ using System;
using System.Threading.Tasks;
using System.IO;
using Elwig.Helpers;
using System.Text;
namespace Elwig.Documents {
public abstract class Document : IDisposable {
@ -63,7 +62,7 @@ namespace Elwig.Documents {
public async Task Generate() {
var pdf = new TempFile("pdf");
using (var tmpHtml = new TempFile("html")) {
await File.WriteAllTextAsync(tmpHtml.FilePath, await Render(), Encoding.UTF8);
await File.WriteAllTextAsync(tmpHtml.FilePath, await Render(), Utils.UTF8);
await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath);
}
PdfFile = pdf;

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using IniParser;
using IniParser.Model;
@ -25,7 +24,7 @@ namespace Elwig.Helpers {
var parser = new FileIniDataParser();
IniData? ini = null;
try {
ini = parser.ReadFile(FileName, Encoding.UTF8);
ini = parser.ReadFile(FileName, Utils.UTF8);
} catch {}
if (ini == null || !ini.TryGetKey("database.file", out string db)) {
@ -70,7 +69,7 @@ namespace Elwig.Helpers {
}
public void Write() {
using var file = new StreamWriter(FileName, false, Encoding.UTF8);
using var file = new StreamWriter(FileName, false, Utils.UTF8);
file.Write($"\r\n[general]\r\n");
if (Branch != null) file.Write($"branch = {Branch}\r\n");
file.Write($"\r\n[database]\r\nfile = {DatabaseFile}\r\n");

View File

@ -15,6 +15,8 @@ using Elwig.Models;
namespace Elwig.Helpers {
public static partial class Utils {
public static readonly Encoding UTF8 = new UTF8Encoding(false, true);
public static int CurrentYear => DateTime.Now.Year;
public static int CurrentNextSeason => DateTime.Now.Year - (DateTime.Now.Month <= 3 ? 1 : 0);
public static int CurrentLastSeason => DateTime.Now.Year - (DateTime.Now.Month <= 7 ? 1 : 0);