diff --git a/openBVE/OpenBve/PluginManager.cs b/openBVE/OpenBve/PluginManager.cs index ed60e1b..1519834 100644 --- a/openBVE/OpenBve/PluginManager.cs +++ b/openBVE/OpenBve/PluginManager.cs @@ -576,50 +576,52 @@ namespace OpenBve { // load ats config internal static bool LoadAtsConfig(string TrainPath, System.Text.Encoding Encoding, TrainManager.Train Train) { string atsConfigFile = Interface.GetCombinedFileName(TrainPath, "ats.cfg"); + if (!System.IO.File.Exists(atsConfigFile)) { + return false; + } + + if (Program.CurrentPlatform != Program.Platform.Windows) { + Interface.AddMessage(Interface.MessageType.Information, false, "Train plugins are not supported on operating systems other than Windows. The built-in safety systems will be used for this train, which might not be compatible with the route."); + return false; + } + + if (IntPtr.Size != 4) { + Interface.AddMessage(Interface.MessageType.Information, false, "Train plugins are not supported in 64-bit environments. The built-in safety systems will be used for this train, which might not be compatible with the route."); + return false; + } + + string dllTitle = System.IO.File.ReadAllText(atsConfigFile, Encoding).Trim(); + if (!dllTitle.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { + Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " must have the extension .dll in " + atsConfigFile); + return false; + } + + string dllFile = Interface.GetCombinedFileName(TrainPath, dllTitle); + if (!System.IO.File.Exists(dllFile)) { + Interface.AddMessage(Interface.MessageType.Error, true, "The train plugin " + dllTitle + " could not be found in " + atsConfigFile); + return false; + } + + if (!CheckDllHeader(dllFile)) { + Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " is of an unsupported binary format or could not be read in " + atsConfigFile); + return false; + } + + // Finally, made it! + PluginLoadState state = LoadPlugin(dllFile, Train); + switch (state) { + case PluginLoadState.Successful: + return true; + + case PluginLoadState.CouldNotLoadDll: + Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " could not be loaded in " + atsConfigFile); + return false; + case PluginLoadState.InvalidPluginVersion: + Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " is of an unsupported version in " + atsConfigFile); + return false; + default: + return false; + } - if (System.IO.File.Exists(atsConfigFile)) { - string dllTitle = System.IO.File.ReadAllText(atsConfigFile, Encoding).Trim(); - if (dllTitle.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { - string dllFile = Interface.GetCombinedFileName(TrainPath, dllTitle); - if (System.IO.File.Exists(dllFile)) { - if (Program.CurrentPlatform == Program.Platform.Windows) { - if (IntPtr.Size == 4) { - if (CheckDllHeader(dllFile)) { - PluginLoadState state = LoadPlugin(dllFile, Train); - switch (state) { - case PluginLoadState.CouldNotLoadDll: - Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " could not be loaded in " + atsConfigFile); - return false; - case PluginLoadState.InvalidPluginVersion: - Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " is of an unsupported version in " + atsConfigFile); - return false; - case PluginLoadState.Successful: - return true; - default: - return false; - } - } else { - Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " is of an unsupported binary format or could not be read in " + atsConfigFile); - return false; - } - } else { - Interface.AddMessage(Interface.MessageType.Information, false, "Train plugins are not supported in 64-bit environments. The built-in safety systems will be used for this train, which might not be compatible with the route."); - return false; - } - } else { - Interface.AddMessage(Interface.MessageType.Information, false, "Train plugins are not supported on operating systems other than Windows. The built-in safety systems will be used for this train, which might not be compatible with the route."); - return false; - } - } else { - Interface.AddMessage(Interface.MessageType.Error, true, "The train plugin " + dllTitle + " could not be found in " + atsConfigFile); - return false; - } - } else { - Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + dllTitle + " must have the extension .dll in " + atsConfigFile); - return false; - } - } else { - return false; - } } // check dll header