@@ -35,28 +35,6 @@ internal class FileManager {
3535 // Currently active view
3636 public static string CurrentView = "" ;
3737
38- /// <summary>
39- /// Export route into a file using filepicker.
40- /// </summary>
41- [ Obsolete ]
42- public static async void ExportRoute ( TopLevel topLevel ) {
43- IStorageFile ? file = await topLevel . StorageProvider . SaveFilePickerAsync ( new FilePickerSaveOptions {
44- Title = "Export JSON" ,
45- FileTypeChoices = new [ ] { JSON } ,
46- SuggestedFileName = "export"
47- } ) ;
48-
49- if ( file == null ) return ;
50-
51- // Create a file and write empty the new route to it
52- JsonSerializerOptions Json_options = new ( ) { WriteIndented = true } ;
53- string output = JsonSerializer . Serialize ( DataManager . TrainRoutes [ DataManager . CurrentTrainRoute ] , Json_options ) ;
54- if ( file is not null ) {
55- await using Stream stream = await file . OpenWriteAsync ( ) ;
56- using StreamWriter streamWriter = new ( stream ) ;
57- await streamWriter . WriteLineAsync ( output ) ;
58- }
59- }
6038
6139 /// <summary>
6240 /// Export any of the JSON files with filepicker
@@ -68,16 +46,16 @@ public static async void Export(TopLevel topLevel, string type) {
6846
6947 switch ( type ) {
7048 case "Route" :
71- string currentTrainRouteName = DataManager . TrainRoutes [ DataManager . CurrentTrainRoute ] . Name ;
49+ string ? currentTrainRouteName = DataManager . GetCurrentRoute ( ) ? . Name ;
7250 nameSuggestion = currentTrainRouteName != ""
73- ? currentTrainRouteName . Replace ( "_" , "-" ) . Replace ( " " , "-" ) + ".json"
51+ ? currentTrainRouteName ? . Replace ( "_" , "-" ) . Replace ( " " , "-" ) + ".json"
7452 : "export.json" ;
7553 break ;
7654
7755 case "Train" :
78- string currentTrainName = DataManager . TrainRoutes [ DataManager . CurrentTrainRoute ] . Name ;
56+ string ? currentTrainName = DataManager . GetCurrentTrain ( ) ? . Name ;
7957 nameSuggestion = currentTrainName != ""
80- ? currentTrainName . Replace ( "_" , "-" ) . Replace ( " " , "-" ) + ".json"
58+ ? currentTrainName ? . Replace ( "_" , "-" ) . Replace ( " " , "-" ) + ".json"
8159 : "export.json" ;
8260 break ;
8361
@@ -86,6 +64,7 @@ public static async void Export(TopLevel topLevel, string type) {
8664 break ;
8765
8866 case "Settings" :
67+ nameSuggestion = "settings.json" ;
8968 break ;
9069
9170 default :
@@ -314,10 +293,16 @@ private static string GetSimulationFileName(SimulationData? sim) {
314293 /// </summary>
315294 /// <param name="SavedPaths">Takes the list of saved paths from settings</param>
316295 /// <returns>Returns imported trains</returns>
317- public static List < Train > StartupTrainFolderImport ( List < string > SavedPaths ) {
296+ public static List < Train > ReadTrainsFromFolder ( List < string > SavedPaths ) {
318297 List < Train > Trains = new ( ) ;
319298 List < string > Paths = new ( ) ;
320299
300+ try {
301+ if ( ! Directory . Exists ( GetTrainDirectory ( ) ) ) Directory . CreateDirectory ( GetTrainDirectory ( ) ) ;
302+ } catch ( Exception ex ) {
303+ Logger . Debug ( ex . Message ) ;
304+ }
305+
321306 if ( SavedPaths == null ) return Trains ;
322307
323308 JsonSerializerOptions Json_options = new ( ) { IncludeFields = true } ;
0 commit comments