Skip to content

Commit 31c983e

Browse files
committed
Automatic merge of T1.5.1-969-g2319f7f14 and 15 pull requests
- Pull request #799 at dfc715e: Consolidated wind simulation - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #882 at 48aa537: Blueprint/train car operations UI window - Pull request #891 at 9a1d6b2: Auto save - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #900 at c27f32d: DMI updates - Pull request #903 at c296b32: Downloading route content (Github, zip) - Pull request #912 at 0cb07c2: New Triple Valve Features Vol. 2 - Pull request #918 at c46eb0d: Manual - News topics updated since 1.5.1 - Pull request #919 at 26cc6a8: Added mouse wheel support for controls which can be moved by pressing t… - Pull request #922 at abe2e52: Autopilot for timetable mode - Pull request #923 at 4c27204: Add curve squeal to route - Pull request #943 at a0ffa96: Dynamic Brakes Behavior & Display Improvements
17 parents 2c1d744 + 2319f7f + dfc715e + d00beb9 + f92de76 + 48aa537 + 9a1d6b2 + 1f5ba4c + 5866028 + c27f32d + c296b32 + 0cb07c2 + c46eb0d + 26cc6a8 + abe2e52 + 4c27204 + a0ffa96 commit 31c983e

File tree

4 files changed

+74
-108
lines changed

4 files changed

+74
-108
lines changed

Source/Menu/DownloadContentForm.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public DownloadContentForm(UserSettings settings)
5858
Catalog = new GettextResourceManager("Menu");
5959
Settings = settings;
6060

61-
Settings.Routes.LoadContentAndInstalled();
62-
Routes = settings.Routes.Routes;
61+
Settings.Content.ContentRouteSettings.LoadContent();
62+
Routes = Settings.Content.ContentRouteSettings.Routes;
6363
for (int index = 0; index < Routes.Count; index++)
6464
{
6565
string routeName = Routes.ElementAt(index).Key;
@@ -79,7 +79,12 @@ public DownloadContentForm(UserSettings settings)
7979
cell.ToolTipText = cell.Value.ToString();
8080
}
8181

82-
InstallPathTextBox.Text = settings.Content.InstallPath;
82+
if (string.IsNullOrEmpty(settings.ContentInstallPath))
83+
{
84+
settings.ContentInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Open Rails", "Content");
85+
}
86+
87+
InstallPathTextBox.Text = settings.ContentInstallPath;
8388

8489
ImageTempFilename = Path.GetTempFileName();
8590
InfoTempFilename = Path.GetTempFileName();
@@ -152,7 +157,7 @@ private void dataGridViewDownloadContent_SelectionChanged(object sender, EventAr
152157
#region InstallPathTextBox
153158
private void InstallPathTextBox_TextChanged(object sender, EventArgs e)
154159
{
155-
Settings.Content.InstallPath = InstallPathTextBox.Text;
160+
Settings.ContentInstallPath = InstallPathTextBox.Text;
156161
}
157162
#endregion
158163

@@ -296,7 +301,7 @@ private async void DownloadContentButton_Click(object sender, EventArgs e)
296301
route.DirectoryInstalledIn = installPathRoute;
297302

298303
Settings.Folders.Save();
299-
Settings.Routes.Save();
304+
Settings.Content.Save();
300305

301306
if (!string.IsNullOrWhiteSpace(route.Start.Route))
302307
{
@@ -957,17 +962,23 @@ private async void DeleteButton_Click(object sender, EventArgs e)
957962
await Task.Run(() => deleteRoute(route.DirectoryInstalledIn));
958963
}
959964

960-
if (Settings.Folders.Folders[route.ContentName] == route.ContentDirectory)
965+
if (Settings.Folders.Folders.ContainsKey(route.ContentName))
961966
{
962-
Settings.Folders.Folders.Remove(route.ContentName);
967+
if (Settings.Folders.Folders[route.ContentName] == route.ContentDirectory)
968+
{
969+
Settings.Folders.Folders.Remove(route.ContentName);
970+
}
971+
Settings.Folders.Save();
963972
}
964-
Settings.Folders.Save();
965973

966974
route.Installed = false;
967975
route.DateInstalled = DateTime.MinValue;
968976
route.DirectoryInstalledIn = "";
969977

970-
Settings.Routes.Save();
978+
// remove from registry, but leave entry in Routes for this route name
979+
ContentRouteSettings.Route routeSaved = route;
980+
Settings.Content.Save();
981+
Routes[RouteName] = routeSaved;
971982

972983
dataGridViewDownloadContent.CurrentRow.Cells[1].Value = "";
973984

@@ -1053,8 +1064,10 @@ private bool doThePull(ContentRouteSettings.Route route) {
10531064
{
10541065
using (var repo = new Repository(route.DirectoryInstalledIn))
10551066
{
1056-
LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
1057-
options.FetchOptions = new FetchOptions();
1067+
LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions
1068+
{
1069+
FetchOptions = new FetchOptions()
1070+
};
10581071

10591072
// User information to create a merge commit
10601073
var signature = new LibGit2Sharp.Signature(

Source/ORTS.Settings/ContentRouteSettings.cs

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
using System;
2020
using System.Collections.Generic;
2121
using System.IO;
22-
using System.Linq;
2322
using Newtonsoft.Json;
2423
using Newtonsoft.Json.Linq;
2524
using LibGit2Sharp;
26-
using System.Windows.Forms;
2725

2826
namespace ORTS.Settings
2927
{
@@ -112,51 +110,18 @@ public DownloadType getDownloadType ()
112110
// RouteSettings are presented to the user in the menu DownloadContent form
113111
//
114112
// lines are a mix from:
115-
// - routes already downloaded, stored in {ApplicationData}\{ProductName\Settings\ORRoute.json",
116-
// eg: "C:\\Users\\Siebren\\AppData\\Roaming\\Open Rails\\Settings\ORRoute.json"
113+
// - routes already downloaded, stored in registry Computer\HKEY_CURRENT_USER\SOFTWARE\OpenRails\ORTS\ContentRoutes
117114
// - routes which can be downloaded, stored in GitHub "https://github.com/openrails/content.git" file routes.json
118115
//
119-
// this .cs file is not like all the other *Settings.cs files, which are derived from class SettingsBase
120-
// and store their settings in the registry
121-
// but since this class stores settings also, be it in a file, it looks like a good place
122-
//
123116
// where above the word route is mentioned, "Installation profile" is ment as can be found in OR's Main menu
124117

125118
public ContentRouteSettings()
126119
{
127120
Routes = new Dictionary<string, Route>();
128121
}
129122

130-
private string RouteJsonName;
131-
132-
public void LoadContentAndInstalled()
123+
public void LoadContent()
133124
{
134-
// set json route filename
135-
136-
string userDataSettingsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.ProductName, "Settings");
137-
if (!Directory.Exists(userDataSettingsFolder))
138-
{
139-
Directory.CreateDirectory(userDataSettingsFolder);
140-
}
141-
142-
RouteJsonName = Path.Combine(userDataSettingsFolder, "ORRoute.json");
143-
144-
if (!string.IsNullOrWhiteSpace(RouteJsonName))
145-
{
146-
if (File.Exists(RouteJsonName))
147-
{
148-
try
149-
{
150-
string json = File.ReadAllText(RouteJsonName);
151-
Routes = JsonConvert.DeserializeObject<IDictionary<string, Route>>(json);
152-
}
153-
catch (Exception error)
154-
{
155-
throw new Exception("Error during reading " + RouteJsonName + ": " + error.Message, error);
156-
}
157-
}
158-
}
159-
160125
// only for debug purposes
161126
string definedContentJsonName = @"c:\content\routes.json";
162127

@@ -310,21 +275,5 @@ private static void directoryRemoveReadOnlyFlags(string directoryName)
310275
directoryRemoveReadOnlyFlags(subDirectoryName);
311276
}
312277
}
313-
314-
public void Save()
315-
{
316-
IDictionary<string, Route> routes = new Dictionary<string, Route>();
317-
318-
for (int index = 0; index < Routes.Count; index++)
319-
{
320-
// only save the installed routes
321-
if (Routes.ElementAt(index).Value.Installed)
322-
{
323-
routes.Add(Routes.ElementAt(index));
324-
}
325-
}
326-
string json = JsonConvert.SerializeObject(routes, Formatting.Indented);
327-
File.WriteAllText(RouteJsonName, json);
328-
}
329278
}
330279
}

Source/ORTS.Settings/ContentSettings.cs

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,83 +15,85 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

18-
using System;
1918
using System.Collections.Generic;
20-
using System.IO;
21-
using System.Reflection;
19+
using Newtonsoft.Json;
2220
using ORTS.Common;
21+
using static ORTS.Settings.ContentRouteSettings;
2322

2423
namespace ORTS.Settings
2524
{
2625
public class ContentSettings : SettingsBase
2726
{
2827
#region User Settings
29-
30-
[Default("")]
31-
public string InstallPath { get; set; }
32-
28+
public ContentRouteSettings ContentRouteSettings;
3329
#endregion
3430

3531
public ContentSettings(IEnumerable<string> options)
36-
: base(SettingsStore.GetSettingStore(UserSettings.SettingsFilePath, UserSettings.RegistryKey, "Content"))
32+
: base(SettingsStore.GetSettingStore(UserSettings.SettingsFilePath, UserSettings.RegistryKey, "ContentRoutes"))
3733
{
34+
ContentRouteSettings = new ContentRouteSettings();
3835
Load(options);
39-
if (string.IsNullOrEmpty(InstallPath))
40-
{
41-
InstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) , "Open Rails", "Content");
42-
}
4336
}
4437

4538
public override object GetDefaultValue(string name)
4639
{
47-
var property = GetType().GetProperty(name);
48-
49-
if (property.GetCustomAttributes(typeof(DefaultAttribute), false).Length > 0)
50-
return (property.GetCustomAttributes(typeof(DefaultAttribute), false)[0] as DefaultAttribute).Value;
51-
52-
throw new InvalidDataException(String.Format("UserSetting {0} has no default value.", property.Name));
40+
return "";
5341
}
54-
public override void Reset()
42+
43+
protected override object GetValue(string name)
5544
{
56-
throw new System.NotImplementedException();
45+
return JsonConvert.SerializeObject(ContentRouteSettings.Routes[name], Formatting.Indented);
5746
}
5847

59-
public override void Save()
48+
protected override void SetValue(string name, object value)
6049
{
61-
foreach (var property in GetProperties())
62-
if (property.GetCustomAttributes(typeof(DoNotSaveAttribute), false).Length == 0)
63-
Save(property.Name, property.PropertyType);
50+
ContentRouteSettings.Routes[name] = JsonConvert.DeserializeObject<Route>((string)value);
6451
}
6552

66-
public override void Save(string name)
53+
protected override void Load(Dictionary<string, string> optionsDictionary)
6754
{
68-
throw new System.NotImplementedException();
55+
foreach (var name in SettingStore.GetUserNames())
56+
{
57+
Load(optionsDictionary, name, typeof(string));
58+
}
6959
}
7060

71-
protected override object GetValue(string name)
61+
public override void Save()
7262
{
73-
return GetProperty(name).GetValue(this, null);
74-
}
63+
foreach (var name in ContentRouteSettings.Routes.Keys)
64+
{
65+
if (ContentRouteSettings.Routes.ContainsKey(name))
66+
{
67+
if (ContentRouteSettings.Routes[name].Installed)
68+
{
69+
Save(name);
70+
}
71+
}
72+
}
7573

76-
PropertyInfo[] GetProperties()
77-
{
78-
return GetType().GetProperties();
79-
}
74+
foreach (var name in SettingStore.GetUserNames())
75+
{
76+
if (!ContentRouteSettings.Routes.ContainsKey(name) ||
77+
(!ContentRouteSettings.Routes[name].Installed))
78+
{
79+
var route = ContentRouteSettings.Routes[name];
80+
// remove from registry
81+
Reset(name);
82+
// ContentRouteSettings.Routes.Add(name, route);
83+
}
84+
85+
}
8086

81-
protected override void Load(Dictionary<string, string> optionsDictionary)
82-
{
83-
foreach (var property in GetProperties())
84-
Load(optionsDictionary, property.Name, property.PropertyType);
8587
}
8688

87-
PropertyInfo GetProperty(string name)
89+
public override void Save(string name)
8890
{
89-
return GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
91+
Save(name, typeof(string));
9092
}
9193

92-
protected override void SetValue(string name, object value)
94+
public override void Reset()
9395
{
94-
GetProperty(name).SetValue(this, value, null);
96+
throw new System.NotImplementedException();
9597
}
9698
}
9799
}

Source/ORTS.Settings/UserSettings.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,16 @@ public string DirectXFeatureLevel
438438
[Default(0)] // TrackMonitor.DisplayMode.All
439439
public int TrackMonitorDisplayMode { get; set; }
440440

441+
// Content form settings
442+
[Default("")]
443+
public string ContentInstallPath { get; set; }
444+
441445
#endregion
442446

443447
public FolderSettings Folders { get; private set; }
444448
public InputSettings Input { get; private set; }
445449
public RailDriverSettings RailDriver { get; private set; }
446-
public ContentSettings Content { get; private set; }
447-
public ContentRouteSettings Routes { get; private set; }
450+
public ContentSettings Content { get; private set; }
448451

449452
public UserSettings(IEnumerable<string> options)
450453
: base(SettingsStore.GetSettingStore(SettingsFilePath, RegistryKey, null))
@@ -457,7 +460,6 @@ public UserSettings(IEnumerable<string> options)
457460
Input = new InputSettings(options);
458461
RailDriver = new RailDriverSettings(options);
459462
Content = new ContentSettings(options);
460-
Routes = new ContentRouteSettings();
461463
}
462464

463465
/// <summary>

0 commit comments

Comments
 (0)