Skip to content

Commit d7eb1f7

Browse files
committed
SP-2372: Hooked up SILAboutBox to call HtmlUtils.CreatePatchedTempHtmlFile
Documented previously undocumented feature: SILAboutBox constructor can accept either a filename or a file URI.
1 parent 08136d1 commit d7eb1f7

File tree

3 files changed

+52
-32
lines changed

3 files changed

+52
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3636

3737
- [SIL.WritingSystems] Updated embedded langtags.json
3838
- [SIL.WritingSystems] Updated embedded ianaSubtagRegistry.txt
39-
39+
- [SIL.Windows.Forms] Documented previously undocumented feature: SILAboutBox constructor can accept either a filename or a file URI.
4040

4141
## [16.0.0] - 2025-05-20
4242

SIL.Windows.Forms/Miscellaneous/SILAboutBox.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public event WebBrowserNavigatedEventHandler Navigated
8787
/// </summary>
8888
/// <param name="pathToAboutBoxHtml">For example, use
8989
/// <see cref="FileLocationUtilities.GetFileDistributedWithApplication(string[])"/>(
90-
/// "DistFiles", "AboutBox.htm")</param>
90+
/// "DistFiles", "AboutBox.htm"). This also can accept a file URI.</param>
9191
/// <param name="useFullVersionNumber"><c>false</c> to display only the first three
9292
/// parts of the version number, i.e. "MajorVersion.MinorVersion.Build",
9393
/// <c>true</c> to display the full version number as found in Application.ProductVersion.
@@ -99,7 +99,10 @@ public SILAboutBox(string pathToAboutBoxHtml, bool useFullVersionNumber = false,
9999
SilLogoVariant logoVariant = SilLogoVariant.Random)
100100
{
101101
_assembly = Assembly.GetEntryAssembly(); // assembly;
102-
_pathToAboutBoxHtml = pathToAboutBoxHtml;
102+
_pathToAboutBoxHtml =
103+
Uri.TryCreate(pathToAboutBoxHtml, UriKind.Absolute, out var uri) && uri.IsFile
104+
? uri.LocalPath
105+
: pathToAboutBoxHtml;
103106
InitializeComponent();
104107
_versionNumber.Text = useFullVersionNumber ? Application.ProductVersion :
105108
GetShortVersionInfo();
@@ -282,28 +285,7 @@ private void SILAboutBoxShown(object sender, EventArgs e)
282285
_browser.Navigate(_pathToAboutBoxHtml);
283286
else
284287
{
285-
// Note: the following comment also applies to the case where HandleMissingLinkTargets tweaks
286-
// the HTML, but hopefully that will be rare in production code.
287-
// Create a temporary file with the DependencyMarker replaced with our collected Acknowledgements.
288-
// This file will be deleted OnClosed.
289-
// This means that if your project uses the DependencyMarker in your html file, you will not be able to
290-
// link to a file on a relative path for css styles or images.
291-
// ----------
292-
// Comments on possible ways around this limitation from John Thomson:
293-
// 1.Document that an About Box HTML file which uses dependency injection must live in its own folder
294-
// with all dependent files, and copy the whole folder to a temp folder.
295-
// (could work but is a nuisance, especially for anyone who doesn't need any dependencies)
296-
// 2.Document that an About Box HTML file which uses dependency injection may only use a few common kinds
297-
// of relative links, search for matching links, and copy the appropriate files to a temp directory along
298-
// with the temp file.
299-
// (I rather like this idea. A fairly simple regular expression will search for src or rel followed by a value
300-
// with no path separators...something like(src | rel) = (['"])([^/\]*)\1 (or something similar...
301-
// handle white space...). That will catch all references to images, stylesheets, and scripts,
302-
// and if the bit of the RegEx that matches the filename corresponds to an existing file in the same folder
303-
// as the HTML we can just copy it. Unless they're doing relative paths to different folders that will do it,
304-
// and I think it's reasonable to have SOME restrictions in the interests of simplicity.
305-
// ----------
306-
_tempAboutBoxHtmlFile = new TempFile(newHtmlContents);
288+
_tempAboutBoxHtmlFile = HtmlUtils.CreatePatchedTempHtmlFile(newHtmlContents, _pathToAboutBoxHtml);
307289
_browser.Navigate(_tempAboutBoxHtmlFile.Path);
308290
}
309291
}

TestApps/SIL.Windows.Forms.TestApp/TestAppForm.cs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,16 @@ private void ShowSilAboutBox(XWebBrowser.BrowserType browserType, bool useFullVe
171171
string html;
172172
var handleNavigation = false;
173173
var allowExtLinksInsideAbout = false;
174+
var createCss = false;
174175
switch (_cboAboutHTML.SelectedIndex)
175176
{
176177
default: // Links without target attribute
177-
html = @"<html><head><meta charset='UTF-8' /></head>
178+
createCss = true;
179+
html = @"<html>
180+
<head>
181+
<meta charset='UTF-8' />
182+
<link rel=""stylesheet"" type=""text/css"" href=""aboutBox.css"" />
183+
</head>
178184
<body>
179185
<h3>Copyright 2025 <a href=""http://sil.org"">SIL Global</a></h3>
180186
<p>Testing the <b>about box</b></p>
@@ -214,10 +220,33 @@ private void ShowSilAboutBox(XWebBrowser.BrowserType browserType, bool useFullVe
214220
allowExtLinksInsideAbout = true;
215221
goto default;
216222
}
217-
using (var tempFile = TempFile.WithExtension("html"))
223+
224+
using var tempFile = TempFile.WithExtension("html");
225+
File.WriteAllText(tempFile.Path, html);
226+
227+
TempFile cssFile = null;
228+
if (createCss)
229+
{
230+
cssFile = TempFile.WithFilename("aboutBox.css");
231+
File.WriteAllText(cssFile.Path, @"
232+
body {
233+
font-family: sans-serif;
234+
}
235+
a {
236+
color: orange;
237+
text-decoration: underline;
238+
}
239+
a:visited {
240+
color: green;
241+
}
242+
a:hover {
243+
text-decoration: none;
244+
}
245+
");
246+
}
247+
248+
try
218249
{
219-
File.WriteAllText(tempFile.Path, html);
220-
221250
var uri = new Uri(tempFile.Path);
222251
using (var dlg = new SILAboutBox(uri.AbsoluteUri, useFullVersionNumber))
223252
{
@@ -230,16 +259,25 @@ private void ShowSilAboutBox(XWebBrowser.BrowserType browserType, bool useFullVe
230259
firstNav = false;
231260
return;
232261
}
262+
233263
args.Cancel = DialogResult.Cancel == MessageBox.Show(
234-
string.Format(LocalizationManager.GetString("About.ExternalNavigationConfirmationMsg",
235-
"Request to navigate to {0} with target frame {1}"), args.Url, args.TargetFrameName),
236-
LocalizationManager.GetString("About.ExternalNavigationConfirmationTitle",
264+
string.Format(LocalizationManager.GetString(
265+
"About.ExternalNavigationConfirmationMsg",
266+
"Request to navigate to {0} with target frame {1}"),
267+
args.Url,
268+
args.TargetFrameName),
269+
LocalizationManager.GetString(
270+
"About.ExternalNavigationConfirmationTitle",
237271
"External navigation request"), MessageBoxButtons.OKCancel);
238272
};
239273
dlg.AllowExternalLinksToOpenInsideAboutBox = allowExtLinksInsideAbout;
240274
dlg.ShowDialog();
241275
}
242276
}
277+
finally
278+
{
279+
cssFile?.Dispose();
280+
}
243281
}
244282

245283
private void OnShowReleaseNotesClicked(object sender, EventArgs e)

0 commit comments

Comments
 (0)