// --- インターフェース関数 --- /// <summary>プラグインが読み込まれたときに呼び出される関数</summary> /// <param name="properties">読み込み時にプラグインに提供されるプロパティ</param> /// <returns>プラグインが正常にロードされたかどうか</returns> public bool Load(LoadProperties properties) { properties.Panel = new int[256]; properties.AISupport = AISupport.None; this.Train = new Train(properties.Panel, properties.PlaySound); return(true); }
// --- インターフェース関数 --- /// <summary>プラグインが読み込まれたときに呼び出される関数</summary> /// <param name="properties">読み込み時にプラグインに提供されるプロパティ</param> /// <returns>プラグインが正常にロードされたかどうか</returns> public bool Load(LoadProperties properties) { string dllPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string cfgPath = System.IO.Path.ChangeExtension(dllPath, ".cfg"); this.LoadConfig = LoadConfig.GetInstance(); LoadConfig.LoadCfgFile(cfgPath); string dllDirectory = System.IO.Path.GetDirectoryName(dllPath); string notchPath = System.IO.Path.Combine(dllDirectory, "Notch", "Notch.txt"); this.LoadPerform = LoadPerform.GetInstance(); LoadPerform.LoadCfgFile(notchPath); this.LoadCurrent = LoadCurrent.GetInstance(); LoadCurrent.LoadPowerCfg(LoadPerform.power_current_path_); LoadCurrent.LoadBrakeCfg(LoadPerform.brake_current_path_); this.LoadSwitch = LoadSwitch.GetInstance(); string dllName = System.IO.Path.GetFileNameWithoutExtension(dllPath); string exCfgPath = System.IO.Path.Combine(dllDirectory, dllName + "_openbve.cfg"); LoadSwitch.LoadCfgFile(exCfgPath); properties.Panel = new int[272]; properties.AISupport = AISupport.None; this.Train = new Train(properties.Panel, properties.PlaySound); return(true); }
public void PromoteToLoad(BatteryPropertyCode code, bool removeFromList = false) { TrippLitePropertyViewModel pm = null; foreach (var currentPm in Properties) { pm = currentPm; if (pm.Code == code) { break; } pm = null; } if (pm is null) { return; } if (removeFromList) { Properties.Remove(pm); } LoadProperties.Add(pm); }
public void DemoteFromLoad(BatteryPropertyCode code) { TrippLitePropertyViewModel pm = null; foreach (var currentPm in ProminentProperties) { pm = currentPm; if (pm.Code == code) { break; } pm = null; } if (pm is null) { return; } if (LoadProperties.Contains(pm)) { LoadProperties.Remove(pm); } Properties.Add(pm); }
// --- interface functions --- /// <summary>Is called when the plugin is loaded.</summary> /// <param name="properties">The properties supplied to the plugin on loading.</param> /// <returns>Whether the plugin was loaded successfully.</returns> public bool Load(LoadProperties properties) { properties.Panel = new int[272]; properties.AISupport = AISupport.Basic; this.Train = new Train(properties.Panel, properties.PlaySound); string configFile = Path.Combine(properties.TrainFolder, "OdakyufanAts.cfg"); string trainDatFile = Path.Combine(properties.TrainFolder, "train.dat"); if (File.Exists(configFile)) { try { this.Train.LoadConfigurationFile(configFile); return(true); } catch (Exception ex) { properties.FailureReason = "Error loading the configuration file: " + ex.Message; return(false); } } else if (File.Exists(trainDatFile)) { try { this.Train.LoadTrainDatFile(trainDatFile); return(true); } catch (Exception ex) { properties.FailureReason = "Error loading the train.dat file: " + ex.Message; return(false); } } else { properties.FailureReason = "Neither the configuration file nor the train.dat file exists."; return(false); } }
public bool Load(LoadProperties properties) { //SML Load //設定ファイル読込 //PIListに設定ファイルのPIをLoad return(false); }
/// <summary> /// Check property whether allow to lazy load /// </summary> /// <param name="property">Property</param> /// <returns>Return wheather property allow load data</returns> protected virtual bool AllowLazyLoad(string property) { if (!LoadLazyMember || LoadProperties == null || !LoadProperties.ContainsKey(property)) { return(false); } return(LoadProperties[property]); }
/// <summary>Is called when the plugin is loaded.</summary> /// <param name="properties">The properties supplied to the plugin on loading.</param> /// <returns>Whether the plugin was loaded successfully.</returns> public bool Load(LoadProperties properties) { Panel = new int[256]; Sound = new SoundHelper(properties.PlaySound, 256); properties.Panel = Panel; properties.AISupport = AISupport.None; // TODO: Your old Load code goes here. return(true); }
public bool Load(LoadProperties properties) { properties.Panel = new int[256]; panel = properties.Panel; SoundDelegate = properties.PlaySound; ATSPlugin.Cpp.Load(); ATSPlugin.Cpp.GetPluginVersion(); return(true); }
// --- functions --- internal override bool Load(VehicleSpecs specs, InitializationModes mode) { LoadProperties properties = new LoadProperties(this.PluginFolder, this.TrainFolder, this.PlaySound, this.PlaySound, this.AddInterfaceMessage, this.AddScore); bool success; try { success = this.Api.Load(properties); base.SupportsAI = properties.AISupport == AISupport.Basic; } catch (Exception ex) { if (ex is ThreadStateException) { //TTC plugin, broken when multi-threading is used success = false; properties.FailureReason = "This plugin does not function correctly with current versions of openBVE. Please ask the plugin developer to fix this."; } else { success = false; properties.FailureReason = ex.Message; } } if (success) { base.Panel = properties.Panel ?? new int[] { }; #if !DEBUG try { #endif Api.SetVehicleSpecs(specs); Api.Initialize(mode); #if !DEBUG } catch (Exception ex) { base.LastException = ex; throw; } #endif UpdatePower(); UpdateBrake(); UpdateReverser(); return(true); } else if (properties.FailureReason != null) { Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for the following reason: " + properties.FailureReason); return(false); } else { Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for an unspecified reason."); return(false); } }
/// <summary>Is called when the plugin is loaded.</summary> public bool Load(LoadProperties properties) { MessageManager.Initialise(properties.AddMessage); SoundManager.Initialise(properties.PlaySound, 256); Panel = new int[512]; Sound = new SoundHelper(properties.PlaySound, 256); properties.Panel = Panel; properties.FailureReason = $"{brand} failed to initalize, some functions might be unavailable."; properties.AISupport = AISupport.None; return(Config.Load(properties)); }
// --- インターフェース関数 --- /// <summary>プラグインが読み込まれたときに呼び出されます。</summary> /// <param name="properties">読み込み時にプラグインに提供されるプロパティ</param> /// <returns>プラグインが正常にロードされたかどうか。</returns> public bool Load(LoadProperties properties) { string dll_path = Assembly.GetExecutingAssembly().Location; string cfg_path = Path.ChangeExtension(dll_path, ".cfg"); LoadConfig load_config = LoadConfig.GetInstance(); load_config.LoadCfgFile(cfg_path); plugins_ = new List <IRuntime>(); properties_list_ = new List <LoadProperties>(); for (int i = 0; i < load_config.plugin_path_.Count; i++) { Assembly plugin; try { plugin = Assembly.LoadFile(load_config.plugin_path_[i]); } catch { return(false); } Type[] types; try { types = plugin.GetTypes(); } catch { return(false); } foreach (Type type in types) { if (typeof(IRuntime).IsAssignableFrom(type)) { if (type.FullName == null) { return(false); } plugins_.Add(plugin.CreateInstance(type.FullName) as IRuntime); properties_list_.Add(new LoadProperties(properties.PluginFolder, properties.TrainFolder, properties.PlaySound, properties.PlayCarSound, properties.AddMessage, properties.AddScore)); } } } for (int i = 0; i < plugins_.Count; i++) { if (!plugins_[i].Load(properties_list_[i])) { return(false); } } int panel_length = 0; for (int i = 0; i < properties_list_.Count; i++) { panel_length += properties_list_[i].Panel.Length - panel_length; } properties.Panel = new int[panel_length]; this.train_ = new Train(properties.Panel); return(true); }
// --- インターフェース関数 --- /// <summary>プラグインが読み込まれたときに呼び出される関数</summary> /// <param name="properties">読み込み時にプラグインに提供されるプロパティ</param> /// <returns>プラグインが正常にロードされたかどうか</returns> public bool Load(LoadProperties properties) { string dllPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string cfgPath = System.IO.Path.ChangeExtension(dllPath, ".cfg"); this.LoadConfig = LoadConfig.GetInstance(); LoadConfig.LoadCfgFile(cfgPath); properties.Panel = new int[272]; properties.AISupport = AISupport.None; this.Train = new Train(properties.Panel, properties.PlaySound); return(true); }
public bool Load(LoadProperties _p1) { LProp = _p1; playSoundDelegate = _p1.PlaySound; _p1.Panel = Panel; for (int i = 0; i < 256; i++) { emulatedSoundState[i] = -10000; } Func = new FunctionCompanion(this); Impl = new AtsProgram(this, Func); try { Impl.Load(); } catch (Exception ex) { RuntimeExceptionBlocking(ex); } return(true); }
// --- functions --- internal override bool Load(VehicleSpecs specs, InitializationModes mode) { LoadProperties properties = new LoadProperties(this.PluginFolder, this.TrainFolder, this.PlaySound, this.PlaySound, this.AddInterfaceMessage, this.AddScore); bool success; #if !DEBUG try { #endif success = this.Api.Load(properties); base.SupportsAI = properties.AISupport == AISupport.Basic; #if !DEBUG } catch (Exception ex) { base.LastException = ex; throw; } #endif if (success) { base.Panel = properties.Panel ?? new int[] { }; #if !DEBUG try { #endif Api.SetVehicleSpecs(specs); Api.Initialize(mode); #if !DEBUG } catch (Exception ex) { base.LastException = ex; throw; } #endif UpdatePower(); UpdateBrake(); UpdateReverser(); return(true); } else if (properties.FailureReason != null) { Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for the following reason: " + properties.FailureReason); return(false); } else { Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for an unspecified reason."); return(false); } }
// --- interface functions --- /// <summary>Is called when the plugin is loaded.</summary> /// <param name="properties">The properties supplied to the plugin on loading.</param> /// <returns>Whether the plugin was loaded successfully.</returns> public bool Load(LoadProperties properties) { properties.Panel = new int[272]; properties.AISupport = AISupport.Basic; this.Train = new Train(properties.Panel, properties.PlaySound); try { string file = OpenBveApi.Path.CombineFile(properties.TrainFolder, "train.dat"); if (!this.Train.LoadTrainDatFile(file)) { this.Train.AtsSx = new AtsSx(this.Train); this.Train.Devices = new Device[] { this.Train.AtsSx }; } } catch { this.Train.AtsSx = new AtsSx(this.Train); this.Train.Devices = new Device[] { this.Train.AtsSx }; } return(true); }
public bool Load(LoadProperties properties) { Win32DetailManagerPInvoke.Load(); return(true); }
public AuthnRequest() { LoadProperties.initProperties(); id = "_" + System.Guid.NewGuid().ToString(); issueInstant = System.DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"); }
// --- インターフェース関数 --- /// <summary>プラグインが読み込まれたときに呼び出されます。</summary> /// <param name="properties">読み込み時にプラグインに提供されるプロパティ</param> /// <returns>プラグインが正常にロードされたかどうか。</returns> public bool Load(LoadProperties properties) { string dll_path = Assembly.GetExecutingAssembly().Location; string cfg_path = Path.ChangeExtension(dll_path, ".cfg"); List <string> win32Dlls = new List <string>(); LoadConfig load_config = LoadConfig.GetInstance(); load_config.LoadCfgFile(cfg_path); plugins_ = new List <IRuntime>(); properties_list_ = new List <LoadProperties>(); for (int i = 0; i < load_config.plugin_path_.Count; i++) { Assembly plugin; try { plugin = Assembly.LoadFile(load_config.plugin_path_[i]); } catch (BadImageFormatException) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { win32Dlls.Add(load_config.plugin_path_[i]); continue; } else { return(false); } } catch { return(false); } Type[] types; try { types = plugin.GetTypes(); } catch { return(false); } foreach (Type type in types) { if (typeof(IRuntime).IsAssignableFrom(type)) { if (type.FullName == null) { return(false); } plugins_.Add(plugin.CreateInstance(type.FullName) as IRuntime); properties_list_.Add(new LoadProperties(properties.PluginFolder, properties.TrainFolder, properties.PlaySound, properties.PlayCarSound, properties.AddMessage, properties.AddScore)); } } } if (win32Dlls.Count > 0) { string rockOnPath = Path.Combine(properties.PluginFolder, Win32DetailManagerPInvoke.MODULE_NAME); if (!File.Exists(rockOnPath)) { File.WriteAllBytes(rockOnPath, Properties.Resources.RockOnDetailManager); } StringBuilder sb = new StringBuilder(); string detailModulePath = Path.Combine(properties.PluginFolder, "detailmodules.txt"); foreach (string dllPath in win32Dlls) { string folder = properties.PluginFolder; Uri pathUri = new Uri(dllPath); if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) { folder += Path.DirectorySeparatorChar; } Uri folderUri = new Uri(folder); Uri relativeUri = folderUri.MakeRelativeUri(pathUri); string relativePath = Uri.UnescapeDataString(relativeUri.ToString().Replace('/', Path.DirectorySeparatorChar)); sb.AppendLine(relativePath); } if (File.Exists(detailModulePath)) { string currentContent = File.ReadAllText(detailModulePath, Encoding.UTF8); if (currentContent.Trim() != sb.ToString().Trim()) { File.WriteAllText(detailModulePath, sb.ToString(), Encoding.UTF8); } } else { File.WriteAllText(detailModulePath, sb.ToString(), Encoding.UTF8); } plugins_.Add(new Win32DetailManagerPlugin()); properties_list_.Add(new LoadProperties(properties.PluginFolder, properties.TrainFolder, properties.PlaySound, properties.PlayCarSound, properties.AddMessage, properties.AddScore)); } for (int i = 0; i < plugins_.Count; i++) { if (!plugins_[i].Load(properties_list_[i])) { return(false); } } int panel_length = 0; for (int i = 0; i < properties_list_.Count; i++) { if (properties_list_[i].Panel != null) { panel_length += properties_list_[i].Panel.Length - panel_length; } } properties.Panel = new int[panel_length]; this.train_ = new Train(properties.Panel); return(true); }
public ConsumeResponse() { LoadProperties.initProperties(); certificate = new Certificate(); certificate.loadCert(LoadProperties.certificate); }
internal static bool Load(LoadProperties prop) { /* prop.PluginFolder will return the folder the plugin is placed on. */ /* The final path will be "Your\TrainDirectory\hkats.ini" or "Your\TrainDirectory\Plugin\hkats.ini" */ string cfgfile = Path.Combine(prop.PluginFolder, "hkats.ini"); /* If it can find the config file by the path given above */ if (File.Exists(cfgfile)) { /* Seperates each line to an array */ string[] lines = File.ReadAllLines(cfgfile); /* Loop through each array (or lines) from the top */ foreach (string line in lines) { /* Semicolon is our comment identifier, ignore the line if it starts with semicolon */ if (!line.StartsWith(";")) { /* Square bracket is our section identifier, set the currentSection to the section name */ if (line.StartsWith("[")) { /* Shift the string to remove the first character, which has to be bracket. Since we shifted 1 character, we have to remove 2 characters in order to remove the last brackets*/ currentSection = line.Trim().Substring(1, line.Length - 2).ToLowerInvariant(); } else { /* Seperate the key and the value by equal sign, as an array */ string[] cfg = line.Split('='); /* After seperating, there should be at least 2 array, one represents the key and one represents the value. Only parse them if there are at least 2 array */ if (!(cfg.Length < 2)) { /* assign the first array to a variable called "key", use the trim function to remove unnecessary spacing and convert them into lower cases */ string key = cfg[0].Trim().ToLowerInvariant(); /* assign the second array to a variable called "valstr", use the trim function to remove unnecessary spacing and convert them into lower cases */ string valstr = cfg[1].Trim().ToLowerInvariant(); /* Used later on to parse integer */ int val; /* Seperate the value by comma as an array, this allows an value to have multiple arguments. */ string[] seperated = valstr.Split(','); /* Check what is the currentSection */ switch (currentSection) { /* If the current section is keydown */ case "keydown": /* If it managed to parse the first value to an integer, assign the value (PanelIndex) to the keys array on PanelManager. The array index is parsed by Functions.cs */ if (int.TryParse(seperated[0], out val)) { PanelManager.Keys[Func.KeyStr2ArrIndex(key)] = val; } /* If there is 2 argument and it is able parse the second argument to an integer, assign the value (SoundIndex) to the keys array on ATSSoundManager. The array index is parsed by Functions.cs*/ if (seperated.Length == 2) { if (int.TryParse(seperated[1], out val)) { ATSSoundManager.Keys[Func.KeyStr2ArrIndex(key)] = val; } } /* If there is more than 2 argument and it is able parse the third argument to an integer, assign the value (SoundIndex) to the keys array on ATSSoundManager. The array index is parsed by Functions.cs*/ if (seperated.Length > 2) { if (seperated[2].ToLowerInvariant() == "hold") { PanelManager.Keysup[Func.KeyStr2ArrIndex(key)] = 1; } } break; /* If the current section is system */ case "system": switch (key) { case "overspeedPanel": if (int.TryParse(valstr, out val)) { PanelManager.Overspd = val; } break; case "speedlimitPanel": if (int.TryParse(valstr, out val)) { PanelManager.SpeedLimit = val; } break; case "speedlimit": if (int.TryParse(valstr, out val)) { SafetySystem.SpeedLimit = val; } break; case "limitspeed": if (int.TryParse(valstr, out val)) { SafetySystem.LimitSpeed = val; } break; default: break; } break; case "interlock": switch (key) { case "door": if (int.TryParse(valstr, out val)) { if (val == 1) { Interlocker.DoorInterlocked = true; } else { Interlocker.DoorInterlocked = false; } } break; case "doorapplybrake": if (int.TryParse(valstr, out val)) { if (val == 1) { Interlocker.DoorBrake = true; } else { Interlocker.DoorBrake = false; } } break; case "doorpowerlock": if (int.TryParse(valstr, out val)) { if (val == 1) { Interlocker.DoorPowerLock = true; } else { Interlocker.DoorPowerLock = false; } } break; case "station": if (int.TryParse(valstr, out val)) { if (val == 1) { Interlocker.StationInterlock = true; } else { Interlocker.StationInterlock = false; } } break; default: break; } break; case "vigilance": switch (key) { case "resettimerkey": if (Func.String2VKey(valstr) != null) { DVS.rsettimerkey = (VirtualKeys)Func.String2VKey(valstr); } break; case "timerlimit": if (int.TryParse(valstr, out val)) { DVS.DSDTimerTimeout = val; } break; case "timerbrake": if (int.TryParse(valstr, out val)) { DVS.DSDTimerBrakeTimeout = DVS.DSDTimerTimeout + val; } break; case "disableontrainstop": if (int.TryParse(valstr, out val)) { if (val == 1) { DVS.DSDDisableOnTrainStop = true; } } break; case "resetondoormove": if (int.TryParse(valstr, out val)) { if (val == 1) { DVS.ResetOnDoorMove = true; } } break; case "resetonnotchmove": if (int.TryParse(valstr, out val)) { if (val == 1) { DVS.ResetOnNotchMove = true; } } break; case "timerexceedPanel": if (int.TryParse(valstr, out val)) { PanelManager.IdleTimer = val; } break; case "resetonklaxon": if (int.TryParse(valstr, out val)) { if (val <= 4) { DVS.ResetOnKlaxon = val; } } break; case "timerexceededsound": if (int.TryParse(valstr, out val)) { ATSSoundManager.DSDTimerExceeded = val; } break; case "timerbrakesound": if (int.TryParse(valstr, out val)) { ATSSoundManager.DSDTimerBrake = val; } break; default: break; } break; case "soundloop": if (int.TryParse(valstr, out val)) { ATSSoundManager.Keysloop[Func.KeyStr2ArrIndex(key)] = val; } break; case "beacon": if (key.StartsWith("beacon")) { if (int.TryParse(seperated[0], out val)) { if (int.TryParse(key.Substring(6), out int beaconNum)) { BeaconManager.RegisterPanelBeacon(beaconNum, val); } } if (seperated.Length > 1) { if (int.TryParse(key.Substring(6), out int beaconSound)) { if (int.TryParse(seperated[1], out int bSoundIndex)) { BeaconManager.RegisterSoundBeacon(beaconSound, bSoundIndex); } } } } switch (key) { case "speedlimit": if (int.TryParse(valstr, out val)) { BeaconManager.SpeedLimit = val; } break; default: break; } break; case "misc": switch (key) { case "travelmeterpanel": if (seperated.Length > 1) { switch (seperated[0]) { case "1": if (int.TryParse(seperated[1], out val)) { PanelManager.TravelMeter1 = val; } break; case "2": if (int.TryParse(seperated[1], out val)) { PanelManager.TravelMeter2 = val; } break; case "3": if (int.TryParse(seperated[1], out val)) { PanelManager.TravelMeter3 = val; } break; case "4": if (int.TryParse(seperated[1], out val)) { PanelManager.TravelMeter4 = val; } break; case "5": if (int.TryParse(seperated[1], out val)) { PanelManager.TravelMeter5 = val; } break; case "6": if (int.TryParse(seperated[1], out val)) { PanelManager.TravelMeter6 = val; } break; } } else { if (int.TryParse(valstr, out val)) { PanelManager.TravelMeter = val; } } break; case "cameramodepanel": if (int.TryParse(valstr, out val)) { PanelManager.CameraViewMode = val; } break; case "disabletimeaccel": if (int.TryParse(valstr, out val)) { if (val == 1) { Misc.DisableTimeAccel = true; } } break; case "crash": if (int.TryParse(seperated[0], out val)) { PanelManager.Crash = val; } if (seperated.Length > 1) { if (int.TryParse(seperated[1], out val)) { ATSSoundManager.Crash = val; } } break; case "crashspeed": if (int.TryParse(valstr, out val)) { Plugin.CrashSpeed = val; } break; default: break; } break; default: break; } } } } } return(true); } else { /* If the file cannot be found */ StringBuilder builder = new StringBuilder(); builder.AppendLine($"; This file is automatically generated by {Plugin.brand}. ;"); builder.AppendLine("; Please follow the template on https://github.com/Kenny-Hui/HK_ATS ;"); builder.AppendLine("[keydown]"); builder.AppendLine("key2" + "=" + "105"); builder.AppendLine("key2" + "=" + "106"); builder.AppendLine(""); builder.AppendLine("[system]"); builder.AppendLine("overspeedPanel" + "=" + "0"); builder.AppendLine("speedlimit" + "=" + "70"); builder.AppendLine("limitspeed" + "=" + "2"); builder.AppendLine(""); builder.AppendLine("[vigilance]"); builder.AppendLine("resettimerkey" + "=" + "keyspace"); builder.AppendLine("timerlimit" + "=" + "60"); builder.AppendLine("timerbrake" + "=" + "5"); builder.AppendLine("resetonnotchmove" + "=" + "1"); builder.AppendLine(""); builder.AppendLine("[interlock]"); builder.AppendLine("doorapplybrake" + "=" + "1"); builder.AppendLine(""); builder.AppendLine("[misc]"); builder.AppendLine("cameramodepanel" + "=" + "212"); builder.AppendLine("disabletimeaccel" + "=" + "1"); /* Try to save it */ try { File.WriteAllText(cfgfile, builder.ToString()); return(true); } catch (Exception ex) { prop.FailureReason = $"\n{Plugin.brand}: Cannot generate config file, error: {ex.Message}\nAre you sure you have write permission and the file isn't locked?"; return(false); } } }
/// <summary>Is called when the plugin is loaded.</summary> /// <param name="properties">The properties supplied to the plugin on loading.</param> /// <returns>Whether the plugin was loaded successfully.</returns> public bool Load(LoadProperties properties) { properties.Panel = new int[512]; SoundManager.Initialise(properties.PlaySound, 512); MessageManager.Initialise(properties.AddMessage); properties.AISupport = AISupport.Basic; this.Train = new Train(properties.Panel); //No AI Support //properties.AISupport = AISupport.None; this.Train = new Train(properties.Panel); string configFile = Path.CombineFile(properties.TrainFolder, "BVEC_Ats.cfg"); string OS_ATSDLL = Path.CombineFile(properties.TrainFolder, "OS_ATS1.dll"); string SZ_ATSDLL = Path.CombineFile(properties.TrainFolder, "OS_SZ_ATS1.dll"); string SZ_ATSDLL_2 = Path.CombineFile(properties.TrainFolder, "OS_SZ_Ats2_0.dll"); string OS_ATSconfigFile = Path.CombineFile(properties.TrainFolder, "OS_ATS1.cfg"); string SZ_ATSconfigFile = Path.CombineFile(properties.TrainFolder, "OS_SZ_ATS1.cfg"); string SZ_ATS_2configFile = Path.CombineFile(properties.TrainFolder, "OS_SZ_Ats2_0.cfg"); string ODF_ATSconfigFile = Path.CombineFile(properties.TrainFolder, "OdakyufanAts.cfg"); TrainFolder = properties.TrainFolder; //Delete error.log from previous run if (File.Exists(Path.CombineFile(properties.TrainFolder, "error.log"))) { try { File.Delete(Path.CombineFile(properties.TrainFolder, "error.log")); } catch { FolderWriteAccess = false; } } if (File.Exists(configFile)) { //Check for the automatic generator version string generatorversion; using (var reader = new StreamReader(configFile)) { //Read in first line generatorversion = reader.ReadLine(); } //If it exists try { if (generatorversion != null && generatorversion.StartsWith(";GenVersion=")) { string versiontext = Regex.Match(generatorversion, @"\d+").Value; int version = Int32.Parse(versiontext, NumberStyles.Number, CultureInfo.InvariantCulture); //If we're below the current version, try to upgrade again if (version < 1) { if (File.Exists(OS_ATSDLL) && File.Exists(OS_ATSconfigFile)) { try { string[] Lines = UpgradeOSATS.UpgradeConfigurationFile(OS_ATSconfigFile, properties.TrainFolder); } catch (Exception) { properties.FailureReason = "An error occured whilst attempting to upgrade the OS_ATS configuration."; return(false); } } } } } catch (Exception) { properties.FailureReason = "Empty configuration file detected."; return(false); } //Now try loading try { string[] Lines = File.ReadAllLines(configFile, Encoding.UTF8); this.Train.LoadConfigurationFile(Lines); return(true); } catch (Exception ex) { properties.FailureReason = "Error loading the configuration file: " + ex.Message; return(false); } } if (!File.Exists(configFile) && File.Exists(OS_ATSDLL) && File.Exists(OS_ATSconfigFile)) { //The F92_en is blacklisted due to a custom OS_ATS version if (Regex.IsMatch(properties.TrainFolder, @"\\F92_en(\\)?", RegexOptions.IgnoreCase)) { properties.FailureReason = "The F92_en is not currently a supported train."; try { using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log"))) { sw.WriteLine("The F92_en is not currently a supported train"); } return(false); } catch { return(false); } } //If there is no existing BVEC_ATS configuration file, but OS_ATS and the appropriate //configuration files exist, then attempt to upgrade the existing file to BVEC_ATS try { string[] Lines = UpgradeOSATS.UpgradeConfigurationFile(OS_ATSconfigFile, properties.TrainFolder); try { File.WriteAllLines(Path.CombineFile(TrainFolder, "BVEC_ATS.cfg"), Lines); } catch { //Error writing the new configuration file } this.Train.LoadConfigurationFile(Lines); return(true); } catch (Exception) { properties.FailureReason = "Error upgrading the existing OS_ATS configuration."; using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log"))) { sw.WriteLine("An existing OS_ATS configuration was found."); sw.WriteLine("However, an error occurred upgrading the existing OS_ATS configuration."); } return(false); } } if (File.Exists(SZ_ATSDLL)) { //We've found an OS_SZ_ATS equipped train //Upgrade for this is in alpha try { string[] Lines = UpgradeOSSZATS.UpgradeConfigurationFile(SZ_ATSconfigFile, properties.TrainFolder); try { File.WriteAllLines(Path.CombineFile(TrainFolder, "BVEC_ATS.cfg"), Lines); } catch { //Error writing the new configuration file } this.Train.LoadConfigurationFile(Lines); return(true); } catch (Exception) { properties.FailureReason = "Error upgrading the existing OS_SZ_ATS configuration."; using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log"))) { sw.WriteLine("An existing OS_SZ_ATS configuration was found."); sw.WriteLine("However, an error occurred upgrading the existing OS_SZ_ATS configuration."); } return(false); } } else { if (File.Exists(SZ_ATSDLL_2)) { //We've found an OS_SZ_ATS equipped train //Upgrade for this is in alpha try { string[] Lines = UpgradeOSSZATS.UpgradeConfigurationFile(SZ_ATS_2configFile, properties.TrainFolder); try { File.WriteAllLines(Path.CombineFile(TrainFolder, "BVEC_ATS.cfg"), Lines); } catch { //Error writing the new configuration file } this.Train.LoadConfigurationFile(Lines); return(true); } catch (Exception) { properties.FailureReason = "Error upgrading the existing OS_SZ_ATS configuration."; using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log"))) { sw.WriteLine("An existing OS_SZ_ATS configuration was found."); sw.WriteLine("However, an error occurred upgrading the existing OS_SZ_ATS configuration."); } return(false); } } if (File.Exists(ODF_ATSconfigFile)) { //We've found an OdyakufanATS equipped train //Upgrade for this is in alpha try { File.Copy(ODF_ATSconfigFile, configFile); string[] Lines = File.ReadAllLines(configFile); this.Train.LoadConfigurationFile(Lines); return(true); } catch (Exception ex) { properties.FailureReason = "Error loading the configuration file: " + ex.Message; return(false); } } else { properties.FailureReason = "No supported configuration files exist."; //Write out error.log with details of what it thinks was found and missing using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log"))) { sw.WriteLine("Plugin location " + Convert.ToString(properties.TrainFolder)); if (File.Exists(OS_ATSDLL)) { sw.WriteLine("OS_ATS DLL found"); } else { sw.WriteLine("No OS_ATS DLL found"); } if (File.Exists(OS_ATSconfigFile)) { sw.WriteLine("OS_ATS configuration file found"); } else { sw.WriteLine("No OS_ATS configuration file found"); } } return(false); } } }