Skip to content

Commit

Permalink
Merge pull request #128 from SubnauticaModding/QMM301BugFix
Browse files Browse the repository at this point in the history
QModManager 3.0.1 bug fix
  • Loading branch information
PrimeSonic authored Jan 15, 2020
2 parents 35a90d7 + 89aa4fd commit c568673
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 20 deletions.
Binary file modified Build/InstallerExtensions.dll
Binary file not shown.
Binary file modified Build/QModInstaller.dll
Binary file not shown.
16 changes: 16 additions & 0 deletions Build/QModInstaller.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Build/QModManager.exe
Binary file not shown.
Binary file modified Build/QModManager_Setup.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Data/latest-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.0.1
4 changes: 2 additions & 2 deletions Executable/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("3.0")]
[assembly: AssemblyFileVersion("3.0")]
[assembly: AssemblyVersion("3.0.1")]
[assembly: AssemblyFileVersion("3.0.1")]
4 changes: 2 additions & 2 deletions Installer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

[assembly: Guid("8c6c9a0b-80c4-43d2-89f2-749e6f09fdda")]

[assembly: AssemblyVersion("3.0")]
[assembly: AssemblyFileVersion("3.0")]
[assembly: AssemblyVersion("3.0.1")]
[assembly: AssemblyFileVersion("3.0.1")]
2 changes: 1 addition & 1 deletion Installer/QModsInstallerScript.iss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#endif

#define Name "QModManager" ; The name of the game will be added after it
#define Version "3.0"
#define Version "3.0.1"
#define Author "QModManager"
#define URL "https://github.com/QModManager/QModManager"
#define SupportURL "https://discord.gg/UpWuWwq"
Expand Down
10 changes: 8 additions & 2 deletions QModManager.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29102.190
# Visual Studio 15
VisualStudioVersion = 15.0.28307.960
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Executable", "Executable\Executable.csproj", "{E00B7FE8-0F1D-4AE6-9E47-4BFD81537F14}"
EndProject
Expand All @@ -11,6 +11,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unit Tests", "Unit Tests\Un
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InstallerExtensions", "Installer\InstallerExtensions.csproj", "{92726127-A08F-4843-BF96-4989CE1BF422}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A8D179E-C749-4346-AD81-05F11C082A1C}"
ProjectSection(SolutionItems) = preProject
Data\latest-version.txt = Data\latest-version.txt
Installer\QModsInstallerScript.iss = Installer\QModsInstallerScript.iss
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
15 changes: 15 additions & 0 deletions QModManager/Patching/IQModFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace QModManager.Patching
{
internal interface IQModFactory
{
/// <summary>
/// Searches through all folders in the provided directory and returns an ordered list of mods to load.<para/>
/// Mods that cannot be loaded will have an unsuccessful <see cref="QMod.Status"/> value.
/// </summary>
/// <param name="qmodsDirectory">The QMods directory</param>
/// <returns>A new, sorted <see cref="List{QMod}"/> ready to be initialized or skipped.</returns>
List<QMod> BuildModLoadingList(string qmodsDirectory);
}
}
2 changes: 2 additions & 0 deletions QModManager/Patching/ManifestValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public ModStatus ValidateManifest(QMod mod, string subDirectory)
versionedDependencies.Add(new RequiredQMod(item.Key));
}
}

mod.RequiredMods = versionedDependencies;
}

if (!mod.Enable)
Expand Down
11 changes: 8 additions & 3 deletions QModManager/Patching/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal static void Patch()
Patched = true;

Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}...");
Logger.Info($"Today is {DateTime.Today:dd-MMMM-yyyy}");

if (QModBaseDir == null)
{
Expand Down Expand Up @@ -97,7 +98,7 @@ internal static void Patch()

AddAssemblyResolveEvent();

var modFactory = new QModFactory();
IQModFactory modFactory = new QModFactory();
List<QMod> modsToLoad = modFactory.BuildModLoadingList(QModBaseDir);

QModServices.LoadKnownMods(modsToLoad);
Expand All @@ -111,7 +112,7 @@ internal static void Patch()
{
if (mod.IsLoaded)
loadedMods++;
else
else if (mod.Enable)
erroredMods++;
}

Expand All @@ -120,7 +121,11 @@ internal static void Patch()
Logger.Info($"Finished loading QModManager. Loaded {loadedMods} mods");

if (ErrorModCount > 0)
Logger.Warn($"A total of {ErrorModCount} mods failed to load");
{
string msg = $"A total of {ErrorModCount} mods failed to load";
Logger.Warn(msg);
Dialog.Show(msg + "\nSee log file for details.", Dialog.Button.close, Dialog.Button.Disabled, false);
}

SummaryLogger.LogSummaries(modsToLoad);
}
Expand Down
18 changes: 11 additions & 7 deletions QModManager/Patching/QModFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
using QModManager.DataStructures;
using QModManager.Utility;

internal class QModFactory
internal class QModFactory : IQModFactory
{
internal static readonly ManifestValidator Validator = new ManifestValidator();

internal List<QMod> BuildModLoadingList(string qmodsDirectory)
/// <summary>
/// Searches through all folders in the provided directory and returns an ordered list of mods to load.<para/>
/// Mods that cannot be loaded will have an unsuccessful <see cref="QMod.Status"/> value.
/// </summary>
/// <param name="qmodsDirectory">The QMods directory</param>
/// <returns>A new, sorted <see cref="List{QMod}"/> ready to be initialized or skipped.</returns>
public List<QMod> BuildModLoadingList(string qmodsDirectory)
{
if (!Directory.Exists(qmodsDirectory))
{
Expand Down Expand Up @@ -68,12 +74,10 @@ internal List<QMod> BuildModLoadingList(string qmodsDirectory)

List<QMod> modsToLoad = modSorter.GetSortedList();

List<QMod> modList = CreateModStatusList(earlyErrors, modsToLoad);

return modList;
return CreateModStatusList(earlyErrors, modsToLoad);
}

private static List<QMod> CreateModStatusList(List<QMod> earlyErrors, List<QMod> modsToLoad)
internal static List<QMod> CreateModStatusList(List<QMod> earlyErrors, List<QMod> modsToLoad)
{
var modList = new List<QMod>(modsToLoad.Count + earlyErrors.Count);

Expand All @@ -99,7 +103,7 @@ private static List<QMod> CreateModStatusList(List<QMod> earlyErrors, List<QMod>

foreach (RequiredQMod requiredMod in mod.RequiredMods)
{
QMod dependency = modList.Find(d => d.Id == requiredMod.Id);
QMod dependency = modsToLoad.Find(d => d.Id == requiredMod.Id);

if (dependency == null || dependency.Status != ModStatus.Success)
{
Expand Down
4 changes: 2 additions & 2 deletions QModManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("3.0.0")]
[assembly: AssemblyFileVersion("3.0.0")]
[assembly: AssemblyVersion("3.0.1")]
[assembly: AssemblyFileVersion("3.0.1")]

[assembly: InternalsVisibleTo("QMMTests")]
[assembly: InternalsVisibleTo("QModManager")]
1 change: 1 addition & 0 deletions QModManager/QModManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<Compile Include="Patching\FatalPatchingException.cs" />
<Compile Include="Patching\GameDetector.cs" />
<Compile Include="Patching\Initializer.cs" />
<Compile Include="Patching\IQModFactory.cs" />
<Compile Include="Patching\ManifestValidator.cs" />
<Compile Include="Patching\Patcher.cs" />
<Compile Include="Patching\IQModSerialiable.cs" />
Expand Down
84 changes: 84 additions & 0 deletions Unit Tests/QModFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
namespace QMMTests
{
using System;
using System.Collections.Generic;
using NUnit.Framework;
using QModManager.API;
using QModManager.API.ModLoading;
using QModManager.Patching;

[TestFixture]
internal class QModFactoryTests
{
[Test]
public void CreateModStatusList_EarlyErrorsCombineWithSuccessfullMods()
{
// Arange
var earlyErrors = new List<QMod>
{
new QMod {Id = "1", Status = ModStatus.CanceledByUser },
new QMod {Id = "2", Status = ModStatus.InvalidCoreInfo },
new QMod {Id = "3", Status = ModStatus.MissingAssemblyFile },
new QMod {Id = "4", Status = ModStatus.MissingDependency },
new QMod {Id = "5", Status = ModStatus.MissingPatchMethod },
};

var modsToLoad = new List<QMod>
{
new QMod { Id = "6", Status = ModStatus.Success },
new QMod { Id = "7", Status = ModStatus.Success },
new QMod { Id = "8", Status = ModStatus.Success },
};

// Act
List<QMod> combinedList = QModFactory.CreateModStatusList(earlyErrors, modsToLoad);

Assert.AreEqual(earlyErrors.Count + modsToLoad.Count, combinedList.Count);

foreach (QMod erroredMod in earlyErrors)
Assert.IsTrue(combinedList.Contains(erroredMod));

foreach (QMod readyMod in modsToLoad)
Assert.IsTrue(combinedList.Contains(readyMod));
}

[TestCase("0", ModStatus.MissingDependency)]
[TestCase("5", ModStatus.MissingDependency)]
[TestCase("7", ModStatus.OutOfDateDependency)]
public void CreateModStatusList_WhenMissingVersionDependencies_StatusUpdates(string missingOrOutdatedMod, ModStatus expectedStatus)
{
// Arange
var earlyErrors = new List<QMod>
{
new QMod {Id = "5", Status = ModStatus.MissingPatchMethod },
};

var modToInspect = new QMod
{
Id = "8",
Status = ModStatus.Success,
RequiredMods = new List<RequiredQMod>
{
new RequiredQMod(missingOrOutdatedMod, new Version(1, 0, 2))
}
};

var modsToLoad = new List<QMod>
{
new QMod { Id = "6", Status = ModStatus.Success },
new QMod
{
Id = "7", Status = ModStatus.Success,
ParsedVersion = new Version(1, 0, 1)
},
modToInspect
};

// Act
List<QMod> combinedList = QModFactory.CreateModStatusList(earlyErrors, modsToLoad);

// Assert
Assert.AreEqual(expectedStatus, modToInspect.Status);
}
}
}
1 change: 1 addition & 0 deletions Unit Tests/Unit Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ModLoadingSimulationTests.cs" />
<Compile Include="QModFactoryTests.cs" />
<Compile Include="SortedTreeTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestPatchClass.cs" />
Expand Down

0 comments on commit c568673

Please sign in to comment.