Skip to content

Commit

Permalink
future proof LSM setting file access.
Browse files Browse the repository at this point in the history
  • Loading branch information
kianzarrin committed Aug 16, 2022
1 parent 4c09273 commit 2cc2f0b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
3 changes: 3 additions & 0 deletions LoadOrder/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ dotnet_diagnostic.HAA0101.severity = none

# HAA0601: Value type to reference type conversion causing boxing allocation
dotnet_diagnostic.HAA0601.severity = none

# IDE0003: Remove qualification
dotnet_diagnostic.IDE0003.severity = none
59 changes: 42 additions & 17 deletions LoadOrder/Data/LSMSettings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using System.Xml.Serialization;
using CO.IO;
using LoadOrder.Util;
using LoadOrderTool;
using LoadOrderTool.Util;

namespace LoadingScreenMod {
public class Settings {
Expand All @@ -13,34 +15,57 @@ public class Settings {
public static string DefaultSkipPath => Path.Combine(DataLocation.mapLocation, "SkippedPrefabs");
public static string DefaultSkipFile => Path.Combine(DefaultSkipPath, "skip.txt");

public int version = 10;
//public int version = 10;
public bool loadEnabled = true;
public bool loadUsed = true;
public bool shareTextures = true;
public bool shareMaterials = true;
public bool shareMeshes = true;
public bool optimizeThumbs = true;
public bool reportAssets;
public bool checkAssets;
public string reportDir = string.Empty;
//public bool shareTextures = true;
//public bool shareMaterials = true;
//public bool shareMeshes = true;
//public bool optimizeThumbs = true;
//public bool reportAssets;
//public bool checkAssets;
//public string reportDir = string.Empty;
public bool skipPrefabs;
public string skipFile = string.Empty;
public bool hideAssets;
public bool useReportDate = true;
//public bool hideAssets;
//public bool useReportDate = true;

#region rest of elements
private readonly List<XElement> elements = new List<XElement>();
[XmlAnyElement]
public List<XElement> Elements => elements;

public string this[XName name] {
get {
return Elements.Where(e => e.Name == name).Select(e => e.Value).FirstOrDefault();
}
set {
var element = Elements.Where(e => e.Name == name).FirstOrDefault();
if (element == null)
Elements.Add(element = new XElement(name));
element.Value = value;
}
}

public override string ToString() {
var ret = $"loadEnabled={loadEnabled}, loadUsed={loadUsed}, skipPrefabs={skipPrefabs}, skipFile={skipFile}";
foreach (var item in Elements) {
ret += $", {item.Name}={item.Value}";
}
return ret;
}
#endregion

public static Settings Deserialize() {
Settings s;
Settings ret;

try {
XmlSerializer serializer = new XmlSerializer(typeof(Settings));

using (StreamReader reader = new StreamReader(FilePath))
s = (Settings)serializer.Deserialize(reader);
} catch (Exception) { s = new Settings(); }

s.version = 6;
return s;
ret = (Settings)serializer.Deserialize(reader);
} catch (Exception) { ret = new Settings(); }
return ret;
}

public void Serialize() {
Expand Down
2 changes: 1 addition & 1 deletion Version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<AssemblyVersion>1.7.1.*</AssemblyVersion>
<AssemblyVersion>1.7.2.*</AssemblyVersion>
</PropertyGroup>
</Project>

0 comments on commit 2cc2f0b

Please sign in to comment.