Skip to content

Commit

Permalink
Use IFileSystemLoader for remaster content.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Sep 29, 2024
1 parent eeb8613 commit 9645e00
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 641 deletions.
89 changes: 89 additions & 0 deletions OpenRA.Mods.Mobius/FileSystem/RemasterFileSystemLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Collections.Generic;
using System.IO;
using System.Linq;
using OpenRA.Mods.Common.FileSystem;
using OpenRA.Mods.Common.Installer;

namespace OpenRA.Mods.Mobius.FileSystem
{
public class RemasterFileSystemLoader : IFileSystemLoader, IFileSystemExternalContent
{
[FieldLoader.Require]
public readonly string RemasterDataMount = null;
public readonly string InstallPromptMod = "cnccontent";
public readonly Dictionary<string, string> Packages = null;
public readonly Dictionary<string, string> RemasterPackages = null;

[FieldLoader.LoadUsing(nameof(LoadSources))]
readonly Dictionary<string, ModContent.ModSource> sources = null;

static object LoadSources(MiniYaml yaml)
{
var ret = new Dictionary<string, ModContent.ModSource>();
var sourcesNode = yaml.Nodes.Single(n => n.Key == "Sources");
foreach (var s in sourcesNode.Value.Nodes)
ret.Add(s.Key, new ModContent.ModSource(s.Value, null));

return ret;
}

bool contentAvailable = true;

public void Mount(OpenRA.FileSystem.FileSystem fileSystem, ObjectCreator objectCreator)
{
if (Packages != null)
foreach (var kv in Packages)
fileSystem.Mount(kv.Key, kv.Value);

if (RemasterPackages == null)
return;

foreach (var kv in sources)
{
var sourceResolver = objectCreator.CreateObject<ISourceResolver>($"{kv.Value.Type.Value}SourceResolver");
var path = sourceResolver.FindSourcePath(kv.Value);
if (path != null)
{
var dataPath = Path.Combine(path, "Data");
if (!Directory.Exists(dataPath))
{
contentAvailable = false;
continue;
}

fileSystem.Mount(dataPath, RemasterDataMount);
foreach (var p in RemasterPackages)
{
var package = fileSystem.OpenPackage(p.Key);
if (package == null)
{
contentAvailable = false;
continue;
}

fileSystem.Mount(package, p.Value);
}
}
}
}

bool IFileSystemExternalContent.InstallContentIfRequired(ModData modData)
{
if (!contentAvailable)
Game.InitializeMod(InstallPromptMod, new Arguments());

return !contentAvailable;
}
}
}
27 changes: 0 additions & 27 deletions OpenRA.Mods.Mobius/RemasterLoadScreen.cs

This file was deleted.

74 changes: 0 additions & 74 deletions OpenRA.Mods.Mobius/RemasterPackages.cs

This file was deleted.

91 changes: 0 additions & 91 deletions OpenRA.Mods.Mobius/UtilityCommands/RemasterCheckMissingSprites.cs

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9645e00

Please sign in to comment.