summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Program.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-11-05 16:14:38 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-11-05 16:14:38 -0400
commit0749fdcbe5d991df9e7c1ad91fd48c198fcc1dbb (patch)
tree2701183d2b28921df147002f060a6a6aa1003ae7 /src/StardewModdingAPI/Program.cs
parenta929d7043368a5aad4eb942064bec5ea8da45ea6 (diff)
downloadSMAPI-0749fdcbe5d991df9e7c1ad91fd48c198fcc1dbb.tar.gz
SMAPI-0749fdcbe5d991df9e7c1ad91fd48c198fcc1dbb.tar.bz2
SMAPI-0749fdcbe5d991df9e7c1ad91fd48c198fcc1dbb.zip
use new helper to read manifest (#159)
Diffstat (limited to 'src/StardewModdingAPI/Program.cs')
-rw-r--r--src/StardewModdingAPI/Program.cs36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index dfd8f703..c0129036 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -240,7 +240,7 @@ namespace StardewModdingAPI
{
foreach (string manifestPath in Directory.GetFiles(directory, "manifest.json"))
{
- // error format
+ ModHelper helper = new ModHelper(directory);
string errorPrefix = $"Couldn't load mod for manifest '{manifestPath}'";
// read manifest
@@ -256,7 +256,12 @@ namespace StardewModdingAPI
}
// deserialise manifest
- manifest = manifest.InitializeConfig(manifestPath);
+ manifest = helper.ReadJsonFile<Manifest>("manifest.json");
+ if (manifest == null)
+ {
+ Log.Error($"{errorPrefix}: the manifest file does not exist.");
+ continue;
+ }
if (string.IsNullOrEmpty(manifest.EntryDll))
{
Log.Error($"{errorPrefix}: manifest doesn't specify an entry DLL.");
@@ -270,12 +275,11 @@ namespace StardewModdingAPI
}
// create per-save directory
- string targDir = Path.GetDirectoryName(manifestPath);
- string psDir = Path.Combine(targDir, "psconfigs");
- try
+ if (manifest.PerSaveConfigs)
{
- if (manifest.PerSaveConfigs)
+ try
{
+ string psDir = Path.Combine(directory, "psconfigs");
Directory.CreateDirectory(psDir);
if (!Directory.Exists(psDir))
{
@@ -283,18 +287,18 @@ namespace StardewModdingAPI
continue;
}
}
- }
- catch (Exception ex)
- {
- Log.Error($"{errorPrefix}: couldm't create the per-save configuration directory ('psconfigs') requested by this mod.\n{ex}");
- continue;
+ catch (Exception ex)
+ {
+ Log.Error($"{errorPrefix}: couldm't create the per-save configuration directory ('psconfigs') requested by this mod.\n{ex}");
+ continue;
+ }
}
// load DLL & hook up mod
string targDll = string.Empty;
try
{
- targDll = Path.Combine(targDir, manifest.EntryDll);
+ targDll = Path.Combine(directory, manifest.EntryDll);
if (!File.Exists(targDll))
{
Log.Error($"{errorPrefix}: target DLL '{targDll}' does not exist.");
@@ -304,12 +308,12 @@ namespace StardewModdingAPI
Assembly modAssembly = Assembly.UnsafeLoadFrom(targDll);
if (modAssembly.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0)
{
- TypeInfo tar = modAssembly.DefinedTypes.First(x => x.BaseType == typeof(Mod));
- Mod modEntry = (Mod)modAssembly.CreateInstance(tar.ToString());
+ TypeInfo modEntryType = modAssembly.DefinedTypes.First(x => x.BaseType == typeof(Mod));
+ Mod modEntry = (Mod)modAssembly.CreateInstance(modEntryType.ToString());
if (modEntry != null)
{
- modEntry.Helper = new ModHelper(targDir);
- modEntry.PathOnDisk = targDir;
+ modEntry.Helper = helper;
+ modEntry.PathOnDisk = directory;
modEntry.Manifest = manifest;
Log.Info($"Loaded mod: {modEntry.Manifest.Name} by {modEntry.Manifest.Author}, v{modEntry.Manifest.Version} | {modEntry.Manifest.Description}\n@ {targDll}");
Program.ModsLoaded += 1;