Browse Source

Added embedded description support

pull/46/head
Anairkoen Schno 5 years ago
parent
commit
c25a251609
1 changed files with 28 additions and 0 deletions
  1. +28
    -0
      IPA.Loader/Loader/PluginLoader.cs

+ 28
- 0
IPA.Loader/Loader/PluginLoader.cs View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Version = SemVer.Version;
@ -108,6 +109,8 @@ namespace IPA.Loader
internal static List<PluginMetadata> PluginsMetadata = new List<PluginMetadata>();
private static Regex embeddedTextDescriptionPattern = new Regex(@"#!\[(.+)\]", RegexOptions.Compiled | RegexOptions.Singleline);
internal static void LoadMetadata()
{
string[] plugins = Directory.GetFiles(BeatSaber.PluginsPath, "*.dll");
@ -213,6 +216,31 @@ namespace IPA.Loader
Logger.loader.Error($"Could not load data for plugin {Path.GetFileName(plugin)}");
Logger.loader.Error(e);
}
foreach (var meta in PluginsMetadata)
{ // process description include
var lines = meta.Manifest.Description.Split('\n');
var m = embeddedTextDescriptionPattern.Match(lines[0]);
if (m.Success)
{
var name = m.Groups[1].Value;
var resc = meta.PluginType.Module.Resources.Select(r => r as EmbeddedResource)
.Where(r => r != null)
.FirstOrDefault(r => r.Name == name);
if (resc == null)
{
Logger.loader.Warn($"Could not find description file for plugin {meta.Name} ({name}); ignoring include");
meta.Manifest.Description = string.Join("\n", lines.Skip(1)); // ignore first line
continue;
}
string description;
using (var reader = new StreamReader(resc.GetResourceStream()))
description = reader.ReadToEnd();
meta.Manifest.Description = description;
}
}
}
IEnumerable<string> bareManifests = Directory.GetFiles(BeatSaber.PluginsPath, "*.json");


Loading…
Cancel
Save