Skip to content

Commit

Permalink
Update per blizzy78/ksp_toolbar#39 to prevent NotSupportedException. …
Browse files Browse the repository at this point in the history
…(Applies to KAC and KS wrappers as well.)
  • Loading branch information
Kerbas-ad-astra committed Oct 20, 2016
1 parent 012a89f commit 7b1e34e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
29 changes: 18 additions & 11 deletions Source/lib/KACWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;

Expand Down Expand Up @@ -72,10 +71,14 @@ public static Boolean InitKACWrapper()
LogFormatted("Attempting to Grab KAC Types...");

//find the base type
KACType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "KerbalAlarmClock.KerbalAlarmClock");
KACType = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == "KerbalAlarmClock.KerbalAlarmClock")
{
KACType = t;
}
});

if (KACType == null)
{
Expand All @@ -88,12 +91,16 @@ public static Boolean InitKACWrapper()
//No TimeEntry or alarmchoice options = need a newer version
NeedUpgrade = true;
}

//now the Alarm Type
KACAlarmType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "KerbalAlarmClock.KACAlarm");

//now the Alarm Type
KACAlarmType = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == "KerbalAlarmClock.KACAlarm")
{
KACAlarmType = t;
}
});

if (KACAlarmType == null)
{
Expand Down
14 changes: 9 additions & 5 deletions Source/lib/KerbalStatsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
using UnityEngine;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System;

namespace ExtraplanetaryLaunchpads.KerbalStats {
public class KerbalExt
Expand All @@ -29,10 +29,14 @@ public static string Get (ProtoCrewMember kerbal, string parms)
{
if (!initialized) {
initialized = true;
System.Type KStype = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "KerbalStats.KerbalExt");
Type KStype = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == "KerbalStats.KerbalExt")
{
KStype = t;
}
});
if (KStype == null) {
Debug.LogWarning ("KerbalStats.KerbalExt class not found.");
} else {
Expand Down
13 changes: 9 additions & 4 deletions Source/toolbar/ToolbarWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;

Expand Down Expand Up @@ -823,9 +822,15 @@ internal ToolbarTypes()

internal static Type getType(string name)
{
return AssemblyLoader.loadedAssemblies
.SelectMany(a => a.assembly.GetExportedTypes())
.SingleOrDefault(t => t.FullName == name);
Type type = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == name)
{
type = t;
}
});
return type;
}

internal static PropertyInfo getProperty(Type type, string name)
Expand Down

0 comments on commit 7b1e34e

Please sign in to comment.