Skip to content

Commit 7353625

Browse files
Added Info button, shows info on webpage for selected route
1 parent 22edf27 commit 7353625

File tree

3 files changed

+142
-10
lines changed

3 files changed

+142
-10
lines changed

Source/Menu/DownloadContentForm.Designer.cs

Lines changed: 15 additions & 2 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: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public partial class DownloadContentForm : Form
4343

4444
private readonly string ImageTempFilename;
4545
private Thread ImageThread;
46+
private readonly string InfoTempFilename;
4647

4748
public DownloadContentForm(UserSettings settings)
4849
{
@@ -65,6 +66,9 @@ public DownloadContentForm(UserSettings settings)
6566
InstallPathTextBox.Text = settings.Content.InstallPath;
6667

6768
ImageTempFilename = Path.GetTempFileName();
69+
InfoTempFilename = Path.GetTempFileName();
70+
File.Delete(InfoTempFilename);
71+
InfoTempFilename = Path.ChangeExtension(ImageTempFilename, "html");
6872
}
6973

7074
void dataGridViewDownloadContent_SelectionChanged(object sender, EventArgs e)
@@ -234,6 +238,7 @@ private void DownloadContentButton_Click(object sender, EventArgs e)
234238
dataGridViewDownloadContent.CurrentRow.Cells[1].Value = dateTimeNowStr;
235239

236240
Routes[RouteName].DateInstalled = dateTimeNowStr;
241+
Routes[RouteName].DirectoryInstalledIn = installPathRoute;
237242

238243
Settings.Folders.Save();
239244
Settings.Routes.Save();
@@ -454,6 +459,73 @@ private bool insertRowInOptions(string installPathRoute)
454459
return true;
455460
}
456461

462+
private void InfoButton_Click(object sender, EventArgs e)
463+
{
464+
465+
using (StreamWriter outputFile = new StreamWriter(InfoTempFilename))
466+
{
467+
RouteSettings.Route route = Routes[RouteName];
468+
469+
outputFile.WriteLine(string.Format("<h3>{0}:</h3>\n", RouteName));
470+
471+
string description = route.Description.Replace("\n", "<br />");
472+
outputFile.WriteLine(string.Format("<p>{0}</p>\n", description));
473+
474+
outputFile.WriteLine(string.Format("<img height='350' width='600' src = '{0}'/>\n", route.Image));
475+
476+
if (string.IsNullOrWhiteSpace(route.AuthorUrl))
477+
{
478+
outputFile.WriteLine(string.Format("<p>created by : {0}</p>\n",
479+
route.AuthorName));
480+
}
481+
else
482+
{
483+
outputFile.WriteLine(string.Format("<p>created by : <a href='{0}'>{1}</a></p>\n",
484+
route.AuthorUrl, route.AuthorName));
485+
}
486+
487+
if (!string.IsNullOrWhiteSpace(route.Screenshot))
488+
{
489+
outputFile.WriteLine(string.Format("<p>screenshots: <a href='{0}'>{1}</a></p>\n",
490+
route.Screenshot, route.Screenshot));
491+
}
492+
493+
if (route.Url.EndsWith("git"))
494+
{
495+
outputFile.WriteLine(String.Format("<p>Downloadable: GitHub format<br>\n"));
496+
outputFile.WriteLine(String.Format("- From: {0}<br>\n", route.Url));
497+
if (route.InstallSize > 0)
498+
{
499+
outputFile.WriteLine(String.Format("- Install size: {0} GB<br></p>\n", (route.InstallSize / (1024.0 * 1024 * 1024)).ToString("N")));
500+
}
501+
}
502+
if (route.Url.EndsWith("zip"))
503+
{
504+
outputFile.WriteLine(String.Format("<p>Downloadable: zip format<br>\n"));
505+
outputFile.WriteLine(String.Format("- From: {0}<br>\n", route.Url));
506+
if (route.InstallSize > 0)
507+
{
508+
outputFile.WriteLine(String.Format("- Install size: {0} GB<br>\n", (route.InstallSize / (1024.0 * 1024 * 1024)).ToString("N")));
509+
}
510+
if (route.DownloadSize > 0)
511+
{
512+
outputFile.WriteLine(String.Format("- Download size: {0} GB<br></p>\n", (route.DownloadSize / (1024.0 * 1024 * 1024)).ToString("N")));
513+
}
514+
}
515+
516+
if (!string.IsNullOrWhiteSpace(route.DateInstalled))
517+
{
518+
outputFile.WriteLine(String.Format("<p>Installed:<br>\n"));
519+
outputFile.WriteLine(String.Format("- at: {0}<br>\n", route.DateInstalled));
520+
outputFile.WriteLine(String.Format("- in: \"{0}\"<br></p>\n", route.DirectoryInstalledIn));
521+
}
522+
}
523+
524+
// show html file in default browser
525+
System.Diagnostics.Process.Start(InfoTempFilename);
526+
}
527+
528+
457529
private void DownloadContentForm_FormClosing(object sender, FormClosingEventArgs e)
458530
{
459531
try
@@ -464,10 +536,11 @@ private void DownloadContentForm_FormClosing(object sender, FormClosingEventArgs
464536
pictureBoxRoute.Image = null;
465537
}
466538
File.Delete(ImageTempFilename);
539+
File.Delete(InfoTempFilename);
467540
}
468541
catch
469542
{
470-
// just ignore, it's a file in the user temp directory anyway
543+
// just ignore, the files are the user temp directory anyway
471544
}
472545
}
473546
}

Source/ORTS.Settings/RouteSettings.cs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public class RouteSettings
3030
{
3131
public class Route
3232
{
33-
public string DateInstalled { get; set; }
34-
public string Url { get; set; }
33+
public string DateInstalled;
34+
35+
public string DirectoryInstalledIn;
36+
public string Url;
3537

3638
public long DownloadSize;
3739
public long InstallSize;
@@ -40,14 +42,27 @@ public class Route
4042

4143
public string Description;
4244

43-
public Route(string dateInstalled, string url, long downloadSize, long installSize, string image, string description)
45+
public string AuthorName;
46+
public string AuthorUrl;
47+
48+
public string Screenshot;
49+
50+
public Route(string dateInstalled, string directoryInstalledIn, string url,
51+
long downloadSize, long installSize,
52+
string image, string description,
53+
string author, string authorUrl,
54+
string screenshot)
4455
{
4556
DateInstalled = dateInstalled;
57+
DirectoryInstalledIn = directoryInstalledIn;
4658
Url = url;
4759
DownloadSize = downloadSize;
4860
InstallSize = installSize;
4961
Image = image;
5062
Description = description;
63+
AuthorName = author;
64+
AuthorUrl = authorUrl;
65+
Screenshot = screenshot;
5166
}
5267
}
5368

@@ -86,14 +101,16 @@ public void LoadContentAndInstalled()
86101
}
87102
}
88103

104+
// only for debug purposes
89105
string definedContentJsonName = @"d:\content\routes.json";
90106

91107
string definedContentJsonDirectoryName = Path.GetTempFileName();
92108
File.Delete(definedContentJsonDirectoryName);
93109

94110
string githubUrl = "https://github.com/openrails/content.git";;
95111

96-
if (Environment.GetEnvironmentVariable("TstLoadContentAndInstalled") == null)
112+
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TstLoadContentAndInstalled")) ||
113+
(Environment.GetEnvironmentVariable("TstLoadContentAndInstalled") != "1"))
97114
{
98115
try
99116
{
@@ -124,12 +141,22 @@ public void LoadContentAndInstalled()
124141
long installSize = convertResultToLong(result, "installSize");
125142
string image = convertResultToString(result, "image");
126143
string description = convertResultToString(result, "description");
144+
JToken author = result["author"];
145+
string authorName = convertResultToString(author, "name");
146+
string authorUrl = convertResultToString(author, "url");
147+
string screenshot = convertResultToString(result, "screenshot");
127148

128149
if (url.EndsWith(".git") || url.EndsWith(".zip"))
129150
{
130151
if (!Routes.ContainsKey(routeName))
131152
{
132-
Routes.Add(routeName, new RouteSettings.Route("", url, downloadSize, installSize, image, description));
153+
Routes.Add(routeName, new RouteSettings.Route(
154+
"", "", url, downloadSize, installSize, image, description, authorName, authorUrl, screenshot));
155+
}
156+
else
157+
{
158+
update(Routes[routeName],
159+
url, downloadSize, installSize, image, description, authorName, authorUrl, screenshot);
133160
}
134161
}
135162
}
@@ -145,6 +172,23 @@ public void LoadContentAndInstalled()
145172
return;
146173
}
147174

175+
private void update(Route route,
176+
string url,
177+
long downloadSize, long installSize,
178+
string img, string description,
179+
string authorName, string authorUrl,
180+
string screenshot)
181+
{
182+
route.Url = url;
183+
route.DownloadSize = downloadSize;
184+
route.InstallSize = installSize;
185+
route.Image = img;
186+
route.Description = description;
187+
route.AuthorName = authorName;
188+
route.AuthorUrl = authorUrl;
189+
route.Screenshot = screenshot;
190+
}
191+
148192
private long convertResultToLong(JToken result, string fieldName)
149193
{
150194
if (result[fieldName] != null)
@@ -183,8 +227,10 @@ private void directoryRemoveReadOnlyFlags(string directoryName)
183227
{
184228
foreach (string filename in Directory.GetFiles(directoryName))
185229
{
186-
FileInfo file = new FileInfo(filename);
187-
file.IsReadOnly = false;
230+
_ = new FileInfo(filename)
231+
{
232+
IsReadOnly = false
233+
};
188234
}
189235
foreach (string subDirectoryName in Directory.GetDirectories(directoryName))
190236
{

0 commit comments

Comments
 (0)