Skip to content

Commit 8fd2066

Browse files
When no internet connection is available, trying to start the Menu Content form gives an error message.
1 parent 7915033 commit 8fd2066

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

Source/Menu/ContentForm.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public partial class ContentForm : Form
6363

6464
private bool ManualInstallChangesMade = false;
6565

66+
private readonly bool NoInternet = false;
67+
6668
public ContentForm(UserSettings settings, string baseDocumentationUrl)
6769
{
6870
InitializeComponent();
@@ -84,7 +86,14 @@ public ContentForm(UserSettings settings, string baseDocumentationUrl)
8486
//
8587
// "Auto Installed" tab
8688
//
87-
Settings.Content.ContentRouteSettings.LoadContent();
89+
string errorMsg = "";
90+
Settings.Content.ContentRouteSettings.LoadContent(ref errorMsg);
91+
if (!string.IsNullOrEmpty(errorMsg))
92+
{
93+
string message = Catalog.GetStringFmt("Not connected to internet, automatic download not available. Error: {0}", errorMsg);
94+
MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OK, MessageBoxIcon.Error);
95+
NoInternet = true;
96+
}
8897
AutoInstallRoutes = Settings.Content.ContentRouteSettings.Routes;
8998
for (int index = 0; index < AutoInstallRoutes.Count; index++)
9099
{
@@ -143,6 +152,19 @@ public ContentForm(UserSettings settings, string baseDocumentationUrl)
143152
buttonCancel.Enabled = false;
144153

145154
setTextBoxesManualInstall();
155+
156+
if (NoInternet)
157+
{
158+
// open the Manually Installed tab since the Auto Installed tab needs internet
159+
tabControlContent.SelectTab(tabPageManuallyInstall);
160+
}
161+
162+
if (dataGridViewAutoInstall.Rows.Count == 0)
163+
{
164+
// disable all auto install buttons for a complete empty auto install grid
165+
// might be the case when no internet available
166+
DisableAutoInstallButtonsWithoutWait();
167+
}
146168
}
147169

148170
void changeManualInstallRoute(string Route)
@@ -272,9 +294,9 @@ private void dataGridViewAutoInstall_SelectionChanged(object sender, EventArgs e
272294
try
273295
{
274296
using (WebClient myWebClient = new WebClient())
275-
{
297+
{
276298
myWebClient.DownloadFile(AutoInstallRoutes[AutoInstallRouteName].Image, ImageTempFilename);
277-
}
299+
}
278300
if (File.Exists(ImageTempFilename))
279301
{
280302
pictureBoxAutoInstallRoute.Image = new Bitmap(ImageTempFilename);
@@ -1094,7 +1116,11 @@ void buttonAutoInstallOK_Click(object sender, EventArgs e)
10941116
private void DisableAutoInstallButtons()
10951117
{
10961118
setCursorToWaitCursor();
1119+
DisableAutoInstallButtonsWithoutWait();
1120+
}
10971121

1122+
private void DisableAutoInstallButtonsWithoutWait()
1123+
{
10981124
dataGridViewAutoInstall.Enabled = false;
10991125
textBoxAutoInstallPath.Enabled = false;
11001126
buttonAutoInstallBrowse.Enabled = false;
@@ -1119,9 +1145,9 @@ private void EnableAutoInstalButtons()
11191145
dataGridViewAutoInstall.Enabled = true;
11201146
textBoxAutoInstallPath.Enabled = true;
11211147
buttonAutoInstallBrowse.Enabled = true;
1122-
buttonAutoInstallInfo.Enabled = true;
1123-
buttonAutoInstallInstall.Enabled = !route.Installed;
1124-
buttonAutoInstallUpdate.Enabled = route.Installed && (route.getDownloadType() == ContentRouteSettings.DownloadType.github);
1148+
buttonAutoInstallInfo.Enabled = !NoInternet;
1149+
buttonAutoInstallInstall.Enabled = !(route.Installed || NoInternet);
1150+
buttonAutoInstallUpdate.Enabled = route.Installed && (route.getDownloadType() == ContentRouteSettings.DownloadType.github) && !NoInternet;
11251151
buttonAutoInstallDelete.Enabled = route.Installed;
11261152
buttonOK.Enabled = true;
11271153

Source/Orts.Settings/ContentRouteSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public ContentRouteSettings()
120120
Routes = new Dictionary<string, Route>();
121121
}
122122

123-
public void LoadContent()
123+
public void LoadContent(ref string errorMsg)
124124
{
125125
// only for debug purposes
126126
string definedContentJsonName = @"c:\content\routes.json";
@@ -142,8 +142,8 @@ public void LoadContent()
142142
definedContentJsonName = Path.Combine(definedContentJsonDirectoryName, "routes.json");
143143
}
144144
catch (Exception error)
145-
{
146-
throw new Exception("Error during retrieving routes.json from \"" + githubUrl + "\": " + error.Message, error);
145+
{
146+
errorMsg = error.Message;
147147
}
148148
}
149149

0 commit comments

Comments
 (0)