Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Fixes for updated mods and installed mods which did not have their de…
Browse files Browse the repository at this point in the history
…pendencies installed
  • Loading branch information
nrgill28 committed Mar 27, 2021
1 parent 2bdc4bf commit 5493d00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 10 additions & 4 deletions DeliCounter/Backend/ModManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ internal static void UninstallMod(Mod mod)
internal static void UpdateMod(Mod mod, Version versionNumber)
{
App.RunInBackgroundThread(() =>
{
{
List<ModOperation.ModOperation> ops = new();

// Check that the requested version won't cause any issues
var notSatisfied = new List<string>();
foreach (var dependents in mod.InstalledDirectDependents)
Expand All @@ -36,17 +38,21 @@ internal static void UpdateMod(Mod mod, Version versionNumber)

foreach ((string key, Range value) in mod.Versions[versionNumber].Dependencies)
{
var dependency = ModRepository.Instance.Mods[key];
var dependency = ModRepository.Instance.Mods[key];

// If for some reason the user doesn't have a dependency installed, skip this because it will be installed later.
if (!dependency.IsInstalled) continue;

if (!value.IsSatisfied(dependency.InstalledVersion))
notSatisfied.Add(dependency.ToString());
}

if (notSatisfied.Count == 0)
ExecuteOperations(new ModOperation.ModOperation[]
ExecuteOperations(EnumerateInstallDependencies(mod, versionNumber).Concat(new ModOperation.ModOperation[]
{
new UninstallModOperation(mod),
new InstallModOperation(mod, versionNumber)
});
}));
else App.RunInMainThread(() =>
{
string op = mod.InstalledVersion < versionNumber ? "updated" : "downgraded";
Expand Down
16 changes: 14 additions & 2 deletions DeliCounter/Backend/ModRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ private void LoadModCache()
mod.InstalledVersion = cached.Version;
mod.Cached = cached;

// The version was removed or updated
// The mod wasn't in the database and we need to stub it with some random info
if (!mod.Versions.ContainsKey(mod.InstalledVersion))
{
// Just insert an empty one to allow nothing to break
mod.Versions.Add(mod.InstalledVersion,
new Mod.ModVersion
mod.Versions.Count == 0 ? new Mod.ModVersion
{
VersionNumber = mod.InstalledVersion,
Authors = Array.Empty<string>(),
Expand All @@ -239,6 +239,18 @@ private void LoadModCache()
Name = cached.Guid,
ShortDescription = "This mod has been removed from the database",
SourceUrl = ""
} :
new Mod.ModVersion
{
VersionNumber = mod.InstalledVersion,
Authors = mod.Latest.Authors,
Dependencies = mod.Latest.Dependencies,
Description = mod.Latest.Description,
IconUrl = mod.Latest.IconUrl,
InstallationSteps = Array.Empty<string>(),
Name = mod.Latest.Name,
ShortDescription = mod.Latest.ShortDescription,
SourceUrl = mod.Latest.SourceUrl
});
}
}
Expand Down

0 comments on commit 5493d00

Please sign in to comment.