Skip to content

Commit

Permalink
Write launcher settings with correct indendation and encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
valters-tomsons committed Apr 23, 2023
1 parent 1f91c4e commit f715e4f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/DayZLauncher.UnixPatcher/Patches/LauncherConfigPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text;
using System.Xml;

namespace DayZLauncher.UnixPatcher.Patches;
Expand Down Expand Up @@ -30,7 +31,8 @@ public static async Task PatchLauncherConfigFile(string gamePath)
newXml = new string(configXml.OuterXml);
}

await File.WriteAllTextAsync(configFilePath, IndentXml(newXml));
newXml = IndentXml(newXml);
await File.WriteAllTextAsync(configFilePath, newXml);
}

public static void RemoveOldUserConfig(string gamePath)
Expand Down Expand Up @@ -74,13 +76,14 @@ private static string IndentXml(string xml)
Indent = true,
IndentChars = " ",
NewLineChars = "\r\n",
NewLineHandling = NewLineHandling.Replace
NewLineHandling = NewLineHandling.Replace,
Encoding = Encoding.UTF8
};

using var stringWriter = new StringWriter();
using var xmlWriter = XmlWriter.Create(stringWriter, settings);
var sb = new StringBuilder();
using var xmlWriter = XmlWriter.Create(sb, settings);
doc.Save(xmlWriter);
return stringWriter.ToString();
var xmlString = sb.ToString();
return xmlString.Replace("utf-16", "utf-8");
}

}

0 comments on commit f715e4f

Please sign in to comment.