Skip to content

Commit c457f11

Browse files
committed
Delete binary paths if the ascii version or the tdb was modified
1 parent c3fd44a commit c457f11

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Source/Orts.Formats.Msts/TrackDatabaseFile.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class TrackDatabaseFile
3939
/// </summary>
4040
public TrackDB TrackDB { get; set; }
4141

42+
/// <summary>
43+
/// The .tdb file last modified time is stored for being able to validate derived files such as binary paths.
44+
/// </summary>
45+
public DateTime LastWriteTime { get; }
46+
4247
/// <summary>
4348
/// Constructor from file
4449
/// </summary>
@@ -49,6 +54,8 @@ public TrackDatabaseFile(string filenamewithpath)
4954
stf.ParseFile(new STFReader.TokenProcessor[] {
5055
new STFReader.TokenProcessor("trackdb", ()=>{ TrackDB = new TrackDB(stf); }),
5156
});
57+
58+
LastWriteTime = File.GetLastWriteTime(filenamewithpath);
5259
}
5360

5461
/// <summary>

Source/Orts.Simulation/Simulation/Timetables/ProcessTimetable.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,19 +1188,23 @@ public AIPath LoadPathNoClone(string pathstring, out bool validPath)
11881188
if (String.IsNullOrEmpty(pathExtension))
11891189
formedpathFilefull = Path.ChangeExtension(formedpathFilefull, "pat");
11901190

1191-
// try to load binary path if required
1192-
bool binaryloaded = false;
1193-
AIPath outPath = null;
1194-
1195-
if (!Paths.TryGetValue(formedpathFilefull, out outPath))
1191+
if (!Paths.TryGetValue(formedpathFilefull, out var outPath))
11961192
{
1193+
// try to load binary path if required
1194+
bool binaryloaded = false;
11971195
string formedpathFilefullBinary = Path.Combine(Path.GetDirectoryName(formedpathFilefull), "OpenRails");
11981196
formedpathFilefullBinary = Path.Combine(formedpathFilefullBinary, Path.GetFileNameWithoutExtension(formedpathFilefull));
11991197
formedpathFilefullBinary = Path.ChangeExtension(formedpathFilefullBinary, "or-binpat");
12001198

1201-
if (BinaryPaths)
1199+
if (BinaryPaths && File.Exists(formedpathFilefullBinary))
12021200
{
1203-
if (File.Exists(formedpathFilefullBinary))
1201+
var binaryLastWriteTime = File.GetLastWriteTime(formedpathFilefullBinary);
1202+
if (binaryLastWriteTime < simulator.TDB.LastWriteTime ||
1203+
File.Exists(formedpathFilefull) && binaryLastWriteTime < File.GetLastWriteTime(formedpathFilefull))
1204+
{
1205+
File.Delete(formedpathFilefullBinary);
1206+
}
1207+
else
12041208
{
12051209
try
12061210
{

0 commit comments

Comments
 (0)