Remove unnecessary loading mod exceptions, log missing icon.png

This commit is contained in:
rob-v
2017-05-27 15:07:24 +02:00
committed by reaperrr
parent 04033e5c79
commit f75115a645
3 changed files with 30 additions and 18 deletions

View File

@@ -80,7 +80,7 @@ namespace OpenRA
mod.Icon = sheetBuilder.Add(bitmap); mod.Icon = sheetBuilder.Add(bitmap);
} }
mods.Add(ExternalMod.MakeKey(mod), mod); mods[ExternalMod.MakeKey(mod)] = mod;
} }
internal void Register(Manifest mod) internal void Register(Manifest mod)

View File

@@ -375,7 +375,10 @@ namespace OpenRA
ModData = null; ModData = null;
if (mod == null) if (mod == null)
throw new InvalidOperationException("Game.Mod argument missing or mod could not be found."); throw new InvalidOperationException("Game.Mod argument missing.");
if (!Mods.ContainsKey(mod))
throw new InvalidOperationException("Unknown or invalid mod '{0}'.".F(mod));
Console.WriteLine("Loading mod: {0}", mod); Console.WriteLine("Loading mod: {0}", mod);

View File

@@ -69,26 +69,38 @@ namespace OpenRA
try try
{ {
if (!Directory.Exists(path)) if (!Directory.Exists(path))
throw new InvalidDataException(path + " is not a valid mod package"); {
Log.Write("debug", path + " is not a valid mod package");
return null;
}
package = new Folder(path); package = new Folder(path);
if (!package.Contains("mod.yaml")) if (package.Contains("mod.yaml"))
throw new InvalidDataException(path + " is not a valid mod package"); {
var manifest = new Manifest(id, package);
using (var stream = package.GetStream("icon.png")) if (package.Contains("icon.png"))
if (stream != null) {
using (var bitmap = new Bitmap(stream)) using (var stream = package.GetStream("icon.png"))
icons[id] = sheetBuilder.Add(bitmap); if (stream != null)
using (var bitmap = new Bitmap(stream))
icons[id] = sheetBuilder.Add(bitmap);
}
else if (!manifest.Metadata.Hidden)
Log.Write("debug", "Mod '{0}' is missing 'icon.png'.".F(path));
return new Manifest(id, package); return manifest;
}
} }
catch (Exception) catch (Exception e)
{ {
if (package != null) Log.Write("debug", "Load mod '{0}': {1}".F(path, e));
package.Dispose();
return null;
} }
if (package != null)
package.Dispose();
return null;
} }
Dictionary<string, Manifest> GetInstalledMods(IEnumerable<string> searchPaths, IEnumerable<string> explicitPaths) Dictionary<string, Manifest> GetInstalledMods(IEnumerable<string> searchPaths, IEnumerable<string> explicitPaths)
@@ -100,9 +112,6 @@ namespace OpenRA
foreach (var pair in candidates) foreach (var pair in candidates)
{ {
var mod = LoadMod(pair.First, pair.Second); var mod = LoadMod(pair.First, pair.Second);
// Mods in the support directory and oramod packages (which are listed later
// in the CandidateMods list) override mods in the main install.
if (mod != null) if (mod != null)
ret[pair.First] = mod; ret[pair.First] = mod;
} }