internal Consist(string filePath, Folder folder, bool reverseConsist) { if (File.Exists(filePath)) { try { var conFile = new ConsistFile(filePath); Name = conFile.Name.Trim(); Locomotive = reverseConsist ? GetLocomotiveReverse(conFile, folder) : GetLocomotive(conFile, folder); } catch { Name = "<" + catalog.GetString("load error:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">"; } if (Locomotive == null) { throw new InvalidDataException("Consist '" + filePath + "' is excluded."); } if (string.IsNullOrEmpty(Name)) { Name = "<" + catalog.GetString("unnamed:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">"; } } else { Name = "<" + catalog.GetString("missing:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">"; } FilePath = filePath; }
public void config(List <string> routes) { foreach (string routeParent in routes) { if (!Directory.Exists(routeParent)) { continue; } string[] subdirectoryEntries = Directory.GetDirectories(routeParent); foreach (string route in subdirectoryEntries) { string[] files = Directory.GetFileSystemEntries(route, "*.trk"); if (files.Count() == 1) { routePaths.Add(route); } } string consistPath = Path.Combine(routeParent, "../TRAINS/CONSISTS"); subdirectoryEntries = Directory.GetFileSystemEntries(consistPath, "*.con"); foreach (string consist in subdirectoryEntries) { string fullPathConsist = Path.GetFullPath(consist); ConsistFile consistName = new ConsistFile(fullPathConsist); ConsistInfo conInfo = new ConsistInfo(consistName.ToString(), fullPathConsist); trainConsists.Add(conInfo); } } }
private static Locomotive GetLocomotive(ConsistFile conFile, Folder folder, bool reverse) { Wagon wagon = reverse ? conFile.Train.Wagons.Where(w => w.IsEngine).LastOrDefault() : conFile.Train.Wagons.Where(w => w.IsEngine).FirstOrDefault(); if (null != wagon) { return(Locomotive.GetLocomotive(folder.ContentFolder.EngineFile(wagon.Folder, wagon.Name))); } return(null); }
public Consist(Content content) { Debug.Assert(content.Type == ContentType.Consist); if (System.IO.Path.GetExtension(content.PathName).Equals(".con", StringComparison.OrdinalIgnoreCase)) { var file = new ConsistFile(content.PathName); Name = file.Name; Cars = from car in file.Train.TrainCfg.WagonList select new Car(car); } }
private static Locomotive GetLocomotiveReverse(ConsistFile conFile, Folder folder) { foreach (var wagon in conFile.Train.Wagons.Where(w => w.IsEngine)) { try { return(Locomotive.GetLocomotive(folder.ContentFolder.EngineFile(wagon.Folder, wagon.Name))); } catch { } } return(null); }
static Locomotive GetLocomotive(ConsistFile conFile, Folder folder) { foreach (var wagon in conFile.Train.TrainCfg.WagonList.Where(w => w.IsEngine)) { var filePath = System.IO.Path.Combine(System.IO.Path.Combine(System.IO.Path.Combine(System.IO.Path.Combine(folder.Path, "TRAINS"), "TRAINSET"), wagon.Folder), wagon.Name + ".eng"); try { return(new Locomotive(filePath)); } catch { } } return(null); }
private Consist(ConsistFile consist, Locomotive locomotive, string fileName) { Locomotive = locomotive; if (string.IsNullOrEmpty(consist.Name)) { Name = $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>"; } else { Name = consist.Name?.Trim(); } FilePath = fileName; }
internal static Consist FromFile(string fileName, Folder folder, bool reverseConsist) { Consist result; try { ConsistFile conFile = new ConsistFile(fileName); Locomotive locomotive = GetLocomotive(conFile, folder, reverseConsist); result = new Consist(conFile, locomotive, fileName); } #pragma warning disable CA1031 // Do not catch general exception types catch #pragma warning restore CA1031 // Do not catch general exception types { result = new Consist($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName); } return(result); }
internal static async Task <Consist> FromFileAsync(string fileName, Folder folder, bool reverseConsist, CancellationToken token) { return(await Task.Run(() => { Consist result = null; try { ConsistFile conFile = new ConsistFile(fileName); Locomotive locomotive = reverseConsist ? GetLocomotiveReverse(conFile, folder) : GetLocomotive(conFile, folder); if (locomotive != null) { result = new Consist(conFile, locomotive, fileName); } } catch { result = new Consist($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName); } return result; }, token).ConfigureAwait(false)); }
/// <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) { var act = new ConsistFile(file); }