Skip to content

Commit 7af1f91

Browse files
Fixes:
[*]The default install path should be "{Documents}\Open Rails\Content" like other games [*]The install path does not get created when it does not exist [*]The install path setting does not seem to save as expected [*]The question dialogs should use "Yes" / "No" buttons
1 parent 29f3d1a commit 7af1f91

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

Source/Menu/DownloadContentForm.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Menu/DownloadContentForm.cs

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ private void dataGridViewDownloadContent_SelectionChanged(object sender, EventAr
142142
}
143143
#endregion
144144

145+
#region InstallPathTextBox
146+
private void InstallPathTextBox_TextChanged(object sender, EventArgs e)
147+
{
148+
Settings.Content.InstallPath = InstallPathTextBox.Text;
149+
}
150+
#endregion
151+
145152
#region InstallPathBrowseButton
146153
private void InstallPathBrowseButton_Click(object sender, EventArgs e)
147154
{
@@ -175,6 +182,14 @@ private async void DownloadContentButton_Click(object sender, EventArgs e)
175182

176183
DisableButtons();
177184

185+
message = Catalog.GetStringFmt("Route to be installed in \"{0}\", are you sure?", installPathRoute);
186+
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
187+
{
188+
// cancelled
189+
EnableButtons();
190+
return;
191+
}
192+
178193
// various checks for the directory where the route is installed
179194

180195
string pathDirectoryExe = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
@@ -191,39 +206,33 @@ private async void DownloadContentButton_Click(object sender, EventArgs e)
191206
return;
192207
}
193208

194-
DriveInfo dInfo = new DriveInfo(installPathRoute);
195-
196-
long size = route.InstallSize + route.DownloadSize;
197-
198-
if (size > (dInfo.AvailableFreeSpace * 1.1))
209+
try
199210
{
200-
message = Catalog.GetStringFmt("Not enough diskspace on drive {0} ({1}), available {2} kB, needed {3} kB, still continue?",
201-
dInfo.Name,
202-
dInfo.VolumeLabel,
203-
(dInfo.AvailableFreeSpace / 1024).ToString("N0"),
204-
(size / 1024).ToString("N0"));
211+
DriveInfo dInfo = new DriveInfo(installPathRoute);
205212

206-
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
207-
{
208-
// cancelled
209-
EnableButtons();
210-
return;
211-
}
212-
}
213+
long size = route.InstallSize + route.DownloadSize;
213214

214-
message = Catalog.GetStringFmt("Route to be installed in \"{0}\", are you sure?", installPathRoute);
215+
if (size > (dInfo.AvailableFreeSpace * 1.1))
216+
{
217+
message = Catalog.GetStringFmt("Not enough diskspace on drive {0} ({1}), available {2} kB, needed {3} kB, still continue?",
218+
dInfo.Name,
219+
dInfo.VolumeLabel,
220+
(dInfo.AvailableFreeSpace / 1024).ToString("N0"),
221+
(size / 1024).ToString("N0"));
215222

216-
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
217-
{
218-
// cancelled
219-
EnableButtons();
220-
return;
223+
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
224+
{
225+
// cancelled
226+
EnableButtons();
227+
return;
228+
}
229+
}
221230
}
222-
223-
if (!Directory.Exists(installPath))
231+
catch (System.IO.DriveNotFoundException)
224232
{
225-
message = Catalog.GetStringFmt("Directory \"{0}\" does not exist", installPath);
233+
message = Catalog.GetStringFmt("Drive not available");
226234
MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OK, MessageBoxIcon.Error);
235+
// cancelled
227236
EnableButtons();
228237
return;
229238
}
@@ -255,8 +264,6 @@ private async void DownloadContentButton_Click(object sender, EventArgs e)
255264
}
256265
}
257266

258-
Settings.Content.InstallPath = installPath;
259-
260267
// the download
261268

262269
dataGridViewDownloadContent.CurrentRow.Cells[1].Value = Catalog.GetString("Installing...");
@@ -922,7 +929,7 @@ private async void DeleteButton_Click(object sender, EventArgs e)
922929
DisableButtons();
923930

924931
message = Catalog.GetStringFmt("Directory \"{0}\" is to be deleted, are you really sure?", route.DirectoryInstalledIn);
925-
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
932+
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
926933
{
927934
// cancelled
928935
EnableButtons();
@@ -935,7 +942,7 @@ private async void DeleteButton_Click(object sender, EventArgs e)
935942
{
936943
writeAndStartInfoFile();
937944
message = Catalog.GetStringFmt("Changed or added local files found in Directory \"{0}\", see Info at the bottom for more information. Do you want to continue?", route.DirectoryInstalledIn);
938-
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
945+
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
939946
{
940947
// cancelled
941948
EnableButtons();
@@ -1006,7 +1013,7 @@ private void updateButton_Click(object sender, EventArgs e)
10061013
{
10071014
writeAndStartInfoFile();
10081015
message = Catalog.GetString("Remote updates found, see Info at the bottom for more information. Do you want to continue?");
1009-
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
1016+
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
10101017
{
10111018
// cancelled
10121019
EnableButtons();
@@ -1015,7 +1022,7 @@ private void updateButton_Click(object sender, EventArgs e)
10151022
if (areThereChangedAddedFiles(route))
10161023
{
10171024
message = Catalog.GetString("Changed or added local files found, Update might fail, see Info at the bottom for more information. Do you want to continue?");
1018-
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
1025+
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
10191026
{
10201027
// cancelled
10211028
EnableButtons();

Source/ORTS.Settings/ContentSettings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ContentSettings : SettingsBase
2727
{
2828
#region User Settings
2929

30-
[Default("C:\\OpenRailsRoutes")]
30+
[Default("")]
3131
public string InstallPath { get; set; }
3232

3333
#endregion
@@ -36,6 +36,10 @@ public ContentSettings(IEnumerable<string> options)
3636
: base(SettingsStore.GetSettingStore(UserSettings.SettingsFilePath, UserSettings.RegistryKey, "Content"))
3737
{
3838
Load(options);
39+
if (string.IsNullOrEmpty(InstallPath))
40+
{
41+
InstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) , "Open Rails", "Content");
42+
}
3943
}
4044

4145
public override object GetDefaultValue(string name)

0 commit comments

Comments
 (0)