本文整理汇总了C#中Manifest.InitializeConfig方法的典型用法代码示例。如果您正苦于以下问题:C# Manifest.InitializeConfig方法的具体用法?C# Manifest.InitializeConfig怎么用?C# Manifest.InitializeConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Manifest
的用法示例。
在下文中一共展示了Manifest.InitializeConfig方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadMods
public static void LoadMods()
{
Log.AsyncY("LOADING MODS");
foreach (var ModPath in _modPaths)
{
foreach (var d in Directory.GetDirectories(ModPath))
{
foreach (var s in Directory.GetFiles(d, "manifest.json"))
{
if (s.Contains("StardewInjector"))
continue;
Log.AsyncG("Found Manifest: " + s);
var manifest = new Manifest();
try
{
var t = File.ReadAllText(s);
if (string.IsNullOrEmpty(t))
{
Log.AsyncR($"Failed to read mod manifest '{s}'. Manifest is empty!");
continue;
}
manifest = manifest.InitializeConfig(s);
if (string.IsNullOrEmpty(manifest.EntryDll))
{
Log.AsyncR($"Failed to read mod manifest '{s}'. EntryDll is empty!");
continue;
}
}
catch (Exception ex)
{
Log.AsyncR($"Failed to read mod manifest '{s}'. Exception details:\n" + ex);
continue;
}
var targDir = Path.GetDirectoryName(s);
var psDir = Path.Combine(targDir, "psconfigs");
Log.AsyncY($"Created psconfigs directory @{psDir}");
try
{
if (manifest.PerSaveConfigs)
{
if (!Directory.Exists(psDir))
{
Directory.CreateDirectory(psDir);
Log.AsyncY($"Created psconfigs directory @{psDir}");
}
if (!Directory.Exists(psDir))
{
Log.AsyncR($"Failed to create psconfigs directory '{psDir}'. No exception occured.");
continue;
}
}
}
catch (Exception ex)
{
Log.AsyncR($"Failed to create psconfigs directory '{targDir}'. Exception details:\n" + ex);
continue;
}
var targDll = string.Empty;
try
{
targDll = Path.Combine(targDir, manifest.EntryDll);
if (!File.Exists(targDll))
{
Log.AsyncR($"Failed to load mod '{manifest.EntryDll}'. File {targDll} does not exist!");
continue;
}
var mod = Assembly.UnsafeLoadFrom(targDll);
if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0)
{
Log.AsyncY("Loading Mod DLL...");
var tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod));
var m = (Mod) mod.CreateInstance(tar.ToString());
if (m != null)
{
m.PathOnDisk = targDir;
m.Manifest = manifest;
Log.AsyncG($"LOADED MOD: {m.Manifest.Name} by {m.Manifest.Authour} - Version {m.Manifest.Version} | Description: {m.Manifest.Description} (@ {targDll})");
Constants.ModsLoaded += 1;
m.Entry();
}
}
else
{
Log.AsyncR("Invalid Mod DLL");
}
}
catch (Exception ex)
{
Log.AsyncR($"Failed to load mod '{targDll}'. Exception details:\n" + ex);
}
}
}
}
Log.AsyncG($"LOADED {Constants.ModsLoaded} MODS");
Console.Title = Constants.ConsoleTitle;
//.........这里部分代码省略.........