1616// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717
1818using System ;
19+ using System . Collections . Generic ;
1920using Orts . Parsers . Msts ;
2021
2122namespace Orts . Formats . Msts
@@ -29,16 +30,33 @@ public class ShapeDescriptorFile
2930 shape = new SDShape ( ) ;
3031 }
3132
33+ public static Dictionary < string , SDShape > Cache = new Dictionary < string , SDShape > ( ) ;
34+
3235 public ShapeDescriptorFile ( string filename )
3336 {
34- using ( STFReader stf = new STFReader ( filename , false ) )
37+ var shapeDescriptorPath = filename . ToLowerInvariant ( ) ;
38+
39+ if ( Cache . ContainsKey ( shapeDescriptorPath ) )
3540 {
36- stf . ParseFile ( new STFReader . TokenProcessor [ ] {
37- new STFReader . TokenProcessor ( "shape" , ( ) => { shape = new SDShape ( stf ) ; } ) ,
38- } ) ;
39- //TODO This should be changed to STFException.TraceError() with defaults values created
40- if ( shape == null )
41- throw new STFException ( stf , "Missing shape statement" ) ;
41+ shape = Cache [ shapeDescriptorPath ] ;
42+ }
43+ else
44+ {
45+ if ( ! System . IO . File . Exists ( filename ) ) // If not found, skip
46+ {
47+ shape = null ;
48+ return ;
49+ }
50+
51+ using ( STFReader stf = new STFReader ( filename , false ) )
52+ {
53+ stf . ParseFile ( new STFReader . TokenProcessor [ ] {
54+ new STFReader . TokenProcessor ( "shape" , ( ) => { shape = new SDShape ( stf ) ; } ) ,
55+ } ) ;
56+ //TODO This should be changed to STFException.TraceError() with defaults values created
57+ if ( shape == null ) throw new STFException ( stf , "Missing shape statement" ) ;
58+ }
59+ Cache . Add ( shapeDescriptorPath , shape ) ;
4260 }
4361 }
4462
0 commit comments