Skip to content

Commit

Permalink
For now, move .train-or files back to the CONSISTS directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
YoRyan committed Jul 25, 2020
1 parent 81b9e5f commit e5c2207
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Source/ORTS.Content/TrainFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static string ResolveTrainFile(string basePath, string filename)
/// <param name="filename">The filename, minus its extension, of the file to locate.</param>
/// <returns>The full path to the train file.</returns>
public static string ResolveOrtsTrainFile(string basePath, string filename) =>
Path.GetFullPath(Path.ChangeExtension(Path.Combine(basePath, "trains", "lists", filename), ".train-or"));
Path.GetFullPath(Path.ChangeExtension(Path.Combine(basePath, "trains", "consists", filename), ".train-or"));

/// <summary>
/// Locate a consist by filename.
Expand Down Expand Up @@ -235,7 +235,7 @@ ISet<string> BaseNames(string directory, string pattern)
StringComparer.InvariantCultureIgnoreCase);
}

ISet<string> ortsBaseNames = BaseNames(Path.Combine(basePath, "trains", "lists"), "*.train-or");
ISet<string> ortsBaseNames = BaseNames(Path.Combine(basePath, "trains", "consists"), "*.train-or");
ISet<string> mstsBaseNames = BaseNames(Path.Combine(basePath, "trains", "consists"), "*.con");

IEnumerable<string> CombinedIterator()
Expand All @@ -245,7 +245,7 @@ IEnumerable<string> CombinedIterator()
string path;
// Prioritize native .train-or files.
if (ortsBaseNames.Contains(baseName))
path = Path.ChangeExtension(Path.Combine(basePath, "trains", "lists", baseName), ".train-or");
path = Path.ChangeExtension(Path.Combine(basePath, "trains", "consists", baseName), ".train-or");
else
path = Path.ChangeExtension(Path.Combine(basePath, "trains", "consists", baseName), ".con");
yield return Path.GetFullPath(path);
Expand Down
36 changes: 18 additions & 18 deletions Source/Orts.Simulation/Simulation/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,7 @@ public void SetExplore(string path, string consist, string start, string season,
ExploreConFile = consist;
PreferredLocomotive = preferredLocomotive;
patFileName = Path.ChangeExtension(path, "PAT");
switch (Path.GetDirectoryName(consist).ToLowerInvariant())
{
case "consists":
trainFileName = Path.ChangeExtension(consist, "CON");
break;
case "lists":
trainFileName = Path.ChangeExtension(consist, "TRAIN-OR");
break;
}
trainFileName = ResolveConsistFileExtension(consist);
var time = start.Split(':');
TimeSpan StartTime = new TimeSpan(int.Parse(time[0]), time.Length > 1 ? int.Parse(time[1]) : 0, time.Length > 2 ? int.Parse(time[2]) : 0);
ClockTime = StartTime.TotalSeconds;
Expand All @@ -414,15 +406,7 @@ public void SetExploreThroughActivity(string path, string consist, string start,
ExploreConFile = consist;
PreferredLocomotive = preferredLocomotive;
patFileName = Path.ChangeExtension(path, "PAT");
switch (Path.GetDirectoryName(consist).ToLowerInvariant())
{
case "consists":
trainFileName = Path.ChangeExtension(consist, "CON");
break;
case "lists":
trainFileName = Path.ChangeExtension(consist, "TRAIN-OR");
break;
}
trainFileName = ResolveConsistFileExtension(consist);
var time = start.Split(':');
TimeSpan StartTime = new TimeSpan(int.Parse(time[0]), time.Length > 1 ? int.Parse(time[1]) : 0, time.Length > 2 ? int.Parse(time[2]) : 0);
Activity.Tr_Activity.Tr_Activity_File.Player_Service_Definition.Player_Traffic_Definition.Time = StartTime.Hours + StartTime.Minutes * 60 +
Expand All @@ -434,6 +418,22 @@ public void SetExploreThroughActivity(string path, string consist, string start,
IsAutopilotMode = true;
}

private static string ResolveConsistFileExtension(string consistPath)
{
switch (Path.GetExtension(consistPath).ToLowerInvariant())
{
case ".train-or":
case ".con":
return consistPath;
default:
string ortsTrain = Path.ChangeExtension(consistPath, ".train-or");
if (File.Exists(ortsTrain))
return ortsTrain;
else
return Path.ChangeExtension(consistPath, ".con");
}
}

public void Start(CancellationToken cancellation)
{
Signals = new Signals(this, SIGCFG, cancellation);
Expand Down

0 comments on commit e5c2207

Please sign in to comment.