Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kianzarrin committed Nov 16, 2022
2 parents 33e8bff + f01c0d0 commit ee74788
Show file tree
Hide file tree
Showing 39 changed files with 299 additions and 554 deletions.
6 changes: 3 additions & 3 deletions LoadOrder/CO/IO/DataLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static class DataLocation {
string m = "Delayed messages: "; // delayed message;
CSCache csCache = null;
try {
csCache = CSCache.Deserialize(LocalLOMData);
csCache = CSCache.Deserialize();
if(csCache == null) {
csCache = new CSCache();
// backward compatibility.
var data2 = LoadOrderConfig.Deserialize(LocalLOMData);
var data2 = LoadOrderConfig.Deserialize();
if(data2 != null) {
csCache.WorkShopContentPath = data2.WorkShopContentPath;
csCache.GamePath = data2.GamePath;
Expand Down Expand Up @@ -128,7 +128,7 @@ public static class DataLocation {
csCache.GamePath = GamePath;
csCache.SteamPath = SteamPath;
csCache.WorkShopContentPath = WorkshopContentPath;
csCache.Serialize(LocalLOMData);
csCache.Serialize();
} else {
Log.Info(m);
Process.GetCurrentProcess().Kill();
Expand Down
18 changes: 9 additions & 9 deletions LoadOrder/Data/ConfigWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ConfigWrapper : SingletonLite<ConfigWrapper> {
public SteamCache SteamCache;
public CSCache CSCache;

public LoadingScreenMod.Settings LSMConfig;
public LoadingScreenMod.LSMSettings LSMConfig;

bool dirty_;
public bool Dirty {
Expand All @@ -34,11 +34,11 @@ public class ConfigWrapper : SingletonLite<ConfigWrapper> {
public override void Awake() {
base.Awake();
var sw = System.Diagnostics.Stopwatch.StartNew();
Config = LoadOrderConfig.Deserialize(DataLocation.LocalLOMData)
Config = LoadOrderConfig.Deserialize()
?? new LoadOrderConfig();
SteamCache = SteamCache.Deserialize() ?? new SteamCache();
ReloadCSCache();
LSMConfig = LoadingScreenMod.Settings.Deserialize();
LSMConfig = LoadingScreenMod.LSMSettings.Deserialize();
Log.Info($"LoadOrderConfig.Deserialize took {sw.ElapsedMilliseconds}ms");
if(!CommandLine.Parse.CommandLine)
StartSaveThread();
Expand Down Expand Up @@ -86,14 +86,14 @@ public class ConfigWrapper : SingletonLite<ConfigWrapper> {
public void Suspend() => Paused = true;
public void Resume() => Paused = false;

public void ReloadCSCache() => CSCache = CSCache.Deserialize(DataLocation.LocalLOMData) ?? new CSCache();
public void ReloadCSCache() => CSCache = CSCache.Deserialize() ?? new CSCache();
public void ResetCSCache() {
CSCache = new CSCache() {
WorkShopContentPath = CSCache?.WorkShopContentPath,
SteamPath = CSCache?.SteamPath,
GamePath = CSCache?.GamePath,
};
CSCache.Serialize(DataLocation.LocalLOMData);
CSCache.Serialize();
}

public void ResetAllConfig() {
Expand All @@ -104,7 +104,7 @@ public class ConfigWrapper : SingletonLite<ConfigWrapper> {
GamePath = DataLocation.GamePath,
SteamPath = DataLocation.SteamPath,
};
Config.Serialize(DataLocation.LocalLOMData);
Config.Serialize();

ResetCSCache();
SteamCache = new SteamCache();
Expand Down Expand Up @@ -132,10 +132,10 @@ public class ConfigWrapper : SingletonLite<ConfigWrapper> {
Log.Called();
Assertion.Assert(Paused, "pause config before doing this");
Dirty = false;
Config = LoadOrderConfig.Deserialize(DataLocation.LocalLOMData)
Config = LoadOrderConfig.Deserialize()
?? new LoadOrderConfig();
ReloadCSCache();
LSMConfig = LoadingScreenMod.Settings.Deserialize();
LSMConfig = LoadingScreenMod.LSMSettings.Deserialize();
Log.Succeeded();
} catch(Exception ex) {
ex.Log();
Expand All @@ -154,7 +154,7 @@ public class ConfigWrapper : SingletonLite<ConfigWrapper> {
Dirty = false;
ManagerList.instance.Save(); // saves but not serialize
PluginManager.instance.ApplyPendingValues(); // saves to game config and moves folders.
Config.Serialize(DataLocation.LocalLOMData);
Config.Serialize();
SteamCache.Serialize();
LSMConfig = LSMConfig.SyncAndSerialize();
Log.Info($"SaveConfigImpl() done. (Dirty={Dirty})");
Expand Down
20 changes: 6 additions & 14 deletions LoadOrder/Data/LSMSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
using System.Xml.Linq;
using System.Xml.Serialization;
using CO.IO;
using LoadOrder.Util;
using LoadOrderTool;

namespace LoadingScreenMod {

[XmlRoot("LoadingScreenModRevisited")]
public class Settings {
public class LSMSettings {
const string FILE_NAME = "LoadingScreenModRevisited.xml";
static string FILE_PATH => Path.Combine(DataLocation.localApplicationData, FILE_NAME);

Expand Down Expand Up @@ -50,31 +49,25 @@ public class Settings {
}
#endregion

public static Settings Deserialize() {
public static LSMSettings Deserialize() {
try {
if (File.Exists(FILE_PATH)) {
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
return LoadOrderShared.SharedUtil.Deserialize<LSMSettings>( FILE_PATH);

using (StreamReader reader = new StreamReader(FILE_PATH))
return (Settings)serializer.Deserialize(reader);
}
} catch (Exception ex) {
ex.Log();
}
return new Settings();
return new LSMSettings();
}

private void Serialize() {
try {
var serializer = new XmlSerializer(typeof(Settings));
using (StreamWriter writer = new StreamWriter(FILE_PATH))
serializer.Serialize(writer, this, XMLUtil.NoNamespaces);
LoadOrderShared.SharedUtil.Serialize(this, FILE_PATH);
} catch (Exception ex) {
ex.Log();
}
}

public Settings SyncAndSerialize() {
public LSMSettings SyncAndSerialize() {
try {
var ret = Deserialize();
ret.skipFile = this.skipFile;
Expand All @@ -88,6 +81,5 @@ public class Settings {
return this;
}
}

}
}
11 changes: 2 additions & 9 deletions LoadOrder/Data/LoadOrderProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace LoadOrderTool.Data {
using System.Linq;
using System.Xml.Serialization;
using LoadOrderTool.Util;
using LoadOrder.Util;

public interface IProfileItem {
string GetIncludedPath();
Expand Down Expand Up @@ -139,19 +138,13 @@ public class Asset : IProfileItem {
public void Serialize(string path) {
try {
Log.Called();
XmlSerializer ser = new XmlSerializer(typeof(LoadOrderProfile));
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) {
ser.Serialize(fs, this, XMLUtil.NoNamespaces);
}
LoadOrderShared.SharedUtil.Serialize(this, path);
} catch (Exception ex) { ex.Log(); }
}

public static LoadOrderProfile Deserialize(string path) {
try {
XmlSerializer ser = new XmlSerializer(typeof(LoadOrderProfile));
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) {
return ser.Deserialize(fs) as LoadOrderProfile;
}
return LoadOrderShared.SharedUtil.Deserialize<LoadOrderProfile>(path);
} catch {
return null;
}
Expand Down
12 changes: 2 additions & 10 deletions LoadOrder/Data/LoadOrderToolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace LoadOrderTool {
using System.IO;
using System.Xml.Serialization;
using CO.IO;
using LoadOrder.Util;

public class LoadOrderToolSettings {
public int FormWidth = -1;
Expand All @@ -17,7 +16,6 @@ public class LoadOrderToolSettings {
public bool LSM = false;
public bool LHT;
public int AutoLoad = 0;
public bool Phased, Poke;

public bool SteamExe = true;
public bool DebugMono;
Expand All @@ -38,19 +36,13 @@ public class LoadOrderToolSettings {
public static void Reset() => instance_ = new LoadOrderToolSettings();

public void Serialize() {
XmlSerializer ser = new XmlSerializer(typeof(LoadOrderToolSettings));
using (FileStream fs = new FileStream(PATH, FileMode.Create, FileAccess.Write)) {
ser.Serialize(fs, this, XMLUtil.NoNamespaces);
}
LoadOrderShared.SharedUtil.Serialize(this, PATH);
}

public static LoadOrderToolSettings Deserialize() {
Log.Info("LoadOrderToolSettings Deserializing ...");
try {
XmlSerializer ser = new XmlSerializer(typeof(LoadOrderToolSettings));
using (FileStream fs = new FileStream(PATH, FileMode.Open, FileAccess.Read)) {
return ser.Deserialize(fs) as LoadOrderToolSettings;
}
return LoadOrderShared.SharedUtil.Deserialize<LoadOrderToolSettings>(PATH);
} catch {
Log.Warning("Deserialize exception caught");
return null;
Expand Down
2 changes: 1 addition & 1 deletion LoadOrder/Data/Manager/LSMManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace LoadOrderTool.Data {
public class LSMManager : SingletonLite<LSMManager>, IDataManager {
static ConfigWrapper ConfigWrapper => ConfigWrapper.instance;
static LoadingScreenMod.Settings LSMConfig => ConfigWrapper.instance.LSMConfig;
static LoadingScreenMod.LSMSettings LSMConfig => ConfigWrapper.instance.LSMConfig;
public bool IsLoading { get; private set; }
public bool IsLoaded { get; private set; }
public event Action EventLoaded;
Expand Down
21 changes: 7 additions & 14 deletions LoadOrder/Data/SteamCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace LoadOrderTool.Data {
using System.Collections.Generic;
using LoadOrderTool.Util;
using CO.PlatformServices;
using LoadOrder.Util;

public static class DownloadStatusExtension {
public static bool IsBroken(this SteamCache.DownloadStatus status) {
Expand All @@ -27,6 +26,7 @@ public enum DownloadStatus {
OK = 1,
Unknown = 2,
OutOfDate,
CatalogOutOfDate,
NotDownloaded,
PartiallyDownloaded,
Removed,
Expand Down Expand Up @@ -93,23 +93,16 @@ public class Item {
static string FilePath => Path.Combine(DIR, FILE_NAME);

internal void Serialize() {
XmlSerializer ser = new XmlSerializer(typeof(SteamCache));
using (FileStream fs = new FileStream(FilePath, FileMode.Create, FileAccess.Write)) {
Items = itemTable_.Values.ToArray();
People = peopleTable_.Values.ToArray();

ser.Serialize(fs, this, XMLUtil.NoNamespaces);
}
Items = itemTable_.Values.ToArray();
People = peopleTable_.Values.ToArray();
LoadOrderShared.SharedUtil.Serialize(this, FilePath);
}

internal static SteamCache Deserialize() {
try {
XmlSerializer ser = new XmlSerializer(typeof(SteamCache));
using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) {
var ret = ser.Deserialize(fs) as SteamCache;
ret.BuildIndeces();
return ret;
}
var ret = LoadOrderShared.SharedUtil.Deserialize<SteamCache>(FilePath);
ret.BuildIndeces();
return ret;
} catch {
return null;
}
Expand Down
10 changes: 3 additions & 7 deletions LoadOrder/LoadOrderTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<LangVersion>latest</LangVersion>
<Description>Helps to manage your mods and assets</Description>
<Configurations>Debug;Release</Configurations>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
<DefineConstants>$(DefineConstants);TOOL</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<Deterministic>false</Deterministic>
Expand All @@ -18,11 +21,6 @@
<StartupObject>LoadOrderTool.Program</StartupObject>
<ApplicationIcon>Resources\LoadOrder.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Compile Remove="CO\Plugins\**" />
<EmbeddedResource Remove="CO\Plugins\**" />
Expand All @@ -45,8 +43,6 @@


<ItemGroup>
<Compile Include="..\LoadOrderMod\Data\LoadOrderConfig.cs" Link="Data\LoadOrderConfig.cs" />
<Compile Include="..\LoadOrderMod\Data\CSCache.cs" Link="Data\CSCache.cs" />
<Compile Include="CO\Plugins\PluginManger.cs" />
</ItemGroup>

Expand Down
34 changes: 13 additions & 21 deletions LoadOrderMod/Data/CSCache.cs → LoadOrder/Shared/CSCache.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
namespace LoadOrderShared {
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using System;

public class CSCache {
public class Item {
Expand Down Expand Up @@ -35,7 +32,7 @@ public class Asset : Item {
/// </summary>
public ulong[] MissingDir = new ulong[0];

internal Dictionary<string, Item> ItemTable = new (100000);
internal Dictionary<string, Item> ItemTable = new(100000);

public void AddItem(Item item) {
ItemTable[item.IncludedPath] = item;
Expand All @@ -48,27 +45,22 @@ public class Asset : Item {
return null;
}

public void Serialize(string dir) {
public static string FilePath => Path.Combine(SharedUtil.LocalLOMData, FILE_NAME);

public void Serialize() {
Mods = ItemTable.Values.OfType<Mod>().ToArray();
Assets = ItemTable.Values.OfType<Asset>().ToArray();
XmlSerializer ser = new XmlSerializer(typeof(CSCache));
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
using (FileStream fs = new FileStream(Path.Combine(dir, FILE_NAME), FileMode.Create, FileAccess.Write)) {
ser.Serialize(fs, this, LoadOrderConfig.NoNamespaces);
}
SharedUtil.Serialize(this, FilePath);
}
public static CSCache Deserialize(string dir) {

public static CSCache Deserialize() {
try {
XmlSerializer ser = new XmlSerializer(typeof(CSCache));
using (FileStream fs = new FileStream(Path.Combine(dir, FILE_NAME), FileMode.Open, FileAccess.Read)) {
var ret = ser.Deserialize(fs) as CSCache;
foreach (var item in ret.Mods) ret.ItemTable[item.IncludedPath] = item;
foreach (var item in ret.Assets) ret.ItemTable[item.IncludedPath] = item;
return ret;
}
} catch {
return null;
}
var ret = SharedUtil.Deserialize<CSCache>(FilePath);
foreach (var item in ret.Mods) ret.ItemTable[item.IncludedPath] = item;
foreach (var item in ret.Assets) ret.ItemTable[item.IncludedPath] = item;
return ret;
} catch { }
return null;
}
}
}
Loading

0 comments on commit ee74788

Please sign in to comment.