summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-14 18:16:44 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-14 18:16:44 -0400
commit307304a03edb82f3a1f5cfa6c47cb17687560ccb (patch)
treefdd46e84bac0d05e4eafdbb4f05d8c5c70507a7b /src/StardewModdingAPI
parent06871a0603fa59ca6734fd913e118a4fe4a4c64c (diff)
downloadSMAPI-307304a03edb82f3a1f5cfa6c47cb17687560ccb.tar.gz
SMAPI-307304a03edb82f3a1f5cfa6c47cb17687560ccb.tar.bz2
SMAPI-307304a03edb82f3a1f5cfa6c47cb17687560ccb.zip
revert all projects except installer to .NET Framework 4.5
This caused obscure invalid-IL crashes when compiled through MonoDevelop on Linux.
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/App.config2
-rw-r--r--src/StardewModdingAPI/Events/ContentEventHandler.cs8
-rw-r--r--src/StardewModdingAPI/Events/ContentEvents.cs2
-rw-r--r--src/StardewModdingAPI/Framework/InternalExtensions.cs29
-rw-r--r--src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs4
-rw-r--r--src/StardewModdingAPI/Framework/UpdateHelper.cs7
-rw-r--r--src/StardewModdingAPI/Program.cs24
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.csproj20
-rw-r--r--src/StardewModdingAPI/packages.config4
9 files changed, 37 insertions, 63 deletions
diff --git a/src/StardewModdingAPI/App.config b/src/StardewModdingAPI/App.config
index 314845f7..27cdf0f7 100644
--- a/src/StardewModdingAPI/App.config
+++ b/src/StardewModdingAPI/App.config
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
diff --git a/src/StardewModdingAPI/Events/ContentEventHandler.cs b/src/StardewModdingAPI/Events/ContentEventHandler.cs
deleted file mode 100644
index 2a7e75d1..00000000
--- a/src/StardewModdingAPI/Events/ContentEventHandler.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace StardewModdingAPI.Events
-{
- /// <summary>Represents a method that will handle a content event.</summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The event arguments.</param>
- /// <remarks>This deviates from <see cref="System.EventHandler{T}"/> in allowing <c>T</c> to be an interface instead of a concrete class. While .NET Framework 4.5 allows that, the current .NET Framework 4.0 targeted by SMAPI to improve compatibility does not.</remarks>
- public delegate void ContentEventHandler(object sender, IContentEventHelper e);
-}
diff --git a/src/StardewModdingAPI/Events/ContentEvents.cs b/src/StardewModdingAPI/Events/ContentEvents.cs
index 339e90fd..9418673a 100644
--- a/src/StardewModdingAPI/Events/ContentEvents.cs
+++ b/src/StardewModdingAPI/Events/ContentEvents.cs
@@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events
public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged;
/// <summary>Raised when an XNB file is being read into the cache. Mods can change the data here before it's cached.</summary>
- internal static event ContentEventHandler AfterAssetLoaded;
+ internal static event EventHandler<IContentEventHelper> AfterAssetLoaded;
/*********
diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs
index 46c76656..4ca79518 100644
--- a/src/StardewModdingAPI/Framework/InternalExtensions.cs
+++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using StardewModdingAPI.Events;
namespace StardewModdingAPI.Framework
{
@@ -60,36 +59,12 @@ namespace StardewModdingAPI.Framework
/// <param name="handlers">The event handlers.</param>
/// <param name="sender">The event sender.</param>
/// <param name="args">The event arguments.</param>
- public static void SafelyRaiseGenericEvent<TEventArgs>(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender, TEventArgs args) where TEventArgs : EventArgs
+ public static void SafelyRaiseGenericEvent<TEventArgs>(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender, TEventArgs args)
{
if (handlers == null)
return;
- foreach (EventHandler<TEventArgs> handler in handlers.Cast<EventHandler<TEventArgs>>())
- {
- try
- {
- handler.Invoke(sender, args);
- }
- catch (Exception ex)
- {
- monitor.Log($"A mod failed handling the {name} event:\n{ex.GetLogSummary()}", LogLevel.Error);
- }
- }
- }
-
- /// <summary>Safely raise an <see cref="EventHandler{TEventArgs}"/> event, and intercept any exceptions thrown by its handlers.</summary>
- /// <param name="monitor">Encapsulates monitoring and logging.</param>
- /// <param name="name">The event name for error messages.</param>
- /// <param name="handlers">The event handlers.</param>
- /// <param name="sender">The event sender.</param>
- /// <param name="args">The event arguments.</param>
- public static void SafelyRaiseGenericEvent(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender, IContentEventHelper args)
- {
- if (handlers == null)
- return;
-
- foreach (ContentEventHandler handler in handlers.Cast<ContentEventHandler>())
+ foreach (EventHandler<TEventArgs> handler in Enumerable.Cast<EventHandler<TEventArgs>>(handlers))
{
try
{
diff --git a/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs b/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs
index d89e8e44..08204b7e 100644
--- a/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs
+++ b/src/StardewModdingAPI/Framework/Reflection/PrivateProperty.cs
@@ -60,7 +60,7 @@ namespace StardewModdingAPI.Framework.Reflection
{
try
{
- return (TValue)this.PropertyInfo.GetValue(this.Parent, null);
+ return (TValue)this.PropertyInfo.GetValue(this.Parent);
}
catch (InvalidCastException)
{
@@ -78,7 +78,7 @@ namespace StardewModdingAPI.Framework.Reflection
{
try
{
- this.PropertyInfo.SetValue(this.Parent, value, null);
+ this.PropertyInfo.SetValue(this.Parent, value);
}
catch (InvalidCastException)
{
diff --git a/src/StardewModdingAPI/Framework/UpdateHelper.cs b/src/StardewModdingAPI/Framework/UpdateHelper.cs
index 342a08cf..e01e55c8 100644
--- a/src/StardewModdingAPI/Framework/UpdateHelper.cs
+++ b/src/StardewModdingAPI/Framework/UpdateHelper.cs
@@ -1,6 +1,7 @@
using System.IO;
using System.Net;
using System.Reflection;
+using System.Threading.Tasks;
using Newtonsoft.Json;
using StardewModdingAPI.Framework.Models;
@@ -14,17 +15,17 @@ namespace StardewModdingAPI.Framework
*********/
/// <summary>Get the latest release from a GitHub repository.</summary>
/// <param name="repository">The name of the repository from which to fetch releases (like "cjsu/SMAPI").</param>
- public static GitRelease GetLatestVersion(string repository)
+ public static async Task<GitRelease> GetLatestVersionAsync(string repository)
{
// build request
// (avoid HttpClient for Mac compatibility)
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.github.com/repos/{repository}/releases/latest");
+ HttpWebRequest request = WebRequest.CreateHttp($"https://api.github.com/repos/{repository}/releases/latest");
AssemblyName assembly = typeof(UpdateHelper).Assembly.GetName();
request.UserAgent = $"{assembly.Name}/{assembly.Version}";
request.Accept = "application/vnd.github.v3+json";
// fetch data
- using (WebResponse response = request.GetResponse())
+ using (WebResponse response = await request.GetResponseAsync())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index 81e6518e..db7a3df6 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -187,7 +187,7 @@ namespace StardewModdingAPI
{
try
{
- GitRelease release = UpdateHelper.GetLatestVersion(Constants.GitHubRepository);
+ GitRelease release = UpdateHelper.GetLatestVersionAsync(Constants.GitHubRepository).Result;
ISemanticVersion latestVersion = new SemanticVersion(release.Tag);
if (latestVersion.IsNewerThan(Constants.ApiVersion))
this.Monitor.Log($"You can update SMAPI from version {Constants.ApiVersion} to {latestVersion}", LogLevel.Alert);
@@ -446,18 +446,26 @@ namespace StardewModdingAPI
continue;
}
- // initialise mod
+ // validate assembly
try
{
- // get mod entry type
- Type modEntryType = modAssembly.GetExportedTypes().FirstOrDefault(x => x.BaseType == typeof(Mod));
- if(modEntryType == null)
+ if (modAssembly.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) == 0)
{
- this.Monitor.Log($"{skippedPrefix} because its DLL has no {typeof(Mod).FullName} entry class.", LogLevel.Error);
+ this.Monitor.Log($"{skippedPrefix} because its DLL has no 'Mod' subclass.", LogLevel.Error);
continue;
}
-
- // get mod class
+ }
+ catch (Exception ex)
+ {
+ this.Monitor.Log($"{skippedPrefix} because its DLL couldn't be loaded.\n{ex.GetLogSummary()}", LogLevel.Error);
+ continue;
+ }
+
+ // initialise mod
+ try
+ {
+ // get implementation
+ TypeInfo modEntryType = modAssembly.DefinedTypes.First(x => x.BaseType == typeof(Mod));
Mod mod = (Mod)modAssembly.CreateInstance(modEntryType.ToString());
if (mod == null)
{
diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj
index dcb299a2..99666f08 100644
--- a/src/StardewModdingAPI/StardewModdingAPI.csproj
+++ b/src/StardewModdingAPI/StardewModdingAPI.csproj
@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>StardewModdingAPI</RootNamespace>
<AssemblyName>StardewModdingAPI</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
@@ -77,22 +77,19 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net40\Mono.Cecil.dll</HintPath>
+ <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
+ <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
+ <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
<Private>True</Private>
</Reference>
- <Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
- </Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
- <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
+ <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
@@ -117,7 +114,6 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Command.cs" />
- <Compile Include="Events\ContentEventHandler.cs" />
<Compile Include="Events\ContentEvents.cs" />
<Compile Include="Events\EventArgsValueChanged.cs" />
<Compile Include="Framework\Command.cs" />
@@ -217,10 +213,12 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
+ <None Include="packages.config">
+ <SubType>Designer</SubType>
+ </None>
<Content Include="StardewModdingAPI.config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
- <None Include="packages.config" />
<None Include="unix-launcher.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
@@ -282,4 +280,4 @@
<!-- Somehow this makes Visual Studio for Mac recognise the previous section. -->
<!-- Nobody knows why. -->
<PropertyGroup Condition="'$(RunConfiguration)' == 'Default'" />
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/StardewModdingAPI/packages.config b/src/StardewModdingAPI/packages.config
index 1dee2c2a..e5fa3c3a 100644
--- a/src/StardewModdingAPI/packages.config
+++ b/src/StardewModdingAPI/packages.config
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Mono.Cecil" version="0.9.6.4" targetFramework="net40" />
- <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net40" />
+ <package id="Mono.Cecil" version="0.9.6.4" targetFramework="net45" />
+ <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" />
</packages> \ No newline at end of file