public static Locomotive GetLocomotive(string fileName) { Locomotive result = null; if (string.IsNullOrEmpty(fileName)) { result = new Locomotive(catalog.GetString("- Any Locomotive -"), fileName); } else if (File.Exists(fileName)) { try { EngineFile engFile = new EngineFile(fileName); if (!string.IsNullOrEmpty(engFile.CabViewFile)) { result = new Locomotive(engFile, fileName); } } catch { result = new Locomotive($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName); } } else { result = new Locomotive($"<{catalog.GetString("missing:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName); } return(result); }
public static Locomotive GetLocomotive(string fileName) { Locomotive result = null; if (File.Exists(fileName)) { try { EngineFile engFile = new EngineFile(fileName); if (!string.IsNullOrEmpty(engFile.CabViewFile)) { result = new Locomotive(engFile, fileName); } } #pragma warning disable CA1031 // Do not catch general exception types catch #pragma warning restore CA1031 // Do not catch general exception types { result = new Locomotive($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName); } } else { result = new Locomotive($"<{catalog.GetString("missing:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName); } return(result); }
private Locomotive(EngineFile engine, string fileName) { Name = engine.Name?.Trim(); Description = engine.Description?.Trim(); if (string.IsNullOrEmpty(Name)) { Name = $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>"; } if (string.IsNullOrEmpty(Description)) { Description = null; } FilePath = fileName; }
public Car(Content content) { Debug.Assert(content.Type == ContentType.Car); if (System.IO.Path.GetExtension(content.PathName).Equals(".eng", StringComparison.OrdinalIgnoreCase)) { var file = new EngineFile(content.PathName); Type = CarType.Engine; Name = file.Name; Description = file.Description; } else if (System.IO.Path.GetExtension(content.PathName).Equals(".wag", StringComparison.OrdinalIgnoreCase)) { var file = new WagonFile(content.PathName); Type = CarType.Wagon; Name = file.Name; Description = ""; } }
internal Locomotive(string filePath) { if (filePath == null) { Name = catalog.GetString("- Any Locomotive -"); } else if (File.Exists(filePath)) { EngineFile engFile; try { engFile = new EngineFile(filePath); } catch { Name = $"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; engFile = null; } if (engFile != null) { bool showInList = !string.IsNullOrEmpty(engFile.CabViewFile); if (!showInList) { throw new InvalidDataException(catalog.GetStringFmt("Locomotive '{0}' is excluded.", filePath)); } string name = (engFile.Name ?? "").Trim(); Name = name != "" ? name : $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; string description = (engFile.Description ?? "").Trim(); if (description != "") { Description = description; } } } else { Name = $"<{catalog.GetString("missing:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; } FilePath = filePath; }
internal Locomotive(string filePath) { if (filePath == null) { Name = catalog.GetString("- Any Locomotive -"); } else if (File.Exists(filePath)) { var showInList = true; try { var engFile = new EngineFile(filePath); showInList = !string.IsNullOrEmpty(engFile.CabViewFile); Name = engFile.Name.Trim(); Description = engFile.Description.Trim(); } catch { Name = "<" + catalog.GetString("load error:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">"; } if (!showInList) { throw new InvalidDataException(catalog.GetStringFmt("Locomotive '{0}' is excluded.", filePath)); } if (string.IsNullOrEmpty(Name)) { Name = "<" + catalog.GetString("unnamed:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">"; } if (string.IsNullOrEmpty(Description)) { Description = null; } } else { Name = "<" + catalog.GetString("missing:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">"; } FilePath = filePath; }
/// <summary> /// Try to load the file. /// Possibly this might raise an exception. That exception is not caught here /// </summary> /// <param name="file">The file that needs to be loaded</param> public override void TryLoading(string file) { _ = new EngineFile(file); }