Skip to content

Commit

Permalink
0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
romen-h committed Apr 24, 2022
1 parent 4166ec3 commit 43ed6b0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/ONIModLauncher/Configs/KPlayerPrefsYaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class KPlayerPrefsYaml : ConfigBase

private string filePath;

private bool configured = false;

[YamlMember]
public Dictionary<string, string> strings
{ get; set; } = new Dictionary<string, string>();
Expand Down Expand Up @@ -134,6 +136,8 @@ public KPlayerPrefsYaml()
RefreshRate = 60;
FullScreen = true;
DLC1Enabled = false;

configured = true;
}

public static KPlayerPrefsYaml Load(string file)
Expand All @@ -156,6 +160,7 @@ public static KPlayerPrefsYaml Load(string file)

public void Save()
{
if (!configured) return;
if (filePath == null) return;

var serializer = new SerializerBuilder().Build();
Expand Down
46 changes: 28 additions & 18 deletions src/ONIModLauncher/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;

Expand Down Expand Up @@ -33,40 +34,50 @@ public class ModManager
public ObservableCollection<ONIMod> Mods
{ get; private set; }

private SynchronizationContext ctx;

private ModManager()
{
//configWatcher = new FileSystemWatcher(GamePaths.ModsFolder);

Mods = new ObservableCollection<ONIMod>();
Mods.CollectionChanged += Mods_CollectionChanged;

ctx = SynchronizationContext.Current;

LoadModList(GamePaths.ModsConfigFile);
}

public void LoadModList(string path)
{
autoSaveDisabled = true;
try
ctx.Post((state) =>
{
Mods.Clear();
autoSaveDisabled = true;
try
{

modConfig = ModConfigJson.Load(path);
Mods.Clear();

foreach(var mod in modConfig.mods)
{
try
{
AddMod(mod);
}
catch (Exception ex)
modConfig = ModConfigJson.Load(path);

foreach (var mod in modConfig.mods)
{
//Debug.Fail(ex.ToString());
try
{
AddMod(mod);
}
catch (Exception ex)
{
//Debug.Fail(ex.ToString());
}
}
}
}
catch
{ }
autoSaveDisabled = false;
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
autoSaveDisabled = false;
}, null);
}

private void AddMod(ModConfigItem modListItem)
Expand Down Expand Up @@ -265,8 +276,7 @@ public void SaveModList(string path)
}
}

string json = JsonConvert.SerializeObject(modConfig, Formatting.Indented);
File.WriteAllText(path, json);
ModConfigJson.Save(modConfig, path);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ONIModLauncher/ONIModLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Description>A mod manager and launcher for Oxygen Not Included.</Description>
<PackageProjectUrl>https://github.com/romen-h/ONI-ModLauncher</PackageProjectUrl>
<RepositoryUrl>https://github.com/romen-h/ONI-ModLauncher</RepositoryUrl>
<Version>0.4.1</Version>
<Version>0.5.0</Version>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<StartupObject>ONIModLauncher.App</StartupObject>
<RootNamespace>ONIModLauncher</RootNamespace>
Expand Down

0 comments on commit 43ed6b0

Please sign in to comment.