Skip to content

Commit

Permalink
Adds a WIX installer
Browse files Browse the repository at this point in the history
  • Loading branch information
replaysMike committed Feb 29, 2020
1 parent a7ca5d6 commit 02d9a92
Show file tree
Hide file tree
Showing 18 changed files with 2,315 additions and 111 deletions.
14 changes: 14 additions & 0 deletions AssemblyInfo/AssemblyInfo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@ VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssemblyInfo", "AssemblyInfo\AssemblyInfo.csproj", "{9AAB585F-C18C-4DC5-85FD-20902AC6732C}"
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "AssemblyInfoInstaller", "AssemblyInfoInstaller\AssemblyInfoInstaller.wixproj", "{25261EE2-F986-45C4-A292-A0DB0F1FBD81}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Debug|x86.ActiveCfg = Debug|Any CPU
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Debug|x86.Build.0 = Debug|Any CPU
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Release|Any CPU.Build.0 = Release|Any CPU
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Release|x86.ActiveCfg = Release|Any CPU
{9AAB585F-C18C-4DC5-85FD-20902AC6732C}.Release|x86.Build.0 = Release|Any CPU
{25261EE2-F986-45C4-A292-A0DB0F1FBD81}.Debug|Any CPU.ActiveCfg = Debug|x86
{25261EE2-F986-45C4-A292-A0DB0F1FBD81}.Debug|x86.ActiveCfg = Debug|x86
{25261EE2-F986-45C4-A292-A0DB0F1FBD81}.Debug|x86.Build.0 = Debug|x86
{25261EE2-F986-45C4-A292-A0DB0F1FBD81}.Release|Any CPU.ActiveCfg = Release|x86
{25261EE2-F986-45C4-A292-A0DB0F1FBD81}.Release|x86.ActiveCfg = Release|x86
{25261EE2-F986-45C4-A292-A0DB0F1FBD81}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 0 additions & 6 deletions AssemblyInfo/AssemblyInfo/App.config

This file was deleted.

35 changes: 35 additions & 0 deletions AssemblyInfo/AssemblyInfo/AssemblyData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace AssemblyInfo
{
public class AssemblyData
{
public string Name { get; set; }
public string ProductName { get; set; }
public string FileDescription { get; set; }
public string Description { get; set; }
public string Company { get; set; }
public string Version { get; set; }
public string FileVersion { get; set; }
public string ProductVersion { get; set; }
public bool IsStronglyNamed { get; set; }
public string PublicKeyToken { get; set; }
public string Framework { get; set; }
public string FrameworkVersion { get; set; }
public string Copyright { get; set; }
public string Build { get; set; }
public string DebuggableModes { get; set; }
public bool IsDebug { get; set; }
public bool IsPatched { get; set; }
public bool IsPreRelease { get; set; }
public string Language { get; set; }
public string OriginalFilename { get; set; }
public string FileSize { get; set; }
public long FileLength { get; set; }
public string Sha { get; set; }
public string Md5 { get; set; }
public bool IsClsCompliant { get; set; }
public string InformationalVersion { get; set; }
public string Metadata { get; set; }

public override string ToString() => Name;
}
}
33 changes: 33 additions & 0 deletions AssemblyInfo/AssemblyInfo/AssemblyDataFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Linq;
using System.Text;

namespace AssemblyInfo
{
public static class AssemblyDataFormatter
{
public static string GetAssemblyDataOutput(FormatterOutput formatterOutput, AssemblyData data)
{
var d = ",";
var sb = new StringBuilder();
var properties = typeof(AssemblyData).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).OrderBy(x => x.Name);
switch (formatterOutput)
{
case FormatterOutput.Parsable:
sb.AppendLine(string.Join(d, properties.Select(x => x.Name)));
sb.AppendLine(string.Join(d, properties.Select(x => x.GetValue(data))));
break;
case FormatterOutput.Pretty:
foreach (var property in properties)
sb.AppendLine($"{property.Name}: {property.GetValue(data)}");
break;
}
return sb.ToString();
}

public enum FormatterOutput
{
Pretty,
Parsable
}
}
}
21 changes: 19 additions & 2 deletions AssemblyInfo/AssemblyInfo/AssemblyInfo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9AAB585F-C18C-4DC5-85FD-20902AC6732C}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<RootNamespace>AssemblyInfo</RootNamespace>
<AssemblyName>AssemblyInfo</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
Expand All @@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -32,6 +33,18 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>AssemblyInfo_128.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>AssemblyInfo.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=2.7.82.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.2.7.82\lib\net461\CommandLine.dll</HintPath>
Expand All @@ -49,6 +62,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyData.cs" />
<Compile Include="AssemblyDataFormatter.cs" />
<Compile Include="AssemblyInspector.cs" />
<Compile Include="AssemlyInfoWindow.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -72,6 +88,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="AssemblyInfo.pfx" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -84,7 +101,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Content Include="AssemblyInfo_128.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file added AssemblyInfo/AssemblyInfo/AssemblyInfo_128.ico
Binary file not shown.
103 changes: 103 additions & 0 deletions AssemblyInfo/AssemblyInfo/AssemblyInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using AssemblyInfo.Extensions;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Versioning;
using System.Security.Cryptography;

namespace AssemblyInfo
{
public class AssemblyInspector
{
/// <summary>
/// Max 1GB hash inspection length
/// </summary>
private const int MaxHashInspectionLength = 1 * 1024 * 1024 * 1024;

public AssemblyData Inspect(string filename)
{
if (File.Exists(filename))
return InspectAssembly(filename);
throw new FileNotFoundException(filename);
}

private AssemblyData InspectAssembly(string filename)
{
var assembly = Assembly.LoadFrom(filename);
var assemblyName = assembly.GetName();
var version = assemblyName.Version;
var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
var targetFramework = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(TargetFrameworkAttribute));
var assemblyConfiguration = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(AssemblyConfigurationAttribute));
var clsCompliant = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(CLSCompliantAttribute));
var assemblyInformationalVersion = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(AssemblyInformationalVersionAttribute));
var assemblyMetadatas = assembly.CustomAttributes.Where(x => x.AttributeType == typeof(AssemblyMetadataAttribute)).ToList();
var debuggable = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DebuggableAttribute));
var debuggableAttributeArguments = debuggable.ConstructorArguments.FirstOrDefault();
var fileInfo = new FileInfo(filename);

var frameworkString = targetFramework?.ConstructorArguments?.FirstOrDefault().Value.ToString();
var targetFrameworkName = frameworkString
?.Split(new string[] { "," }, System.StringSplitOptions.None)
.FirstOrDefault();
var targetFrameworkVersion = frameworkString
?.Split(new string[] { "," }, System.StringSplitOptions.None)
// remove version label
?.Skip(1).FirstOrDefault()?.Split(new string[] { "="}, System.StringSplitOptions.None)
// remove v prepend
?.Skip(1).FirstOrDefault()?.Replace("v", "");
var metadata = assemblyMetadatas?.SelectMany(x => x.ConstructorArguments.Select(y => y.Value.ToString()));
var metadataKeys = metadata?.Where((x, i) => i % 2 == 0).ToList();
var metadataValues = metadata?.Skip(1).Where((x, i) => i % 2 == 0).ToList();
var data = new AssemblyData
{
Name = assembly.FullName,
ProductName = fileVersion.ProductName,
FileDescription = fileVersion.FileDescription,
Description = fileVersion.Comments,
Company = fileVersion.CompanyName,
Version = version.ToString(),
FileVersion = fileVersion.FileVersion,
ProductVersion = fileVersion.ProductVersion,
IsClsCompliant = (bool?)clsCompliant?.ConstructorArguments?.FirstOrDefault().Value ?? false,
InformationalVersion = assemblyInformationalVersion?.ConstructorArguments?.FirstOrDefault().Value.ToString(),
Metadata = string.Join(",", metadataKeys.Select((x, i) => $"{x}={metadataValues[i].ToString()}")),
IsStronglyNamed = assemblyName.GetPublicKeyToken().Length > 0,
PublicKeyToken = string.Join("", assemblyName.GetPublicKeyToken().Select(b => b.ToString("x2"))),
Framework = targetFrameworkName,
FrameworkVersion = targetFrameworkVersion,
Copyright = fileVersion.LegalCopyright,
Build = assemblyConfiguration?.ConstructorArguments?.FirstOrDefault().Value.ToString(),
IsDebug = fileVersion.IsDebug,
DebuggableModes = debuggableAttributeArguments != null ? ((DebuggableAttribute.DebuggingModes)debuggableAttributeArguments.Value).ToString() : string.Empty,
IsPatched = fileVersion.IsPatched,
IsPreRelease = fileVersion.IsPreRelease,
Language = fileVersion.Language,
OriginalFilename = fileVersion.OriginalFilename,
FileSize = Util.BytesToString(fileInfo.Length),
FileLength = fileInfo.Length
};

if (data.FileLength < MaxHashInspectionLength)
ComputeHash(data, filename);
return data;
}

private void ComputeHash(AssemblyData data, string filename)
{
var bytes = File.ReadAllBytes(filename);
using (var sha = SHA256.Create())
{
var shaHash = sha.ComputeHash(bytes);
data.Sha = AssemblyInfo.Extensions.ByteConverter.ToHex(shaHash);
}
using (var md5 = MD5.Create())
{
var md5Hash = md5.ComputeHash(bytes);
data.Md5 = AssemblyInfo.Extensions.ByteConverter.ToHex(md5Hash);
}
}
}
}
25 changes: 13 additions & 12 deletions AssemblyInfo/AssemblyInfo/AssemlyInfoWindow.Designer.cs

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

Loading

0 comments on commit 02d9a92

Please sign in to comment.