Skip to content

Commit 37805a8

Browse files
author
Jere Liimatainen
committed
Updated version number to 2.0, small fixes.
1 parent b63c1d2 commit 37805a8

File tree

6 files changed

+17
-32
lines changed

6 files changed

+17
-32
lines changed

Data/FileManager.cs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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 };

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Teleste
3+
Copyright (c) 2025 Teleste
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"SimulationDirectories": [
1111
"C:\\Users\\thear\\source\\repos\\START\\START-data\\Simulations"
1212
],
13-
"VersionNumber": "11.0.2.0"
13+
"VersionNumber": "2.0.0"
1414
}

SmartTrainApplication.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
9-
<Version>1.0.0.0</Version>
9+
<Version>2.0.0.0</Version>
1010
<ApplicationIcon>Assets\start.ico</ApplicationIcon>
1111
<Title>START</Title>
1212
</PropertyGroup>

Views/SimulationViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public SimulationViewModel() {
6565

6666
// Get trains
6767
if (DataManager.Trains.Count == 0)
68-
DataManager.Trains = FileManager.StartupTrainFolderImport(SettingsManager.CurrentSettings.TrainDirectories);
68+
DataManager.Trains = FileManager.ReadTrainsFromFolder(SettingsManager.CurrentSettings.TrainDirectories);
6969

7070
if (Icons == null)
7171
SetIcons();

Views/TrainEditorViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public TrainEditorViewModel() {
206206

207207
private void InitializeData() {
208208
if (DataManager.Trains.Count == 0)
209-
DataManager.Trains = FileManager.StartupTrainFolderImport(SettingsManager.CurrentSettings.TrainDirectories);
209+
DataManager.Trains = FileManager.ReadTrainsFromFolder(SettingsManager.CurrentSettings.TrainDirectories);
210210

211211
SetIcons();
212212
Trains = DataManager.Trains.Select(t => new ListedTrain(t, Icons[t.Icon])).ToList();

0 commit comments

Comments
 (0)