Skip to content

Commit

Permalink
Manifeset support for multiple games
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathWeasel1337 committed Aug 28, 2021
1 parent 8deea4b commit 58659a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions BepisPlugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Global
src\Core_ExtensibleSaveFormat_Studio\Core_ExtensibleSaveFormat_Studio.projitems*{20fd60f3-3086-4a25-876b-e977bda46687}*SharedItemsImports = 13
src\AIHS2_Core_Screencap\AIHS2_Core_Screencap.projitems*{2c5bcf22-76b1-42d5-b078-fa8bd529bfd5}*SharedItemsImports = 4
src\Shared\Shared.projitems*{2c5bcf22-76b1-42d5-b078-fa8bd529bfd5}*SharedItemsImports = 4
src\Shared\Shared.projitems*{2c8dc4c7-99a4-45e1-b379-e67111810926}*SharedItemsImports = 4
src\Core_SliderUnlocker\Core_SliderUnlocker.projitems*{2df3121a-62de-451b-9854-bcda34b200f2}*SharedItemsImports = 4
src\Shared\Shared.projitems*{2df3121a-62de-451b-9854-bcda34b200f2}*SharedItemsImports = 4
src\Core_ExtensibleSaveFormat\Core_ExtensibleSaveFormat.projitems*{303c404b-9d91-4622-9b8b-8415e0de6a8f}*SharedItemsImports = 4
Expand Down
11 changes: 11 additions & 0 deletions src/Core_Sideloader/Core.Sideloader.Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ public partial class Manifest
/// <summary>
/// Game the mod is made for. If specified, the mod will only load for that game. If not specified will load on any game.
/// </summary>
[Obsolete("Use Games instead")]
public string Game => manifestDocument.Root?.Element("game")?.Value;

private readonly List<string> _Games = new List<string>();
/// <summary>
/// Games the mod is made for. If specified, the mod will only load for those games. If not specified will load on any game.
/// </summary>
public List<string> Games => _Games;
/// <summary>
/// List of all migration info for this mod
/// </summary>
Expand All @@ -64,6 +71,10 @@ internal Manifest(Stream stream)
{
using (XmlReader reader = XmlReader.Create(stream))
manifestDocument = XDocument.Load(reader);

foreach (var element in manifestDocument.Root?.Elements("game"))
if (element != null && !element.Value.IsNullOrWhiteSpace())
_Games.Add(element.Value);
}

internal void LoadMigrationInfo()
Expand Down
18 changes: 16 additions & 2 deletions src/Core_Sideloader/Core.Sideloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,23 @@ private void LoadModsFromDirectories(params string[] modDirectories)
if (Manifest.TryLoadFromZip(archive, out Manifest manifest))
{
//Skip the mod if it is not for this game
if (!manifest.Game.IsNullOrWhiteSpace() && !GameNameList.Contains(manifest.Game.ToLower().Replace("!", "")))
bool allowed = false;
if (manifest.Games.Count == 0)
allowed = true;
else
{
foreach (var gameName in manifest.Games)
{
if (GameNameList.Contains(gameName.ToLower()))
{
allowed = true;
break;
}
}
}
if (!allowed)
{
Logger.LogInfo($"Skipping archive \"{GetRelativeArchiveDir(archivePath)}\" because it's meant for {manifest.Game}");
Logger.LogInfo($"Skipping archive \"{GetRelativeArchiveDir(archivePath)}\" because it's meant for {string.Join(", ", manifest.Games.ToArray())}");
return null;
}
Expand Down

0 comments on commit 58659a7

Please sign in to comment.