Skip to content

Commit

Permalink
File with runtime routeinformation ORRoute.json now hardcode placed i…
Browse files Browse the repository at this point in the history
…n C:\Users\<user>\AppData\Roaming\Open Rails\Settings
  • Loading branch information
sweiland-openrails committed Jan 18, 2024
1 parent dd0668f commit f1c7eb8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 0 additions & 4 deletions Source/Menu/DownloadContentForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ private void DownloadContentButton_Click(object sender, EventArgs e)

Settings.Content.InstallPath = installPath;

// set json route filename

Settings.Content.RouteJsonName = Path.Combine(installPath, "ORRoute.json");

// the download

Cursor.Current = Cursors.WaitCursor;
Expand Down
3 changes: 0 additions & 3 deletions Source/ORTS.Settings/ContentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class ContentSettings : SettingsBase
[Default("C:\\OpenRails")]
public string InstallPath { get; set; }

[Default("")]
public string RouteJsonName { get; set; }

#endregion

public ContentSettings(IEnumerable<string> options)
Expand Down
27 changes: 21 additions & 6 deletions Source/ORTS.Settings/RouteSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
using Newtonsoft.Json.Linq;
using LibGit2Sharp;
using ORTS.Common;
using System.Windows.Forms;

namespace ORTS.Settings
{
public class RouteSettings
{


public enum DownloadType
{
github,
Expand Down Expand Up @@ -123,20 +126,32 @@ public void Load()
// left empty
}

private string RouteJsonName;

public void LoadContentAndInstalled()
{
if (!string.IsNullOrWhiteSpace(Content.RouteJsonName))
// set json route filename

string userDataSettingsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.ProductName, "Settings");
if (!Directory.Exists(userDataSettingsFolder))
{
Directory.CreateDirectory(userDataSettingsFolder);
}

RouteJsonName = Path.Combine(userDataSettingsFolder, "ORRoute.json");

if (!string.IsNullOrWhiteSpace(RouteJsonName))
{
if (File.Exists(Content.RouteJsonName))
if (File.Exists(RouteJsonName))
{
try
{
string json = File.ReadAllText(Content.RouteJsonName);
string json = File.ReadAllText(RouteJsonName);
Routes = JsonConvert.DeserializeObject<IDictionary<string, Route>>(json);
}
catch (Exception error)
{
throw new Exception("Error during reading " + Content.RouteJsonName + ": " + error.Message, error);
throw new Exception("Error during reading " + RouteJsonName + ": " + error.Message, error);
}
}
}
Expand All @@ -162,7 +177,7 @@ public void LoadContentAndInstalled()
}
catch (Exception error)
{
throw new Exception("Error during retrieving routes.json from \"" + githubUrl + "\":" + error.Message, error);
throw new Exception("Error during retrieving routes.json from \"" + githubUrl + "\": " + error.Message, error);
}
}

Expand Down Expand Up @@ -281,7 +296,7 @@ public void Save()
}
}
string json = JsonConvert.SerializeObject(routes, Formatting.Indented);
File.WriteAllText(Content.RouteJsonName, json);
File.WriteAllText(RouteJsonName, json);
}
}
}

0 comments on commit f1c7eb8

Please sign in to comment.