Skip to content

Commit fe7ac85

Browse files
committed
fix for #5 , #6 , #7 and rebuilt framework for mod priority system
1 parent 443a8d3 commit fe7ac85

18 files changed

+388
-331
lines changed

PandoraPlus/MVVM/Data/NemesisModInfoProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public class NemesisModInfoProvider : IModInfoProvider
2020
public async Task<List<IModInfo>> GetInstalledMods(string folderPath)
2121
{
2222
List<IModInfo> infoList = new List<IModInfo>();
23+
2324
if (!Path.Exists(folderPath)) return infoList;
25+
2426
string[] folders = Directory.GetDirectories(folderPath);
2527
foreach (string folder in folders)
2628
{

PandoraPlus/MVVM/Model/IModInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ public interface IModInfo
2323

2424

2525
public bool Active { get; set; }
26+
27+
public UInt32 Priority { get; }
2628
}
2729
}

PandoraPlus/MVVM/Model/NemesisModInfo.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ public class NemesisModInfo : IModInfo
1818

1919
public Dictionary<string, string> StringProperties { get; private set; } = new Dictionary<string, string>();
2020

21-
public string Name { get; set; } = "Default";
21+
public string Name { get; private set; } = "Default";
2222

23-
public string Author { get; set; } = "Default";
24-
public string URL { get; set; } = "Default";
23+
public string Author { get; private set; } = "Default";
24+
public string URL { get; private set; } = "Default";
2525

26-
public string Code { get; set; } = "Default";
26+
public string Code { get; private set; } = "Default";
2727

2828
public Version Version { get; } = new Version(1,0,0);
2929

30+
public UInt32 Priority { get; private set; } = 0;
31+
3032
//internal string Auto { get; set; } = "Default";
3133
//internal string RequiredFile { get; set; } = "Default";
3234
//internal string FileToCopy { get; set; } = "Default";
3335
//internal bool Hidden { get; set; } = false;
34-
public bool Valid { get; set; } = false;
36+
public bool Valid { get; private set; } = false;
3537

3638
public NemesisModInfo()
3739
{

PandoraPlus/MVVM/ViewModel/EngineViewModel.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ public EngineViewModel(IModInfoProvider modinfoProvider)
6868
public async Task LoadAsync()
6969
{
7070

71-
List<IModInfo> modInfos;
71+
List<IModInfo> modInfos = new List<IModInfo>();
7272
#if DEBUG
7373
modInfos = await modinfoProvider?.GetInstalledMods("C:\\Games\\Skyrim Modding\\Creation Tools\\Skyrim.Behavior.Tool\\PandoraTEST\\Pandora_Engine\\mod")!;
74-
modInfos.AddRange(await modinfoProvider?.GetInstalledMods(Directory.GetCurrentDirectory() + "\\Nemesis_Engine\\mod")!);
75-
modInfos.AddRange(await modinfoProvider?.GetInstalledMods(Directory.GetCurrentDirectory() + "\\Pandora_Engine\\mod")!);
76-
#else
77-
modInfos = await modinfoProvider?.GetInstalledMods(Directory.GetCurrentDirectory()+ "\\Pandora_Engine\\mod")!;
78-
modInfos.AddRange(await modinfoProvider?.GetInstalledMods(Directory.GetCurrentDirectory()+ "\\Nemesis_Engine\\mod")!);
7974
#endif
75+
modInfos.AddRange(await modinfoProvider?.GetInstalledMods(Directory.GetCurrentDirectory() + "\\Nemesis_Engine\\mod")!);
76+
modInfos.AddRange(await modinfoProvider?.GetInstalledMods(Directory.GetCurrentDirectory() + "\\Pandora_Engine\\mod")!);
77+
8078

8179
foreach (var modInfo in modInfos)
8280
{
@@ -106,10 +104,14 @@ internal async Task WriteLogBox(string text)
106104
LogText = sb.ToString();
107105
}
108106

109-
private void LoadActiveMods()
107+
private bool LoadActiveMods()
110108
{
111-
if (!activeModConfig.Exists) return;
112-
109+
if (!activeModConfig.Exists) return false;
110+
foreach(var mod in Mods)
111+
{
112+
if (mod == null) continue;
113+
mod.Active = false;
114+
}
113115
using (var readStream = activeModConfig.OpenRead())
114116
{
115117
using (var streamReader = new StreamReader(readStream))
@@ -126,7 +128,7 @@ private void LoadActiveMods()
126128

127129

128130
}
129-
131+
return true;
130132
}
131133
private void SaveActiveMods(List<IModInfo> activeMods)
132134
{
Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
using System;
1+
using Pandora.Core;
2+
using System;
23
using System.Xml;
34
using System.Xml.Linq;
45

5-
namespace Pandora.Patch.Patchers.Skyrim.Hkx
6-
{
7-
public class AppendElementChange : IPackFileChange
8-
{
9-
public IPackFileChange.ChangeType Type { get; } = IPackFileChange.ChangeType.Append;
10-
11-
public XmlNodeType AssociatedType { get; } = XmlNodeType.Element;
6+
namespace Pandora.Patch.Patchers.Skyrim.Hkx;
127

13-
public string Path { get; private set; }
8+
public class AppendElementChange : IPackFileChange
9+
{
10+
public IPackFileChange.ChangeType Type { get; } = IPackFileChange.ChangeType.Append;
1411

15-
private XElement element { get; set; }
12+
public XmlNodeType AssociatedType { get; } = XmlNodeType.Element;
1613

17-
public string ModName { get; private set; }
14+
public string Path { get; private set; }
1815

19-
public AppendElementChange(string path, XElement element, string modName)
20-
{
21-
Path = path;
22-
this.element = element;
23-
ModName = modName;
24-
}
25-
public bool Apply(PackFile packFile)
26-
{
27-
if (!packFile.Map.PathExists(Path)) return false;
28-
string newPath = PackFileEditor.AppendElement(packFile, Path, element);
29-
Path = String.IsNullOrEmpty(newPath) ? Path : newPath;
30-
return packFile.Map.PathExists(Path);
16+
private XElement element { get; set; }
3117

32-
}
18+
public IModInfo Origin { get; private set; }
3319

34-
public bool Revert(PackFile packFile)
35-
{
36-
if (!packFile.Map.PathExists(Path)) return false;
37-
PackFileEditor.RemoveElement(packFile, Path);
38-
return true;
39-
}
20+
public AppendElementChange(string path, XElement element, IModInfo modInfo)
21+
{
22+
Path = path;
23+
this.element = element;
24+
Origin = modInfo;
4025
}
26+
public bool Apply(PackFile packFile)
27+
{
28+
if (!packFile.Map.PathExists(Path)) return false;
29+
string newPath = PackFileEditor.AppendElement(packFile, Path, element);
30+
Path = String.IsNullOrEmpty(newPath) ? Path : newPath;
31+
return packFile.Map.PathExists(Path);
4132

33+
}
4234

43-
44-
35+
public bool Revert(PackFile packFile)
36+
{
37+
if (!packFile.Map.PathExists(Path)) return false;
38+
PackFileEditor.RemoveElement(packFile, Path);
39+
return true;
40+
}
4541
}
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
1-
using System;
1+
using Pandora.Core;
2+
using System;
23
using System.Xml;
34
using System.Xml.Linq;
45

5-
namespace Pandora.Patch.Patchers.Skyrim.Hkx
6+
namespace Pandora.Patch.Patchers.Skyrim.Hkx;
7+
8+
public class InsertElementChange : IPackFileChange
69
{
7-
public class InsertElementChange : IPackFileChange
8-
{
9-
public IPackFileChange.ChangeType Type { get; } = IPackFileChange.ChangeType.Insert;
10-
11-
public XmlNodeType AssociatedType { get; } = XmlNodeType.Element;
12-
13-
public string Path { get; private set; }
14-
15-
private XElement element { get; set; }
16-
17-
public string ModName { get; private set; }
18-
19-
public InsertElementChange(string path, XElement element, string modName)
20-
{
21-
Path = path;
22-
this.element = element;
23-
ModName = modName;
24-
}
25-
public bool Apply(PackFile packFile)
26-
{
27-
string newPath = PackFileEditor.InsertElement(packFile, Path, element);
28-
Path = String.IsNullOrEmpty(newPath) ? Path : newPath;
29-
return packFile.Map.PathExists(Path);
30-
31-
}
32-
33-
public bool Revert(PackFile packFile)
34-
{
35-
if (!packFile.Map.PathExists(Path)) return false;
36-
PackFileEditor.RemoveElement(packFile, Path);
37-
return true;
38-
}
39-
}
10+
public IPackFileChange.ChangeType Type { get; } = IPackFileChange.ChangeType.Insert;
4011

12+
public XmlNodeType AssociatedType { get; } = XmlNodeType.Element;
4113

14+
public string Path { get; private set; }
4215

16+
private XElement element { get; set; }
4317

18+
public IModInfo Origin { get; private set; }
19+
20+
public InsertElementChange(string path, XElement element, IModInfo modInfo)
21+
{
22+
Path = path;
23+
this.element = element;
24+
Origin = modInfo;
25+
}
26+
public bool Apply(PackFile packFile)
27+
{
28+
string newPath = PackFileEditor.InsertElement(packFile, Path, element);
29+
Path = String.IsNullOrEmpty(newPath) ? Path : newPath;
30+
return packFile.Map.PathExists(Path);
31+
32+
}
33+
34+
public bool Revert(PackFile packFile)
35+
{
36+
if (!packFile.Map.PathExists(Path)) return false;
37+
PackFileEditor.RemoveElement(packFile, Path);
38+
return true;
39+
}
4440
}

PandoraPlus/Patch/Patchers/Skyrim/Hkx/Changes/InsertTextChange.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Xml;
1+
using Pandora.Core;
2+
using System.Xml;
23

34
namespace Pandora.Patch.Patchers.Skyrim.Hkx
45
{
@@ -11,13 +12,13 @@ public class InsertTextChange : IPackFileChange
1112
public string Path { get; private set; }
1213
private string value { get; set; }
1314

14-
public string ModName { get; private set; }
15+
public IModInfo Origin { get; private set; }
1516

16-
public InsertTextChange(string path, string value, string modName)
17+
public InsertTextChange(string path, string value, IModInfo modInfo)
1718
{
1819
Path = path;
1920
this.value = value;
20-
ModName = modName;
21+
Origin = modInfo;
2122
}
2223

2324
public bool Apply(PackFile packFile)
Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
using System;
1+
using Pandora.Core;
2+
using System;
23
using System.Xml;
34
using System.Xml.Linq;
45

5-
namespace Pandora.Patch.Patchers.Skyrim.Hkx
6+
namespace Pandora.Patch.Patchers.Skyrim.Hkx;
7+
8+
public class RemoveElementChange : IPackFileChange
69
{
7-
public class RemoveElementChange : IPackFileChange
8-
{
9-
public IPackFileChange.ChangeType Type { get; } = IPackFileChange.ChangeType.Remove;
10-
11-
public XmlNodeType AssociatedType { get; } = XmlNodeType.Element;
12-
13-
public string Path { get; private set; }
14-
15-
private XElement? element { get; set; }
16-
17-
public string ModName { get; private set; }
18-
public RemoveElementChange(string path, string modName)
19-
{
20-
Path = path;
21-
ModName = modName;
22-
}
23-
public bool Apply(PackFile packFile)
24-
{
25-
if (!packFile.Map.PathExists(Path)) return false;
26-
element = PackFileEditor.RemoveElement(packFile, Path);
27-
return !packFile.Map.PathExists(Path);
28-
29-
}
30-
31-
public bool Revert(PackFile packFile)
32-
{
33-
if (element == null) return false;
34-
string newPath = PackFileEditor.InsertElement(packFile, Path, element);
35-
Path = String.IsNullOrEmpty(newPath) ? Path : newPath;
36-
return packFile.Map.PathExists(Path);
37-
}
38-
}
10+
public IPackFileChange.ChangeType Type { get; } = IPackFileChange.ChangeType.Remove;
3911

12+
public XmlNodeType AssociatedType { get; } = XmlNodeType.Element;
4013

14+
public string Path { get; private set; }
4115

16+
private XElement? element { get; set; }
17+
18+
public IModInfo Origin { get; private set; }
19+
public RemoveElementChange(string path, IModInfo modInfo)
20+
{
21+
Path = path;
22+
Origin = modInfo;
23+
}
24+
public bool Apply(PackFile packFile)
25+
{
26+
if (!packFile.Map.PathExists(Path)) return false;
27+
element = PackFileEditor.RemoveElement(packFile, Path);
28+
return !packFile.Map.PathExists(Path);
4229

30+
}
4331

32+
public bool Revert(PackFile packFile)
33+
{
34+
if (element == null) return false;
35+
string newPath = PackFileEditor.InsertElement(packFile, Path, element);
36+
Path = String.IsNullOrEmpty(newPath) ? Path : newPath;
37+
return packFile.Map.PathExists(Path);
38+
}
4439
}

PandoraPlus/Patch/Patchers/Skyrim/Hkx/Changes/RemoveTextChange.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Xml;
1+
using Pandora.Core;
2+
using System.Xml;
23

34
namespace Pandora.Patch.Patchers.Skyrim.Hkx
45
{
@@ -11,12 +12,12 @@ public class RemoveTextChange : IPackFileChange
1112
public string Path { get; private set; }
1213
private string value { get; set; }
1314

14-
public string ModName { get; private set; }
15-
public RemoveTextChange(string path, string value, string modName)
15+
public IModInfo Origin { get; private set; }
16+
public RemoveTextChange(string path, string value, IModInfo modInfo)
1617
{
1718
Path = path;
1819
this.value = value;
19-
ModName = modName;
20+
Origin = modInfo;
2021
}
2122

2223
public bool Apply(PackFile packFile)

PandoraPlus/Patch/Patchers/Skyrim/Hkx/Changes/ReplaceElementChange.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Xml;
1+
using Pandora.Core;
2+
using System.Xml;
23
using System.Xml.Linq;
34

45
namespace Pandora.Patch.Patchers.Skyrim.Hkx
@@ -16,13 +17,13 @@ public class ReplaceElementChange : IPackFileChange
1617
//public XElement oldElement { get; private set; }
1718
private XElement element { get; set; }
1819

19-
public string ModName { get; private set; }
20+
public IModInfo Origin { get; private set; }
2021

21-
public ReplaceElementChange(string path, XElement element, string modName)
22+
public ReplaceElementChange(string path, XElement element, IModInfo modInfo)
2223
{
2324
Path = path;
2425
this.element = element;
25-
ModName = modName;
26+
Origin = modInfo;
2627
}
2728
public bool Apply(PackFile packFile)
2829
{

0 commit comments

Comments
 (0)