Skip to content

Commit f1c7eb8

Browse files
File with runtime routeinformation ORRoute.json now hardcode placed in C:\Users\<user>\AppData\Roaming\Open Rails\Settings
1 parent dd0668f commit f1c7eb8

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

Source/Menu/DownloadContentForm.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,6 @@ private void DownloadContentButton_Click(object sender, EventArgs e)
250250

251251
Settings.Content.InstallPath = installPath;
252252

253-
// set json route filename
254-
255-
Settings.Content.RouteJsonName = Path.Combine(installPath, "ORRoute.json");
256-
257253
// the download
258254

259255
Cursor.Current = Cursors.WaitCursor;

Source/ORTS.Settings/ContentSettings.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public class ContentSettings : SettingsBase
3030
[Default("C:\\OpenRails")]
3131
public string InstallPath { get; set; }
3232

33-
[Default("")]
34-
public string RouteJsonName { get; set; }
35-
3633
#endregion
3734

3835
public ContentSettings(IEnumerable<string> options)

Source/ORTS.Settings/RouteSettings.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
using Newtonsoft.Json.Linq;
2525
using LibGit2Sharp;
2626
using ORTS.Common;
27+
using System.Windows.Forms;
2728

2829
namespace ORTS.Settings
2930
{
3031
public class RouteSettings
3132
{
33+
34+
3235
public enum DownloadType
3336
{
3437
github,
@@ -123,20 +126,32 @@ public void Load()
123126
// left empty
124127
}
125128

129+
private string RouteJsonName;
130+
126131
public void LoadContentAndInstalled()
127132
{
128-
if (!string.IsNullOrWhiteSpace(Content.RouteJsonName))
133+
// set json route filename
134+
135+
string userDataSettingsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.ProductName, "Settings");
136+
if (!Directory.Exists(userDataSettingsFolder))
137+
{
138+
Directory.CreateDirectory(userDataSettingsFolder);
139+
}
140+
141+
RouteJsonName = Path.Combine(userDataSettingsFolder, "ORRoute.json");
142+
143+
if (!string.IsNullOrWhiteSpace(RouteJsonName))
129144
{
130-
if (File.Exists(Content.RouteJsonName))
145+
if (File.Exists(RouteJsonName))
131146
{
132147
try
133148
{
134-
string json = File.ReadAllText(Content.RouteJsonName);
149+
string json = File.ReadAllText(RouteJsonName);
135150
Routes = JsonConvert.DeserializeObject<IDictionary<string, Route>>(json);
136151
}
137152
catch (Exception error)
138153
{
139-
throw new Exception("Error during reading " + Content.RouteJsonName + ": " + error.Message, error);
154+
throw new Exception("Error during reading " + RouteJsonName + ": " + error.Message, error);
140155
}
141156
}
142157
}
@@ -162,7 +177,7 @@ public void LoadContentAndInstalled()
162177
}
163178
catch (Exception error)
164179
{
165-
throw new Exception("Error during retrieving routes.json from \"" + githubUrl + "\":" + error.Message, error);
180+
throw new Exception("Error during retrieving routes.json from \"" + githubUrl + "\": " + error.Message, error);
166181
}
167182
}
168183

@@ -281,7 +296,7 @@ public void Save()
281296
}
282297
}
283298
string json = JsonConvert.SerializeObject(routes, Formatting.Indented);
284-
File.WriteAllText(Content.RouteJsonName, json);
299+
File.WriteAllText(RouteJsonName, json);
285300
}
286301
}
287302
}

0 commit comments

Comments
 (0)