Skip to content

Commit

Permalink
Embed manual.html in executable
Browse files Browse the repository at this point in the history
Embed HTML help file in CIL View binary to avoid issues when running from directory with non-latin characters in path.
  • Loading branch information
MSDN-WhiteKnight committed Dec 14, 2022
1 parent 6d954b9 commit b1179dd
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
10 changes: 10 additions & 0 deletions CilView.Core/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* License: BSD 2.0 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -195,5 +196,14 @@ public static bool IsMethodWithoutBody(MethodBase m)
}
else return false;
}

public static string ReadEmbeddedResource(Assembly assembly, string nspace, string name)
{
using (Stream stream = assembly.GetManifestResourceStream(nspace + "." + name))
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
4 changes: 1 addition & 3 deletions CilView/CilView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@
<Content Include="license.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="manual.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="manual.html" />
<Content Include="readme.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
7 changes: 3 additions & 4 deletions CilView/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,9 @@ void OnHelpClick()
{
try
{
string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(dir, "manual.html");

HtmlViewWindow wnd = new HtmlViewWindow(path);
Type t = typeof(MainWindow);
string content = Utils.ReadEmbeddedResource(t.Assembly, t.Namespace, "manual.html");
HtmlViewWindow wnd = new HtmlViewWindow(content);
wnd.Owner = this;
wnd.Title = "CIL View Help";
wnd.Show();
Expand Down
4 changes: 2 additions & 2 deletions CilView/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
// в приложении или в каких-либо словарях ресурсов для конкретной темы)
)]

[assembly: AssemblyVersion("2.5.0.1")]
[assembly: AssemblyFileVersion("2.5.0.1")]
[assembly: AssemblyVersion("2.5.0.2")]
[assembly: AssemblyFileVersion("2.5.0.2")]
4 changes: 1 addition & 3 deletions CilView/UI.Dialogs/HtmlViewWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* License: BSD 2.0 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows;

Expand All @@ -14,10 +13,9 @@ namespace CilView.UI.Dialogs
/// </summary>
public partial class HtmlViewWindow : Window
{
public HtmlViewWindow(string filepath)
public HtmlViewWindow(string content)
{
InitializeComponent();
string content = File.ReadAllText(filepath);
this.content.NavigateToString(content);
}

Expand Down
4 changes: 4 additions & 0 deletions CilView/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ Changelog
- Fix literal syntax for enum and boolean types
- Fix `serializable` attribute handling

2.5.0.2

- Fix help when running from directory with non-latin characters in path

---------------------------------------------

Copyright (c) 2022, MSDN.WhiteKnight
3 changes: 1 addition & 2 deletions scripts/package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ $fileList = "CilTools.BytecodeAnalysis.dll",
"Newtonsoft.Json.dll",
"license.txt",
"ReadMe.txt",
"credits.txt",
"manual.html"
"credits.txt"

foreach ($file in $fileList)
{
Expand Down

0 comments on commit b1179dd

Please sign in to comment.