Skip to content

Commit

Permalink
feat: improved error message dialog for all errors; updated message f…
Browse files Browse the repository at this point in the history
…or missing external cabs


* Improved error message for the specific case of missing external cab file
* Better UI for users to read error messages/information
* Users can copy/paste error details
closes #148
  • Loading branch information
activescott authored Oct 13, 2020
1 parent 93e2067 commit 57b364b
Show file tree
Hide file tree
Showing 8 changed files with 887 additions and 535 deletions.
1 change: 1 addition & 0 deletions src/LessMsi.Core/LessMsi.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Msi\ColumnInfo.cs" />
<Compile Include="Msi\ExternalCabNotFoundException.cs" />
<Compile Include="Msi\MsiDirectory.cs" />
<Compile Include="Msi\MsiFile.cs" />
<Compile Include="Msi\TableWrapper.cs" />
Expand Down
33 changes: 33 additions & 0 deletions src/LessMsi.Core/Msi/ExternalCabNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LessMsi.Msi
{
/// <summary>
/// Thrown when the msi file indicates there should be an external .cab file (i.e. not embedded inside the MSI, but saved along side it) but that cab file does not exist.
/// </summary>
public class ExternalCabNotFoundException : Exception
{
public static ExternalCabNotFoundException CreateFromCabPath(string cabFileName, string expectedLocation)
{
var msg = string.Format("This msi file references a CAB file that is not embedded inside of the msi file itself. The msi file is named {0} and was expected to be in the following folder: {1}", cabFileName, expectedLocation);
return new ExternalCabNotFoundException(msg);
}

public ExternalCabNotFoundException()
{
}

public ExternalCabNotFoundException(string message)
: base(message)
{
}

public ExternalCabNotFoundException(string message, Exception inner)
: base(message, inner)
{
}
}
}
7 changes: 6 additions & 1 deletion src/LessMsi.Core/Msi/Wixtracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ private static List<CabInfo> CabsFromMsiToDisk(Path msi, Database msidb, string
if (!string.IsNullOrEmpty(cabSourceName))
{
bool extract = false;
if (cabSourceName.StartsWith("#"))
// NOTE: If the cabinet name is preceded by the number sign, the cabinet is stored as a data stream inside the package. https://docs.microsoft.com/en-us/windows/win32/msi/cabinet
if (cabSourceName.StartsWith("#"))
{
extract = true;
cabSourceName = cabSourceName.Substring(1);
Expand All @@ -501,6 +502,10 @@ private static List<CabInfo> CabsFromMsiToDisk(Path msi, Database msidb, string
else
{
Path originalCabFile = Path.Combine(msi.Parent, cabSourceName);
if (!originalCabFile.Exists)
{
throw ExternalCabNotFoundException.CreateFromCabPath(cabSourceName, msi.Parent.FullPathString);
}
FileSystem.Copy(originalCabFile, localCabFile);
}
/* http://code.google.com/p/lessmsi/issues/detail?id=1
Expand Down
9 changes: 9 additions & 0 deletions src/LessMsi.Gui/LessMsi.Gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="Windows.Forms\ElevationNativeMethods.cs" />
<Compile Include="Windows.Forms\ErrorDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Windows.Forms\ErrorDialog.Designer.cs">
<DependentUpon>ErrorDialog.cs</DependentUpon>
</Compile>
<Compile Include="Windows.Forms\SearchPanel.cs">
<SubType>UserControl</SubType>
</Compile>
Expand All @@ -115,6 +121,9 @@
<EmbeddedResource Include="PreferencesForm.resx">
<DependentUpon>PreferencesForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Windows.Forms\ErrorDialog.resx">
<DependentUpon>ErrorDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Windows.Forms\SearchPanel.resx">
<DependentUpon>SearchPanel.cs</DependentUpon>
</EmbeddedResource>
Expand Down
1,068 changes: 534 additions & 534 deletions src/LessMsi.Gui/MainForm.cs

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions src/LessMsi.Gui/Windows.Forms/ErrorDialog.Designer.cs

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

25 changes: 25 additions & 0 deletions src/LessMsi.Gui/Windows.Forms/ErrorDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Windows.Forms;

namespace LessMsi.Gui.Windows.Forms
{
public partial class ErrorDialog : Form
{
public ErrorDialog()
{
InitializeComponent();
}

public static void ShowError(IWin32Window owner, string message, string technicalDetails)
{
var dlg = new ErrorDialog();
dlg.txtErrorDetail.Text = string.Format("{0}\r\n\r\nTechnical Detail:\r\n\r\n{1}", message, technicalDetails);
dlg.ShowDialog(owner);
}

private void lblPleaseReportLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
var target = "https://github.com/activescott/lessmsi/issues/";
System.Diagnostics.Process.Start(target);
}
}
}
123 changes: 123 additions & 0 deletions src/LessMsi.Gui/Windows.Forms/ErrorDialog.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="lblPleaseReportLink.Text" xml:space="preserve">
<value>An error has occurred. This may be a problem with the msi file or it may be a problem with this application. If you think this might be an error this application please report it, along with the error details below, at the following location: https://github.com/activescott/lessmsi/issues/</value>
</data>
</root>

0 comments on commit 57b364b

Please sign in to comment.