Add startup message

This commit is contained in:
NGnius (Graham) 2021-05-12 12:58:38 -04:00
parent 7c304c8bdc
commit 037a653eca
2 changed files with 72 additions and 26 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
@ -19,6 +20,11 @@ namespace CLre
public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
internal static Harmony harmonyInstance = null;
internal static bool _isInidicatorActive = true;
internal static string _indicatorMsg = " CLre loading...";
// called when Cardlife shuts down
public override void OnApplicationQuit()
{
@ -46,6 +52,8 @@ namespace CLre
// misc
LogIPAPlugins();
Fixes.BugfixAttributeUtility.LogBugfixes();
BuildIndicatorMessage();
API.App.Client.MenuReady += (_, __) => { _isInidicatorActive = false; }; // dismiss CLre msg
// Log info
API.Utility.Logging.MetaLog($"{Name} init complete.");
@ -103,12 +111,36 @@ namespace CLre
sb.AppendFormat("-----------------------------\n");
API.Utility.Logging.Log(sb.ToString());
}
private void BuildIndicatorMessage()
{
int fixCount = Fixes.BugfixAttributeUtility.Count;
int modCount = IllusionInjector.PluginManager.Plugins.Count();
StringBuilder sb = new StringBuilder();
sb.AppendFormat(" {0} {1}\n", Name, Version);
sb.AppendFormat("{0} bugfixes, {1} plugins, no frills", fixCount, modCount);
#if DEBUG
sb.AppendFormat(" DEBUG version\n");
#endif
#if RELEASE
sb.AppendFormat(" RELEASE version\n");
#endif
sb.AppendFormat(" Starting up...\n");
_indicatorMsg = sb.ToString();
}
public override void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 50, 50), "TEST"))
// CLre startup inidicator
if (_isInidicatorActive)
{
GUILayout.BeginVertical();
GUILayout.Label(_indicatorMsg);
if (GUILayout.Button("Hide"))
{
_isInidicatorActive = false;
}
GUILayout.EndVertical();
}
}
}

View file

@ -29,30 +29,17 @@ namespace CLre.Fixes
internal static class BugfixAttributeUtility
{
public static int Count { get; private set; }
public static void LogBugfixes()
{
List<uint> keys = new List<uint>();
Dictionary<uint, BugfixStruct> fixes = new Dictionary<uint, BugfixStruct>();
foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
{
BugfixAttribute b = t.GetCustomAttribute<BugfixAttribute>(true);
if (b != null)
{
if (!fixes.ContainsKey(b.id))
{
BugfixStruct bugfixStruct = new BugfixStruct{id = b.id};
bugfixStruct.Merge(b);
fixes[b.id] = bugfixStruct;
keys.Add(b.id);
}
else
{
BugfixStruct bugfixStruct = fixes[b.id];
bugfixStruct.Merge(b);
fixes[b.id] = bugfixStruct;
}
}
}
API.Utility.Logging.Log(BugfixMessage());
}
public static string BugfixMessage()
{
Dictionary<uint, BugfixStruct> fixes = Bugfixes();
List<uint> keys = new List<uint>(fixes.Keys);
keys.Sort();
//keys.Sort((u, u1) => u.CompareTo(u1));
StringBuilder sb = new StringBuilder();
@ -64,10 +51,37 @@ namespace CLre.Fixes
sb.Append("\n");
}
sb.AppendFormat("-----------------------------\n");
API.Utility.Logging.Log(sb.ToString());
return sb.ToString();
}
private struct BugfixStruct
public static Dictionary<uint, BugfixStruct> Bugfixes()
{
Dictionary<uint, BugfixStruct> fixes = new Dictionary<uint, BugfixStruct>();
foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
{
BugfixAttribute b = t.GetCustomAttribute<BugfixAttribute>(true);
if (b != null)
{
if (!fixes.ContainsKey(b.id))
{
BugfixStruct bugfixStruct = new BugfixStruct{id = b.id};
bugfixStruct.Merge(b);
fixes[b.id] = bugfixStruct;
}
else
{
BugfixStruct bugfixStruct = fixes[b.id];
bugfixStruct.Merge(b);
fixes[b.id] = bugfixStruct;
}
}
}
Count = fixes.Count;
return fixes;
}
public struct BugfixStruct
{
public string name;
public string description;