Skip to content

Commit

Permalink
Fixes:
Browse files Browse the repository at this point in the history
[*]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
  • Loading branch information
sweiland-openrails committed Apr 1, 2024
1 parent 29f3d1a commit 7af1f91
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
1 change: 1 addition & 0 deletions Source/Menu/DownloadContentForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 39 additions & 32 deletions Source/Menu/DownloadContentForm.cs
Expand Up @@ -142,6 +142,13 @@ private void dataGridViewDownloadContent_SelectionChanged(object sender, EventAr
}
#endregion

#region InstallPathTextBox
private void InstallPathTextBox_TextChanged(object sender, EventArgs e)
{
Settings.Content.InstallPath = InstallPathTextBox.Text;
}
#endregion

#region InstallPathBrowseButton
private void InstallPathBrowseButton_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -175,6 +182,14 @@ private async void DownloadContentButton_Click(object sender, EventArgs e)

DisableButtons();

message = Catalog.GetStringFmt("Route to be installed in \"{0}\", are you sure?", installPathRoute);
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
{
// cancelled
EnableButtons();
return;
}

// various checks for the directory where the route is installed

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

DriveInfo dInfo = new DriveInfo(installPathRoute);

long size = route.InstallSize + route.DownloadSize;

if (size > (dInfo.AvailableFreeSpace * 1.1))
try
{
message = Catalog.GetStringFmt("Not enough diskspace on drive {0} ({1}), available {2} kB, needed {3} kB, still continue?",
dInfo.Name,
dInfo.VolumeLabel,
(dInfo.AvailableFreeSpace / 1024).ToString("N0"),
(size / 1024).ToString("N0"));
DriveInfo dInfo = new DriveInfo(installPathRoute);

if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
{
// cancelled
EnableButtons();
return;
}
}
long size = route.InstallSize + route.DownloadSize;

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

if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
{
// cancelled
EnableButtons();
return;
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
{
// cancelled
EnableButtons();
return;
}
}
}

if (!Directory.Exists(installPath))
catch (System.IO.DriveNotFoundException)
{
message = Catalog.GetStringFmt("Directory \"{0}\" does not exist", installPath);
message = Catalog.GetStringFmt("Drive not available");
MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OK, MessageBoxIcon.Error);
// cancelled
EnableButtons();
return;
}
Expand Down Expand Up @@ -255,8 +264,6 @@ private async void DownloadContentButton_Click(object sender, EventArgs e)
}
}

Settings.Content.InstallPath = installPath;

// the download

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

message = Catalog.GetStringFmt("Directory \"{0}\" is to be deleted, are you really sure?", route.DirectoryInstalledIn);
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
{
// cancelled
EnableButtons();
Expand All @@ -935,7 +942,7 @@ private async void DeleteButton_Click(object sender, EventArgs e)
{
writeAndStartInfoFile();
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);
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
{
// cancelled
EnableButtons();
Expand Down Expand Up @@ -1006,7 +1013,7 @@ private void updateButton_Click(object sender, EventArgs e)
{
writeAndStartInfoFile();
message = Catalog.GetString("Remote updates found, see Info at the bottom for more information. Do you want to continue?");
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
{
// cancelled
EnableButtons();
Expand All @@ -1015,7 +1022,7 @@ private void updateButton_Click(object sender, EventArgs e)
if (areThereChangedAddedFiles(route))
{
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?");
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
{
// cancelled
EnableButtons();
Expand Down
6 changes: 5 additions & 1 deletion Source/ORTS.Settings/ContentSettings.cs
Expand Up @@ -27,7 +27,7 @@ public class ContentSettings : SettingsBase
{
#region User Settings

[Default("C:\\OpenRailsRoutes")]
[Default("")]
public string InstallPath { get; set; }

#endregion
Expand All @@ -36,6 +36,10 @@ public ContentSettings(IEnumerable<string> options)
: base(SettingsStore.GetSettingStore(UserSettings.SettingsFilePath, UserSettings.RegistryKey, "Content"))
{
Load(options);
if (string.IsNullOrEmpty(InstallPath))
{
InstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) , "Open Rails", "Content");
}
}

public override object GetDefaultValue(string name)
Expand Down

0 comments on commit 7af1f91

Please sign in to comment.