Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #74 from V10lator/modName
Browse files Browse the repository at this point in the history
ModLoader: Set the mods name in case it's NULL or empty.
  • Loading branch information
ikkentim authored Sep 7, 2016
2 parents 17bbc43 + 7024595 commit 3c46dab
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ParkitectNexus.Mod.ModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ParkitectNexusClient
// ParkitectNexusClient
// Copyright (C) 2016 ParkitectNexus, Tim Potze
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -68,6 +68,19 @@ private static void SetProperty<T>(object @object, string propertyName, T value)
}
}

private static T GetProperty<T>(object @object, string propertyName)
{
var property = @object.GetType ()
.GetProperty (propertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null,
typeof (T), new Type [0], null);

if (property == null)
return default(T);

var ret = property.GetValue (@object, null);
return (T)ret;
}

private static void LogToMod(string folder, string level, string format, params object[] args)
{
File.AppendAllText(FPath.Combine(folder, "mod.log"),
Expand Down Expand Up @@ -153,6 +166,8 @@ public void LoadMods()
// Bind additional mod information.
SetProperty(userMod, "Path", folder);
SetProperty(userMod, "Identifier", directoryName);
if(String.IsNullOrEmpty(GetProperty<String>(userMod, "Name")))
SetProperty(userMod, "Name", directoryName.Split('@')[1]);

ModManager.Instance.addMod(userMod, (int) priority);
_loadedMods.Add(userMod);
Expand Down

0 comments on commit 3c46dab

Please sign in to comment.