Skip to content

Commit b0b11f0

Browse files
committed
ModAPI.Common: simplify loading of {InstalledMods,LauncherSettings}.config
1 parent 1a73528 commit b0b11f0

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

ModAPI.Common/InstalledMods.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,17 @@ public bool Load(string path)
247247

248248
if (File.Exists(path))
249249
{
250-
251-
using (var reader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
250+
string xmlIn = File.ReadAllText(path);
251+
if (!String.IsNullOrEmpty(xmlIn))
252252
{
253-
string xmlIn = reader.ReadToEnd();
254-
if (!String.IsNullOrEmpty(xmlIn))
255-
{
256-
var document = new XmlDocument();
257-
document.LoadXml(xmlIn);
253+
var document = new XmlDocument();
254+
document.LoadXml(xmlIn);
258255

259-
foreach (XmlNode node in document.ChildNodes)
256+
foreach (XmlNode node in document.ChildNodes)
257+
{
258+
if (node.Name == InstalledMods.ElementName)
260259
{
261-
if (node.Name == InstalledMods.ElementName)
262-
{
263-
Load(document, node);
264-
}
260+
Load(document, node);
265261
}
266262
}
267263
}

ModAPI.Common/LauncherSettings.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,19 @@ public static bool Load(string path)
7474
{
7575
if (File.Exists(FileName))
7676
{
77-
using (var reader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
77+
string xmlIn = File.ReadAllText(path);
78+
if (!String.IsNullOrEmpty(xmlIn))
7879
{
79-
string xmlIn = reader.ReadToEnd();
80-
if (!String.IsNullOrEmpty(xmlIn))
81-
{
82-
var document = new XmlDocument();
83-
document.LoadXml(xmlIn);
80+
var document = new XmlDocument();
81+
document.LoadXml(xmlIn);
8482

85-
foreach (XmlNode node in document.ChildNodes)
83+
foreach (XmlNode node in document.ChildNodes)
84+
{
85+
if (node.Name == "Settings")
8686
{
87-
if (node.Name == "Settings")
87+
foreach (XmlNode settingNode in node.ChildNodes)
8888
{
89-
foreach (XmlNode settingNode in node.ChildNodes)
90-
{
91-
_dictionary[settingNode.Name] = settingNode.InnerText;
92-
}
89+
_dictionary[settingNode.Name] = settingNode.InnerText;
9390
}
9491
}
9592
}

0 commit comments

Comments
 (0)