/// <summary>Loads the specified route.</summary> /// <param name="path">The path to the file or folder that contains the route.</param> /// <param name="Encoding">The user-selected encoding (if appropriate)</param> /// <param name="trainPath">The path to the selected train</param> /// <param name="objectPath">The base object folder path</param> /// <param name="soundPath">The base sound folder path</param> /// <param name="PreviewOnly">Whether this is a preview</param> /// <param name="route">Receives the route.</param> /// <returns>Whether loading the sound was successful.</returns> public override bool LoadRoute(string path, Encoding Encoding, string trainPath, string objectPath, string soundPath, bool PreviewOnly, ref object route) { if (Encoding == null) { Encoding = Encoding.UTF8; } LastException = null; Cancel = false; CurrentProgress = 0.0; IsLoading = true; FileSystem.AppendToLogFile("Loading route file: " + path); FileSystem.AppendToLogFile("INFO: Route file hash " + Path.GetChecksum(path)); CurrentRoute = (CurrentRoute)route; //First, check the format of the route file //RW routes were written for BVE1 / 2, and have a different command syntax bool isRw = path.ToLowerInvariant().EndsWith(".rw"); FileSystem.AppendToLogFile("Route file format is: " + (isRw ? "RW" : "CSV")); try { Parser parser = new Parser(); parser.ParseRoute(path, isRw, Encoding, trainPath, objectPath, soundPath, PreviewOnly, this); IsLoading = false; return(true); } catch (Exception ex) { route = null; CurrentHost.AddMessage(MessageType.Error, false, "An unexpected error occured whilst attempting to load the following routefile: " + path); IsLoading = false; LastException = ex; return(false); } }
/// <summary>Loads the specified route.</summary> /// <param name="path">The path to the file or folder that contains the route.</param> /// <param name="Encoding">The user-selected encoding (if appropriate)</param> /// <param name="trainPath">The path to the selected train</param> /// <param name="objectPath">The base object folder path</param> /// <param name="soundPath">The base sound folder path</param> /// <param name="PreviewOnly">Whether this is a preview</param> /// <param name="route">Receives the route.</param> /// <returns>Whether loading the sound was successful.</returns> public override bool LoadRoute(string path, System.Text.Encoding Encoding, string trainPath, string objectPath, string soundPath, bool PreviewOnly, ref object route) { LastException = null; Cancel = false; CurrentProgress = 0.0; IsLoading = true; FileSystem.AppendToLogFile("Loading route file: " + path); CurrentRoute = (CurrentRoute)route; CurrentRoute.Stations = new RouteStation[] { }; FileSystem.AppendToLogFile("Route file format is: Mechanik"); try { Parser parser = new Parser(); parser.ParseRoute(path, PreviewOnly); if (PreviewOnly && CurrentRoute.Stations.Length == 0) { route = null; CurrentHost.AddMessage(MessageType.Error, false, "No stations were found in the following Mechanik routefile: " + path + Environment.NewLine + Environment.NewLine + "This is most likely a module file."); IsLoading = false; return(false); } IsLoading = false; return(true); } catch (Exception ex) { route = null; CurrentHost.AddMessage(MessageType.Error, false, "An unexpected error occured whilst attempting to load the following Mechanik routefile: " + path); IsLoading = false; LastException = ex; return(false); } }
public static FileSystem FromConfigurationFile(string file, string assemblyFile) { string assemblyFolder = System.IO.Path.GetDirectoryName(assemblyFile); FileSystem system = FileSystem.FromCommandLineArgs(new[] { "/filesystem=" + file }); try { string[] lines = File.ReadAllLines(file, Encoding.UTF8); foreach (string line in lines) { int equals = line.IndexOf('='); if (equals >= 0) { string key = line.Substring(0, equals).Trim(new char[] { }).ToLowerInvariant(); string value = line.Substring(equals + 1).Trim(new char[] { }); switch (key) { case "data": system.DataFolder = GetAbsolutePath(value, assemblyFile, true); if (!Directory.Exists(system.DataFolder)) { system.DataFolder = OpenBveApi.Path.CombineDirectory(assemblyFolder, "Data"); if (!Directory.Exists(system.DataFolder)) { //If we are unable to find the data folder, this is a critical error, as it contains all sorts of essential stuff..... Environment.Exit(0); } } break; case "managedcontent": /* system.ManagedContentFolders = value.Split(new char[] { ',' }); * for (int i = 0; i < system.ManagedContentFolders.Length; i++) { * system.ManagedContentFolders[i] = GetAbsolutePath(system.ManagedContentFolders[i].Trim(new char[] { }), true); * } */ break; case "version": int v; if (!int.TryParse(value, out v)) { system.AppendToLogFile("WARNING: Invalid filesystem.cfg version detected."); } /* if (v <= 1) { * //Silently upgrade to the current config version * system.Version = 1; * break; * } * if (v > 1) { * system.AppendToLogFile("WARNING: A newer filesystem.cfg version " + v + " was detected. The current version is 1."); * system.Version = v; * } */ break; case "settings": system.SettingsFolder = GetAbsolutePath(value, assemblyFile, true); break; case "initialroute": system.InitialRouteFolder = GetAbsolutePath(value, assemblyFile, true); break; case "initialtrain": system.InitialTrainFolder = GetAbsolutePath(value, assemblyFile, true); break; case "restartprocess": system.RestartProcess = GetAbsolutePath(value, assemblyFile, true); break; case "restartarguments": system.RestartArguments = GetAbsolutePath(value, assemblyFile, false); break; case "routepackageinstall": system.RouteInstallationDirectory = GetAbsolutePath(value, assemblyFile, true); break; case "trainpackageinstall": system.TrainInstallationDirectory = GetAbsolutePath(value, assemblyFile, true); break; case "otherpackageinstall": system.OtherInstallationDirectory = GetAbsolutePath(value, assemblyFile, true); break; case "loksimpackageinstall": system.LoksimPackageInstallationDirectory = GetAbsolutePath(value, assemblyFile, true); break; default: /* if (system.NotUnderstoodLines == null) { * system.NotUnderstoodLines = new string[0]; * } * int l = system.NotUnderstoodLines.Length; * Array.Resize(ref system.NotUnderstoodLines, system.NotUnderstoodLines.Length + 1); * system.NotUnderstoodLines[l] = line; */ system.AppendToLogFile("WARNING: Unrecognised key " + key + " detected in filesystem.cfg"); break; } } } // disable once EmptyGeneralCatchClause } catch { } return(system); }
public override bool LoadTrain(Encoding Encoding, string trainPath, ref AbstractTrain train, ref Control[] currentControls) { CurrentControls = currentControls; TrainBase currentTrain = train as TrainBase; if (currentTrain == null) { currentHost.ReportProblem(ProblemType.InvalidData, "Train was not valid"); return(false); } if (currentTrain.State == TrainState.Bogus) { // bogus train string TrainData = Path.CombineFile(FileSystem.GetDataFolder("Compatibility", "PreTrain"), "train.dat"); TrainDatParser.Parse(TrainData, Encoding.UTF8, currentTrain); Thread.Sleep(1); if (Cancel) { return(false); } } else { currentTrain.TrainFolder = trainPath; // real train if (currentTrain.IsPlayerTrain) { FileSystem.AppendToLogFile("Loading player train: " + currentTrain.TrainFolder); } else { FileSystem.AppendToLogFile("Loading AI train: " + currentTrain.TrainFolder); } string TrainData = Path.CombineFile(currentTrain.TrainFolder, "train.dat"); TrainDatParser.Parse(TrainData, Encoding, currentTrain); Thread.Sleep(1); if (Cancel) { return(false); } SoundCfgParser.ParseSoundConfig(currentTrain); Thread.Sleep(1); if (Cancel) { return(false); } // door open/close speed for (int i = 0; i < currentTrain.Cars.Length; i++) { currentTrain.Cars[i].DetermineDoorClosingSpeed(); } } // add panel section if (currentTrain.IsPlayerTrain) { ParsePanelConfig(currentTrain, Encoding); Thread.Sleep(1); if (Cancel) { return(false); } FileSystem.AppendToLogFile("Train panel loaded sucessfully."); } // add exterior section if (currentTrain.State != TrainState.Bogus) { bool[] VisibleFromInterior = new bool[currentTrain.Cars.Length]; UnifiedObject[] CarObjects = new UnifiedObject[currentTrain.Cars.Length]; UnifiedObject[] BogieObjects = new UnifiedObject[currentTrain.Cars.Length * 2]; UnifiedObject[] CouplerObjects = new UnifiedObject[currentTrain.Cars.Length]; string tXml = Path.CombineFile(currentTrain.TrainFolder, "train.xml"); if (File.Exists(tXml)) { TrainXmlParser.Parse(tXml, currentTrain, ref CarObjects, ref BogieObjects, ref CouplerObjects, ref VisibleFromInterior); } else { ExtensionsCfgParser.ParseExtensionsConfig(currentTrain.TrainFolder, Encoding, ref CarObjects, ref BogieObjects, ref CouplerObjects, ref VisibleFromInterior, currentTrain); } currentTrain.CameraCar = currentTrain.DriverCar; Thread.Sleep(1); if (Cancel) { return(false); } //Stores the current array index of the bogie object to add //Required as there are two bogies per car, and we're using a simple linear array.... int currentBogieObject = 0; for (int i = 0; i < currentTrain.Cars.Length; i++) { if (CarObjects[i] == null) { // load default exterior object string file = Path.CombineFile(FileSystem.GetDataFolder("Compatibility"), "exterior.csv"); StaticObject so; currentHost.LoadStaticObject(file, Encoding.UTF8, false, out so); if (so == null) { CarObjects[i] = null; } else { StaticObject c = (StaticObject)so.Clone(); //Clone as otherwise the cached object doesn't scale right c.ApplyScale(currentTrain.Cars[i].Width, currentTrain.Cars[i].Height, currentTrain.Cars[i].Length); CarObjects[i] = c; } } if (CarObjects[i] != null) { // add object currentTrain.Cars[i].LoadCarSections(CarObjects[i], VisibleFromInterior[i]); } if (CouplerObjects[i] != null) { currentTrain.Cars[i].Coupler.LoadCarSections(CouplerObjects[i], VisibleFromInterior[i]); } //Load bogie objects if (BogieObjects[currentBogieObject] != null) { currentTrain.Cars[i].FrontBogie.LoadCarSections(BogieObjects[currentBogieObject], VisibleFromInterior[i]); } currentBogieObject++; if (BogieObjects[currentBogieObject] != null) { currentTrain.Cars[i].RearBogie.LoadCarSections(BogieObjects[currentBogieObject], VisibleFromInterior[i]); } currentBogieObject++; } } // place cars currentTrain.PlaceCars(0.0); currentControls = CurrentControls; return(true); }