Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
🥅 Avoid using XmlSerializer to not generate assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed May 20, 2022
1 parent 19a33e2 commit fb2bec4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion RogueLibsCore/Names/Localization/LanguageVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace RogueLibsCore
{
public sealed class LanguageVersions : IXmlSerializable
{
private LanguageVersions() { }
internal LanguageVersions() { }
public Dictionary<string, int> Entries { get; private set; } = null!; // initialized on deserialization

public void WriteXml(XmlWriter xml)
Expand Down
2 changes: 1 addition & 1 deletion RogueLibsCore/Names/Localization/LocaleLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RogueLibsCore
[XmlRoot("Language")]
public sealed class LocaleLanguage : IXmlSerializable
{
private LocaleLanguage() { }
internal LocaleLanguage() { }
public string Id { get; private set; } = null!; // initialized on deserialization
public int Version { get; private set; }
public LanguageCode Code { get; internal set; }
Expand Down
13 changes: 9 additions & 4 deletions RogueLibsCore/Names/Localization/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ private static bool DownloadIndex()
WebClient web = new WebClient();
web.DownloadFile(url, downloadPath);

XmlSerializer ser = new XmlSerializer(typeof(LanguageVersions));
using (FileStream stream = new FileStream(downloadPath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (XmlReader reader = XmlReader.Create(stream))
Versions = (LanguageVersions)ser.Deserialize(reader);
{
Versions = new LanguageVersions();
Versions.ReadXml(reader);
}

string lastAccessFile = Path.Combine(localePath, ".lastaccess");
File.WriteAllText(lastAccessFile, DateTime.Now.ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -132,7 +134,6 @@ private static void UpdateLanguage(string language, string filePath, int newVers
}
}

private static readonly XmlSerializer languageSer = new XmlSerializer(typeof(LocaleLanguage));
private static string localePath = null!; // initialized in Init()

private static void InitializeLanguages()
Expand Down Expand Up @@ -185,7 +186,11 @@ public static void ReInitializeLanguages()
{
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (XmlReader reader = XmlReader.Create(stream))
return (LocaleLanguage)languageSer.Deserialize(reader);
{
LocaleLanguage language = new LocaleLanguage();
language.ReadXml(reader);
return language;
}
}
catch
{
Expand Down

0 comments on commit fb2bec4

Please sign in to comment.