Initial commit

This commit is contained in:
Holger Boerchers
2018-03-21 20:07:40 +01:00
commit d383f0ef1c
77 changed files with 7050 additions and 0 deletions

26
Creator/App.config Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Frameworks" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Versioning" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Packaging" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,62 @@
using System.ComponentModel;
using System.IO;
namespace KattekerCreator
{
public class ApplicationArguments
{
private string _changeLog;
private string _channel;
private string _outputDir;
private string _programFile;
private string _publishDir;
[DisplayName("Program")]
[Description("Path to the program file")]
public string ProgramFile
{
get => _programFile;
set => SetPropertyIfNotDefault(ref _programFile, Path.GetFullPath(value));
}
[DisplayName("Changelog")]
[Description("Filename of the changelog file")]
public string ChangeLog
{
get => _changeLog;
set => SetPropertyIfNotDefault(ref _changeLog, value);
}
[DisplayName("Channel")]
[Description("Channel of releasing.")]
public string Channel
{
get => _channel;
set => SetPropertyIfNotDefault(ref _channel, value);
}
[DisplayName("OutDir")]
[Description("Directory for output")]
public string OutputDir
{
get => _outputDir;
set => SetPropertyIfNotDefault(ref _outputDir, value);
}
[DisplayName("PublishDir")]
[Description("Path for output from the point of view of the application.")]
public string PublishDir
{
get => _publishDir;
set => SetPropertyIfNotDefault(ref _publishDir, value);
}
private static bool SetPropertyIfNotDefault<T>(ref T field, T value)
{
if (Equals(value, field)) return false;
if (!Equals(field, default(T))) return false;
field = value;
return true;
}
}
}

View File

@ -0,0 +1,93 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using Katteker;
using TsudaKageyu;
using Vestris.ResourceLib;
namespace KattekerCreator
{
public class AssemblyFileInfo
{
private readonly string _company;
private readonly string _copyright;
private readonly string _description;
private readonly string _productName;
public AssemblyFileInfo(string fileName, string tempDir)
{
FileInfo = new FileInfo(fileName);
using (var resourceInfo = new ResourceInfo())
{
resourceInfo.Load(fileName);
var versionResource = (VersionResource) resourceInfo[Kernel32.ResourceTypes.RT_VERSION].First();
var stringFileInfo = ((StringFileInfo) versionResource[nameof(StringFileInfo)]).Strings.FirstOrDefault()
.Value;
AssemblyIconPath = GetAssemblyIcon(fileName, tempDir);
if (stringFileInfo.Strings.ContainsKey("CompanyName"))
_company = stringFileInfo.Strings["CompanyName"].StringValue;
if (stringFileInfo.Strings.ContainsKey("FileDescription"))
_description = stringFileInfo.Strings["FileDescription"].StringValue;
if (stringFileInfo.Strings.ContainsKey("LegalCopyright"))
_copyright = stringFileInfo.Strings["LegalCopyright"].StringValue;
if (stringFileInfo.Strings.ContainsKey("ProductName"))
_productName = stringFileInfo.Strings["ProductName"].StringValue;
if (!stringFileInfo.Strings.ContainsKey("ProductVersion")) return;
AssemblyVersion = GetSemanticVersion(stringFileInfo.Strings["ProductVersion"].StringValue);
}
}
public string AssemblyIconPath { get; }
public SemanticVersion AssemblyVersion { get; private set; }
public string Company => _company ?? string.Empty;
public string Copyright => _copyright ?? string.Empty;
public string Description => _description ?? string.Empty;
public FileInfo FileInfo { get; }
public string ProductName => _productName ?? Description;
private static string GetAssemblyIcon(string programFile, string tempDir)
{
var applicationIcon = Path.Combine(tempDir, "application.ico");
if (string.IsNullOrWhiteSpace(programFile)) throw new ApplicationException("Program not set.");
if (!File.Exists(programFile)) throw new ApplicationException("Program not found.");
if (File.Exists(applicationIcon)) File.Delete(applicationIcon);
using (var fileStream = new FileStream(applicationIcon, FileMode.CreateNew))
{
try
{
var ie = new IconExtractor(programFile);
using (var icon = ie.GetIcon(0))
{
icon?.Save(fileStream);
}
}
catch (Exception)
{
using (var icon = Icon.ExtractAssociatedIcon(programFile))
{
icon?.Save(fileStream);
}
}
}
return applicationIcon;
}
private static SemanticVersion GetSemanticVersion(string productVersion)
{
if (!SemanticVersion.TryParse(productVersion, out var semanticVersion))
{
Version.TryParse(productVersion, out var version);
return SemanticVersion.Parse(version.ToString(3));
}
return semanticVersion?.Change(build: string.Empty);
}
}
}

51
Creator/Helper/Log.cs Normal file
View File

@ -0,0 +1,51 @@
using System;
namespace KattekerCreator.Helper
{
public static class Log
{
private const string Info = "INFO";
private const string Error = "ERROR";
public static void WriteInfoLine(string text)
{
using (var c = new ConsoleWithOtherColor())
{
c.WriteLine($"{Info} [{DateTime.Now:G}] {text}");
}
}
public static void WriteErrorLine(string text)
{
using (var c = new ConsoleWithOtherColor(ConsoleColor.DarkRed))
{
c.WriteLine($"{Error} [{DateTime.Now:G}] {text}");
}
}
}
public class ConsoleWithOtherColor : IDisposable
{
public ConsoleWithOtherColor()
{
}
private readonly ConsoleColor? _defaultColor;
public ConsoleWithOtherColor(ConsoleColor color)
{
_defaultColor = Console.ForegroundColor;
Console.ForegroundColor = color;
}
public void WriteLine(string text)
{
Console.WriteLine(text);
}
public void Dispose()
{
if (_defaultColor != null) Console.ForegroundColor = _defaultColor.Value;
}
}
}

View File

@ -0,0 +1,166 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
namespace KattekerCreator.Helper
{
public class SimpleCommandLineParser<TObject> where TObject : new()
{
private TObject _parsedObject;
public SimpleCommandLineParser(IEnumerable<string> args)
{
Parse(args);
}
private IDictionary<string, string[]> Arguments { get; } = new Dictionary<string, string[]>();
public bool Contains(string name) => Arguments.ContainsKey(name);
public TObject GetObject()
{
if (!EqualityComparer<TObject>.Default.Equals(_parsedObject, default(TObject)))
return _parsedObject;
_parsedObject = new TObject();
try
{
LoopProperties(pi =>
{
var displayName = GetDisplayName(pi);
if (displayName == null) return;
if (!Arguments.TryGetValue(displayName.ToLowerInvariant(), out var argument)) return;
if (pi.PropertyType == typeof(bool))
{
pi.SetValue(_parsedObject, true);
return;
}
if (pi.PropertyType.IsArray)
pi.SetValue(_parsedObject, argument);
else
pi.SetValue(_parsedObject, argument.FirstOrDefault());
});
}
catch (Exception e)
{
Log.WriteErrorLine("Error parsing commandline arguments: " + e.Message);
ShowHelp();
}
return _parsedObject;
}
public void ShowHelp(TextWriter textWriter = null)
{
if (textWriter == null) textWriter = Console.Out;
var executable = Assembly.GetExecutingAssembly().GetName().Name + ".exe";
var assemblyTitle = ((AssemblyTitleAttribute) Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute), false))?.Title ?? executable;
var assemblyDescription = ((AssemblyDescriptionAttribute) Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyDescriptionAttribute), false))?.Description;
textWriter.WriteLine();
textWriter.WriteLine(assemblyTitle);
textWriter.WriteLine();
textWriter.WriteLine(assemblyDescription);
textWriter.WriteLine();
textWriter.WriteLine(executable + " <options>");
textWriter.WriteLine();
var dict = new Dictionary<string, string>();
LoopProperties(pi =>
{
var displayName = GetDisplayName(pi);
if (displayName == null) return;
var description = GetDescription(pi);
if (pi.PropertyType == typeof(bool)) description = "(Switch) " + description;
dict.Add(displayName, description);
});
var longestWord = dict.Keys.Max(x => x.Length);
foreach (var kv in dict)
{
textWriter.Write("-" + kv.Key.PadRight(longestWord + 3, ' '));
textWriter.WriteLine(kv.Value);
}
textWriter.WriteLine();
textWriter.WriteLine("A switch will be set to true, if it will called.");
textWriter.WriteLine($"Example: {executable} <Switch>");
textWriter.WriteLine();
textWriter.WriteLine("A parameter will be set.");
textWriter.WriteLine($"Example: {executable} <Key> \"Value\"");
}
/// <summary>
/// Shows the current set options.
/// </summary>
/// <param name="textWriter">If not set Console.Out will be set.</param>
public void ShowProgramArguments(TextWriter textWriter = null)
{
if (textWriter == null) textWriter = Console.Out;
LoopProperties(pi =>
{
var displayName = GetDisplayName(pi) ?? pi.Name;
var value = pi.GetValue(_parsedObject);
textWriter.Write(displayName.PadRight(20, ' '));
if (value == null)
{
textWriter.WriteLine("<NOT SET>");
}
else
{
if (value.GetType().IsArray)
{
var arrayAsString = ((IEnumerable) value)
.Cast<object>()
.Aggregate(string.Empty, (current, x) => current + x?.ToString() + ", ");
textWriter.WriteLine(arrayAsString);
}
else
{
textWriter.WriteLine(value.ToString());
}
}
});
}
private static TAttribute GetAttribute<TAttribute>(MemberInfo memberInfo) where TAttribute : Attribute =>
(TAttribute) Attribute.GetCustomAttribute(memberInfo, typeof(TAttribute));
private static string GetDescription(MemberInfo memberInfo) => GetAttribute<DescriptionAttribute>(memberInfo)?.Description;
private static string GetDisplayName(MemberInfo memberInfo) => GetAttribute<DisplayNameAttribute>(memberInfo)?.DisplayName;
private static void LoopProperties(Action<PropertyInfo> action)
{
var properties = typeof(TObject).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var propertyInfo in properties)
action.Invoke(propertyInfo);
}
private void Parse(IEnumerable<string> args)
{
var currentName = "";
var values = new List<string>();
foreach (var arg in args)
{
if (arg.StartsWith("-", StringComparison.Ordinal))
{
if (!string.IsNullOrWhiteSpace(currentName))
Arguments[currentName.ToLowerInvariant()] = values.ToArray();
values.Clear();
currentName = arg.Substring(1);
}
else if (string.IsNullOrWhiteSpace(currentName))
{
Arguments[arg] = new string[0];
}
else
{
values.Add(arg);
}
}
if (currentName != "")
Arguments[currentName.ToLowerInvariant()] = values.ToArray();
}
}
}

102
Creator/Helper/Utils.cs Normal file
View File

@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Vestris.ResourceLib;
namespace KattekerCreator.Helper
{
public static class Utils
{
public static bool CheckFileExistens(string filePath)
{
if (File.Exists(filePath)) return true;
var file = filePath.Replace(Directory.GetParent(filePath) + "\\", "");
Console.WriteLine("Checking the prerequisites has failed.");
Console.WriteLine($"{file} is missing. Program exits now.");
Console.ReadKey();
return false;
}
public static string CreateTempDirectory()
{
string result;
do
{
result = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp", Environment.UserName,
Path.GetRandomFileName());
} while (Directory.Exists(result));
Directory.CreateDirectory(result);
return result;
}
public static bool IsFilesizeWrong(string filename)
{
var file = new FileInfo(filename);
return !file.Exists || file.Length < 524288;
}
public static void CopyResources(string inFile, string outFile)
{
using (var ri = new ResourceInfo())
{
ri.Load(inFile);
var versionResource = (VersionResource) ri[Kernel32.ResourceTypes.RT_VERSION].First();
if (ri.ResourceTypes.Any(x => x.ResourceType == Kernel32.ResourceTypes.RT_GROUP_ICON))
{
var groupIcon = ri[Kernel32.ResourceTypes.RT_GROUP_ICON];
var iconDictionary = groupIcon.FirstOrDefault() as IconDirectoryResource;
iconDictionary?.SaveTo(outFile);
}
versionResource.Language = 0;
versionResource.SaveTo(outFile);
}
}
public static void DeleteTempDir(string tempDir)
{
#if !DEBUG
try
{
Directory.Delete(tempDir, true);
}
catch (Exception)
{
//silently ignore
}
#endif
}
public static IEnumerable<FileInfo> EnumerateFiles(string programFile, IEnumerable<string> userdefinedFileExclusions = null)
{
if (string.IsNullOrWhiteSpace(programFile)) return null;
var directoryName = Path.GetDirectoryName(programFile);
if (directoryName == null) return null;
var files = new DirectoryInfo(directoryName).EnumerateFiles("*.*", SearchOption.AllDirectories);
var filter = FileExclusions(userdefinedFileExclusions).ToArray();
return files.Where(x => !filter.Any(y => x.Name.EndsWith(y, StringComparison.Ordinal)));
}
private static IEnumerable<string> FileExclusions(IEnumerable<string> userdefinedfileExclusions = null)
{
yield return ".pdb";
yield return ".tmp";
yield return ".obj";
yield return ".pch";
yield return ".vshost.exe";
yield return ".vshost.exe.config";
yield return ".vshost.exe.manifest";
yield return "squirrelHelperInfo.json";
yield return "Katteker.config";
if (userdefinedfileExclusions == null) yield break;
foreach (var fileExclusion in userdefinedfileExclusions)
{
yield return fileExclusion;
}
}
}
}

View File

@ -0,0 +1,283 @@
/*
* IconExtractor/IconUtil for .NET
* Copyright (C) 2014 Tsuda Kageyu. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace TsudaKageyu
{
public class IconExtractor
{
////////////////////////////////////////////////////////////////////////
// Constants
// Flags for LoadLibraryEx().
private const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
// Resource types for EnumResourceNames().
private readonly static IntPtr RT_ICON = (IntPtr)3;
private readonly static IntPtr RT_GROUP_ICON = (IntPtr)14;
private const int MAX_PATH = 260;
////////////////////////////////////////////////////////////////////////
// Fields
private byte[][] iconData = null; // Binary data of each icon.
////////////////////////////////////////////////////////////////////////
// Public properties
/// <summary>
/// Gets the full path of the associated file.
/// </summary>
public string FileName
{
get;
private set;
}
/// <summary>
/// Gets the count of the icons in the associated file.
/// </summary>
public int Count
{
get { return iconData.Length; }
}
/// <summary>
/// Initializes a new instance of the IconExtractor class from the specified file name.
/// </summary>
/// <param name="fileName">The file to extract icons from.</param>
public IconExtractor(string fileName)
{
Initialize(fileName);
}
/// <summary>
/// Extracts an icon from the file.
/// </summary>
/// <param name="index">Zero based index of the icon to be extracted.</param>
/// <returns>A System.Drawing.Icon object.</returns>
/// <remarks>Always returns new copy of the Icon. It should be disposed by the user.</remarks>
public Icon GetIcon(int index)
{
if (index < 0 || Count <= index)
throw new ArgumentOutOfRangeException("index");
// Create an Icon from the .ico file in memory.
using (var ms = new MemoryStream(iconData[index]))
{
return new Icon(ms);
}
}
/// <summary>
/// Extracts all the icons from the file.
/// </summary>
/// <returns>An array of System.Drawing.Icon objects.</returns>
/// <remarks>Always returns new copies of the Icons. They should be disposed by the user.</remarks>
public Icon[] GetAllIcons()
{
var icons = new List<Icon>();
for (int i = 0; i < Count; ++i)
icons.Add(GetIcon(i));
return icons.ToArray();
}
/// <summary>
/// Save an icon to the specified output Stream.
/// </summary>
/// <param name="index">Zero based index of the icon to be saved.</param>
/// <param name="outputStream">The Stream to save to.</param>
public void Save(int index, Stream outputStream)
{
if (index < 0 || Count <= index)
throw new ArgumentOutOfRangeException("index");
if (outputStream == null)
throw new ArgumentNullException("outputStream");
var data = iconData[index];
outputStream.Write(data, 0, data.Length);
}
private void Initialize(string fileName)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
IntPtr hModule = IntPtr.Zero;
try
{
hModule = NativeMethods.LoadLibraryEx(fileName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
if (hModule == IntPtr.Zero)
throw new Win32Exception();
FileName = GetFileName(hModule);
// Enumerate the icon resource and build .ico files in memory.
var tmpData = new List<byte[]>();
ENUMRESNAMEPROC callback = (h, t, name, l) =>
{
// Refer to the following URL for the data structures used here:
// http://msdn.microsoft.com/en-us/library/ms997538.aspx
// RT_GROUP_ICON resource consists of a GRPICONDIR and GRPICONDIRENTRY's.
var dir = GetDataFromResource(hModule, RT_GROUP_ICON, name);
// Calculate the size of an entire .icon file.
int count = BitConverter.ToUInt16(dir, 4); // GRPICONDIR.idCount
int len = 6 + 16 * count; // sizeof(ICONDIR) + sizeof(ICONDIRENTRY) * count
for (int i = 0; i < count; ++i)
len += BitConverter.ToInt32(dir, 6 + 14 * i + 8); // GRPICONDIRENTRY.dwBytesInRes
using (var dst = new BinaryWriter(new MemoryStream(len)))
{
// Copy GRPICONDIR to ICONDIR.
dst.Write(dir, 0, 6);
int picOffset = 6 + 16 * count; // sizeof(ICONDIR) + sizeof(ICONDIRENTRY) * count
for (int i = 0; i < count; ++i)
{
// Load the picture.
ushort id = BitConverter.ToUInt16(dir, 6 + 14 * i + 12); // GRPICONDIRENTRY.nID
var pic = GetDataFromResource(hModule, RT_ICON, (IntPtr)id);
// Copy GRPICONDIRENTRY to ICONDIRENTRY.
dst.Seek(6 + 16 * i, SeekOrigin.Begin);
dst.Write(dir, 6 + 14 * i, 8); // First 8bytes are identical.
dst.Write(pic.Length); // ICONDIRENTRY.dwBytesInRes
dst.Write(picOffset); // ICONDIRENTRY.dwImageOffset
// Copy a picture.
dst.Seek(picOffset, SeekOrigin.Begin);
dst.Write(pic, 0, pic.Length);
picOffset += pic.Length;
}
tmpData.Add(((MemoryStream)dst.BaseStream).ToArray());
}
return true;
};
NativeMethods.EnumResourceNames(hModule, RT_GROUP_ICON, callback, IntPtr.Zero);
iconData = tmpData.ToArray();
}
finally
{
if (hModule != IntPtr.Zero)
NativeMethods.FreeLibrary(hModule);
}
}
private byte[] GetDataFromResource(IntPtr hModule, IntPtr type, IntPtr name)
{
// Load the binary data from the specified resource.
IntPtr hResInfo = NativeMethods.FindResource(hModule, name, type);
if (hResInfo == IntPtr.Zero)
throw new Win32Exception();
IntPtr hResData = NativeMethods.LoadResource(hModule, hResInfo);
if (hResData == IntPtr.Zero)
throw new Win32Exception();
IntPtr pResData = NativeMethods.LockResource(hResData);
if (pResData == IntPtr.Zero)
throw new Win32Exception();
uint size = NativeMethods.SizeofResource(hModule, hResInfo);
if (size == 0)
throw new Win32Exception();
byte[] buf = new byte[size];
Marshal.Copy(pResData, buf, 0, buf.Length);
return buf;
}
private string GetFileName(IntPtr hModule)
{
// Alternative to GetModuleFileName() for the module loaded with
// LOAD_LIBRARY_AS_DATAFILE option.
// Get the file name in the format like:
// "\\Device\\HarddiskVolume2\\Windows\\System32\\shell32.dll"
string fileName;
{
var buf = new StringBuilder(MAX_PATH);
int len = NativeMethods.GetMappedFileName(
NativeMethods.GetCurrentProcess(), hModule, buf, buf.Capacity);
if (len == 0)
throw new Win32Exception();
fileName = buf.ToString();
}
// Convert the device name to drive name like:
// "C:\\Windows\\System32\\shell32.dll"
for (char c = 'A'; c <= 'Z'; ++c)
{
var drive = c + ":";
var buf = new StringBuilder(MAX_PATH);
int len = NativeMethods.QueryDosDevice(drive, buf, buf.Capacity);
if (len == 0)
continue;
var devPath = buf.ToString();
if (fileName.StartsWith(devPath))
return (drive + fileName.Substring(devPath.Length));
}
return fileName;
}
}
}

View File

@ -0,0 +1,202 @@
/*
* IconExtractor/IconUtil for .NET
* Copyright (C) 2014 Tsuda Kageyu. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
namespace TsudaKageyu
{
public static class IconUtil
{
private delegate byte[] GetIconDataDelegate(Icon icon);
static GetIconDataDelegate getIconData;
static IconUtil()
{
// Create a dynamic method to access Icon.iconData private field.
var dm = new DynamicMethod(
"GetIconData", typeof(byte[]), new Type[] { typeof(Icon) }, typeof(Icon));
var fi = typeof(Icon).GetField(
"iconData", BindingFlags.Instance | BindingFlags.NonPublic);
var gen = dm.GetILGenerator();
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldfld, fi);
gen.Emit(OpCodes.Ret);
getIconData = (GetIconDataDelegate)dm.CreateDelegate(typeof(GetIconDataDelegate));
}
/// <summary>
/// Split an Icon consists of multiple icons into an array of Icon each
/// consists of single icons.
/// </summary>
/// <param name="icon">A System.Drawing.Icon to be split.</param>
/// <returns>An array of System.Drawing.Icon.</returns>
public static Icon[] Split(Icon icon)
{
if (icon == null)
throw new ArgumentNullException("icon");
// Get an .ico file in memory, then split it into separate icons.
var src = GetIconData(icon);
var splitIcons = new List<Icon>();
{
int count = BitConverter.ToUInt16(src, 4);
for (int i = 0; i < count; i++)
{
int length = BitConverter.ToInt32(src, 6 + 16 * i + 8); // ICONDIRENTRY.dwBytesInRes
int offset = BitConverter.ToInt32(src, 6 + 16 * i + 12); // ICONDIRENTRY.dwImageOffset
using (var dst = new BinaryWriter(new MemoryStream(6 + 16 + length)))
{
// Copy ICONDIR and set idCount to 1.
dst.Write(src, 0, 4);
dst.Write((short)1);
// Copy ICONDIRENTRY and set dwImageOffset to 22.
dst.Write(src, 6 + 16 * i, 12); // ICONDIRENTRY except dwImageOffset
dst.Write(22); // ICONDIRENTRY.dwImageOffset
// Copy a picture.
dst.Write(src, offset, length);
// Create an icon from the in-memory file.
dst.BaseStream.Seek(0, SeekOrigin.Begin);
splitIcons.Add(new Icon(dst.BaseStream));
}
}
}
return splitIcons.ToArray();
}
/// <summary>
/// Converts an Icon to a GDI+ Bitmap preserving the transparent area.
/// </summary>
/// <param name="icon">An System.Drawing.Icon to be converted.</param>
/// <returns>A System.Drawing.Bitmap Object.</returns>
public static Bitmap ToBitmap(Icon icon)
{
if (icon == null)
throw new ArgumentNullException("icon");
// Quick workaround: Create an .ico file in memory, then load it as a Bitmap.
using (var ms = new MemoryStream())
{
icon.Save(ms);
using (var bmp = (Bitmap)Image.FromStream(ms))
{
return new Bitmap(bmp);
}
}
}
/// <summary>
/// Gets the bit depth of an Icon.
/// </summary>
/// <param name="icon">An System.Drawing.Icon object.</param>
/// <returns>Bit depth of the icon.</returns>
/// <remarks>
/// This method takes into account the PNG header.
/// If the icon has multiple variations, this method returns the bit
/// depth of the first variation.
/// </remarks>
public static int GetBitCount(Icon icon)
{
if (icon == null)
throw new ArgumentNullException("icon");
// Get an .ico file in memory, then read the header.
var data = GetIconData(icon);
if (data.Length >= 51
&& data[22] == 0x89 && data[23] == 0x50 && data[24] == 0x4e && data[25] == 0x47
&& data[26] == 0x0d && data[27] == 0x0a && data[28] == 0x1a && data[29] == 0x0a
&& data[30] == 0x00 && data[31] == 0x00 && data[32] == 0x00 && data[33] == 0x0d
&& data[34] == 0x49 && data[35] == 0x48 && data[36] == 0x44 && data[37] == 0x52)
{
// The picture is PNG. Read IHDR chunk.
switch (data[47])
{
case 0:
return data[46];
case 2:
return data[46] * 3;
case 3:
return data[46];
case 4:
return data[46] * 2;
case 6:
return data[46] * 4;
default:
// NOP
break;
}
}
else if (data.Length >= 22)
{
// The picture is not PNG. Read ICONDIRENTRY structure.
return BitConverter.ToUInt16(data, 12);
}
throw new ArgumentException("The icon is corrupt. Couldn't read the header.", "icon");
}
private static byte[] GetIconData(Icon icon)
{
var data = getIconData(icon);
if (data != null)
{
return data;
}
else
{
using (var ms = new MemoryStream())
{
icon.Save(ms);
return ms.ToArray();
}
}
}
}
}

View File

@ -0,0 +1,81 @@
/*
* IconExtractor/IconUtil for .NET
* Copyright (C) 2014 Tsuda Kageyu. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
namespace TsudaKageyu
{
internal static class NativeMethods
{
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);
[DllImport("kernel32.dll", SetLastError = true)]
[SuppressUnmanagedCodeSecurity]
public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
public static extern bool EnumResourceNames(IntPtr hModule, IntPtr lpszType, ENUMRESNAMEPROC lpEnumFunc, IntPtr lParam);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
public static extern IntPtr FindResource(IntPtr hModule, IntPtr lpName, IntPtr lpType);
[DllImport("kernel32.dll", SetLastError = true)]
[SuppressUnmanagedCodeSecurity]
public static extern IntPtr LoadResource(IntPtr hModule, IntPtr hResInfo);
[DllImport("kernel32.dll", SetLastError = true)]
[SuppressUnmanagedCodeSecurity]
public static extern IntPtr LockResource(IntPtr hResData);
[DllImport("kernel32.dll", SetLastError = true)]
[SuppressUnmanagedCodeSecurity]
public static extern uint SizeofResource(IntPtr hModule, IntPtr hResInfo);
[DllImport("kernel32.dll", SetLastError = true)]
[SuppressUnmanagedCodeSecurity]
public static extern IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
public static extern int QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);
[DllImport("psapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
public static extern int GetMappedFileName(IntPtr hProcess, IntPtr lpv, StringBuilder lpFilename, int nSize);
}
[UnmanagedFunctionPointer(CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
internal delegate bool ENUMRESNAMEPROC(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam);
}

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{53D065EB-8818-4F60-9EBE-75705E1BB00D}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KattekerCreator</RootNamespace>
<AssemblyName>KattekerCreator</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xml" />
<Reference Include="Vestris.ResourceLib, Version=1.6.422.0, Culture=neutral, PublicKeyToken=ec632d8ba5e5750d, processorArchitecture=MSIL">
<HintPath>..\packages\Vestris.ResourceLib.1.6.422\lib\Vestris.ResourceLib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationArguments.cs" />
<Compile Include="AssemblyFileInfo.cs" />
<Compile Include="Helper\Log.cs" />
<Compile Include="IconExtractor\IconExtractor.cs" />
<Compile Include="IconExtractor\IconUtil.cs" />
<Compile Include="IconExtractor\NativeMethods.cs" />
<Compile Include="PhysicalFile.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helper\SimpleCommandLineParser.cs" />
<Compile Include="Helper\Utils.cs" />
<Compile Include="SetupTmpl.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>SetupTmpl.tt</DependentUpon>
</Compile>
<Compile Include="SetupTmplCode.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="contrib\LoadingBar_Icon.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="contrib\uninstall.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SetupTmpl.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>SetupTmpl.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Katteker\Katteker.csproj">
<Project>{a45e1c59-ba9e-452c-a5e2-50de49d53e92}</Project>
<Name>Katteker</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

14
Creator/PhysicalFile.cs Normal file
View File

@ -0,0 +1,14 @@
namespace KattekerCreator
{
public class PhysicalFile
{
public PhysicalFile(string sourcePath, string targetPath)
{
SourcePath = sourcePath;
TargetPath = targetPath;
}
public string SourcePath { get; }
public string TargetPath { get; }
}
}

213
Creator/Program.cs Normal file
View File

@ -0,0 +1,213 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Katteker;
using KattekerCreator.Helper;
namespace KattekerCreator
{
public class Program
{
private const string _executable = @"C:\Program Files (x86)\NSIS\makensis.exe";
private readonly string _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
private ApplicationArguments _appArguments;
private AssemblyFileInfo _assemblyFileInfo;
private string _tempDir;
private Releases _releases;
private static int Main(string[] args)
{
var program = new Program();
try
{
return program.Run(args);
}
catch (Exception ex)
{
Log.WriteErrorLine(ex.Message);
if (ex.InnerException != null)
Log.WriteErrorLine(ex.InnerException.Message);
#if DEBUG
throw;
#else
return -1;
#endif
}
}
private int Run(string[] args)
{
//Parse App-Arguments
var parser = new SimpleCommandLineParser<ApplicationArguments>(args);
if (args.Length == 0)
{
parser.ShowHelp();
return 1924;
}
_appArguments = parser.GetObject();
//Create tempdir
_tempDir = Utils.CreateTempDirectory();
_releases = new Releases(_appArguments.OutputDir);
parser.ShowProgramArguments();
//Modify AppStub
var appStubFile = ModifyAppStub();
//Acquire infos from Executable.
_assemblyFileInfo = new AssemblyFileInfo(_appArguments.ProgramFile, _tempDir);
var configFile = CreateConfigFile();
//Generate NSIS-Script
var additionalFiles = new[]
{
new PhysicalFile(appStubFile, Path.GetFileName(_appArguments.ProgramFile)),
new PhysicalFile(configFile, Path.Combine($"app-{_assemblyFileInfo.AssemblyVersion}", Path.GetFileName(configFile)))
};
var templateFile = GenerateNsisTemplate(additionalFiles);
//Start makensis.exe
var setupFilePath = CompileSetupScript(templateFile);
//Copy to Output-Folder
if (CopyToOutputFolder(setupFilePath))
{
//Create/Modify RELEASE File
var releaseEntry = AddPackageToReleaseFile(setupFilePath);
//Copy installer as setup.exe
CopyAsSetup(setupFilePath, releaseEntry);
}
return 0;
}
private void CopyAsSetup(string setupFilePath, ReleaseEntry releaseEntry)
{
if (!_releases.IsLatestEntry(releaseEntry)) return;
var target = Path.Combine(_appArguments.OutputDir, Constants.SetupFile);
File.Delete(target);
File.Copy(setupFilePath, target);
}
private ReleaseEntry AddPackageToReleaseFile(string setupFilePath)
{
try
{
var result = _releases.Add(setupFilePath, _assemblyFileInfo.AssemblyVersion);
_releases.WriteReleaseFile();
return result;
}
catch (Exception e)
{
Log.WriteErrorLine(e.Message);
throw;
}
}
private bool CopyToOutputFolder(string setupFilePath)
{
try
{
if (setupFilePath == null) throw new ArgumentNullException(nameof(setupFilePath));
var setupFile = Path.GetFileName(setupFilePath);
if (string.IsNullOrEmpty(setupFile)) throw new ArgumentException();
if (!File.Exists(setupFilePath)) throw new FileNotFoundException(setupFile);
if (!string.IsNullOrEmpty(_appArguments.ChangeLog))
{
var changeLogPath = Path.Combine(Path.GetDirectoryName(_appArguments.ProgramFile), _appArguments.ChangeLog);
if (!File.Exists(changeLogPath)) throw new FileNotFoundException(changeLogPath);
File.Copy(changeLogPath, Path.Combine(_appArguments.OutputDir, Path.GetFileName(_appArguments.ChangeLog) ?? throw new InvalidOperationException()), true);
}
if (!Directory.Exists(_appArguments.OutputDir)) Directory.CreateDirectory(_appArguments.OutputDir);
File.Copy(setupFilePath, Path.Combine(_appArguments.OutputDir, setupFile), true);
return true;
}
catch (Exception e)
{
Log.WriteErrorLine(e.Message);
return false;
}
}
private static string CompileSetupScript(string templateFile)
{
if (!File.Exists(_executable)) throw new FileNotFoundException("NSIS not installed properly.");
int exitcode;
using (var p = new Process())
{
p.StartInfo = new ProcessStartInfo
{
FileName = _executable,
Arguments = templateFile,
UseShellExecute = false
};
var sw = Stopwatch.StartNew();
p.Start();
p.WaitForExit();
exitcode = p.ExitCode;
Log.WriteInfoLine($"{Path.GetFileName(_executable)} has exited with Exitcode: {exitcode} (Took: {sw.ElapsedMilliseconds}ms)");
}
if (exitcode != 0) throw new Exception($"{Path.GetFileName(_executable)} has exited with Exitcode: {exitcode}");
return Path.ChangeExtension(templateFile, "exe");
}
private string CreateConfigFile()
{
var pathToFile = Path.Combine(_tempDir, Constants.KattekerConfig);
var kattekerConfig = new KattekerConfig
{
PublishDir = _appArguments.PublishDir ?? _appArguments.OutputDir,
Changelog = _appArguments.ChangeLog
};
kattekerConfig.WriteToFile(pathToFile);
return pathToFile;
}
private string ModifyAppStub()
{
var baseFile = new FileInfo(Path.Combine(_baseDirectory, Constants.ExecutionStub));
var targetFile = baseFile.CopyTo(Path.Combine(_tempDir, Constants.ExecutionStub));
Utils.CopyResources(_appArguments.ProgramFile, targetFile.FullName);
return targetFile.FullName;
}
private static string GenerateFilename(string name, string version, string extension, bool isDelta = false) => $"{name}-{version}-{(isDelta ? "delta" : "full")}.{extension}";
private string GenerateNsisTemplate(IEnumerable<PhysicalFile> additionalFiles)
{
try
{
var outFile = Path.Combine(_tempDir, GenerateFilename(_assemblyFileInfo.ProductName, _assemblyFileInfo.AssemblyVersion.ToString(), "nsi"));
var setupTmpl = new SetupTmpl
{
Executable = _assemblyFileInfo.FileInfo.Name,
AppName = _assemblyFileInfo.ProductName,
CompanyName = _assemblyFileInfo.Company,
Description = _assemblyFileInfo.Description,
IconPath = _assemblyFileInfo.AssemblyIconPath,
Version = _assemblyFileInfo.AssemblyVersion,
HelpUrl = "http://example.org", //Not used at the moment.
UserInterface = Path.Combine(_baseDirectory, "contrib", "LoadingBar_Icon.exe"),
UninstallIcon = Path.Combine(_baseDirectory, "contrib", "uninstall.ico"),
OutFile = Path.GetFileName(Path.ChangeExtension(outFile, "exe")),
ReleaseChannel = _appArguments.Channel
};
var path = Path.GetDirectoryName(_appArguments.ProgramFile) ?? string.Empty;
setupTmpl.Files.AddRange(additionalFiles);
var files = Utils.EnumerateFiles(_appArguments.ProgramFile).ToArray();
setupTmpl.InstallSize = (long) Math.Floor(files.Sum(x => x.Length) / 1024f);
setupTmpl.Files.AddRange(files.Select(x => new PhysicalFile(x.FullName, x.FullName.Replace(path, $"app-{_assemblyFileInfo.AssemblyVersion}"))));
var transformText = setupTmpl.TransformText();
File.WriteAllText(outFile, transformText);
return outFile;
}
catch (Exception e)
{
Log.WriteErrorLine(e.Message);
throw;
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("KattekerCreator")]
[assembly: AssemblyDescription("Creates Installation and Update packages.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Holger Börchers")]
[assembly: AssemblyProduct("KattekerCreator")]
[assembly: AssemblyCopyright("Copyright © Holger Börchers")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("ef6af08f-1e5f-44c5-9be8-973b130f8086")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

270
Creator/SemanticVersion.cs Normal file
View File

@ -0,0 +1,270 @@
using System;
using System.Text.RegularExpressions;
namespace KattekerCreator
{
/// <summary>
/// A hybrid implementation of SemVer that supports semantic versioning as described at http://semver.org while not
/// strictly enforcing it to
/// allow older 4-digit versioning schemes to continue working.
/// </summary>
[Serializable]
//[TypeConverter(typeof(SemanticVersionTypeConverter))]
public sealed class SemanticVersion : IComparable, IComparable<SemanticVersion>, IEquatable<SemanticVersion>
{
private const RegexOptions Flags =
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture;
private static readonly Regex SemanticVersionRegex =
new Regex(@"^(?<Version>\d+(\s*\.\s*\d+){0,3})(?<Release>-[a-z][0-9a-z-]*)?$", Flags);
private static readonly Regex StrictSemanticVersionRegex =
new Regex(@"^(?<Version>\d+(\.\d+){2})(?<Release>-[a-z][0-9a-z-]*)?$", Flags);
private readonly string _originalString;
public SemanticVersion(string version)
: this(Parse(version))
{
// The constructor normalizes the version string so that it we do not need to normalize it every time we need to operate on it.
// The original string represents the original form in which the version is represented to be used when printing.
_originalString = version;
}
public SemanticVersion(int major, int minor, int build, int revision)
: this(new Version(major, minor, build, revision))
{
}
public SemanticVersion(int major, int minor, int build, string specialVersion)
: this(new Version(major, minor, build), specialVersion)
{
}
public SemanticVersion(Version version)
: this(version, string.Empty)
{
}
public SemanticVersion(Version version, string specialVersion)
: this(version, specialVersion, null)
{
}
private SemanticVersion(Version version, string specialVersion, string originalString)
{
if (version == null)
throw new ArgumentNullException(nameof(version));
Version = NormalizeVersionValue(version);
SpecialVersion = specialVersion ?? string.Empty;
_originalString = string.IsNullOrEmpty(originalString)
? version + (!string.IsNullOrEmpty(specialVersion) ? '-' + specialVersion : null)
: originalString;
}
internal SemanticVersion(SemanticVersion semVer)
{
_originalString = semVer.ToString();
Version = semVer.Version;
SpecialVersion = semVer.SpecialVersion;
}
/// <summary>
/// Gets the normalized version portion.
/// </summary>
public Version Version { get; }
/// <summary>
/// Gets the optional special version.
/// </summary>
public string SpecialVersion { get; }
public int CompareTo(object obj)
{
if (ReferenceEquals(obj, null))
return 1;
var other = obj as SemanticVersion;
if (other == null)
throw new ArgumentException("Type Must Be A Semantic Version", nameof(obj));
return CompareTo(other);
}
public int CompareTo(SemanticVersion other)
{
if (ReferenceEquals(other, null))
return 1;
var result = Version.CompareTo(other.Version);
if (result != 0)
return result;
var empty = string.IsNullOrEmpty(SpecialVersion);
var otherEmpty = string.IsNullOrEmpty(other.SpecialVersion);
if (empty && otherEmpty)
return 0;
if (empty)
return 1;
if (otherEmpty)
return -1;
return StringComparer.OrdinalIgnoreCase.Compare(SpecialVersion, other.SpecialVersion);
}
public bool Equals(SemanticVersion other)
{
return !ReferenceEquals(null, other) &&
Version.Equals(other.Version) &&
SpecialVersion.Equals(other.SpecialVersion, StringComparison.OrdinalIgnoreCase);
}
public string[] GetOriginalVersionComponents()
{
if (!string.IsNullOrEmpty(_originalString))
{
// search the start of the SpecialVersion part, if any
var dashIndex = _originalString.IndexOf('-');
var original = dashIndex != -1 ? _originalString.Substring(0, dashIndex) : _originalString;
return SplitAndPadVersionString(original);
}
return SplitAndPadVersionString(Version.ToString());
}
private static string[] SplitAndPadVersionString(string version)
{
var a = version.Split('.');
if (a.Length == 4)
{
return a;
}
// if 'a' has less than 4 elements, we pad the '0' at the end
// to make it 4.
var b = new string[4] {"0", "0", "0", "0"};
Array.Copy(a, 0, b, 0, a.Length);
return b;
}
/// <summary>
/// Parses a version string using loose semantic versioning rules that allows 2-4 version components followed by an
/// optional special version.
/// </summary>
public static SemanticVersion Parse(string version)
{
if (string.IsNullOrEmpty(version))
throw new ArgumentException(nameof(version));
if (!TryParse(version, out var semVer))
throw new ArgumentException("Invalid Version String", nameof(version));
return semVer;
}
/// <summary>
/// Parses a version string using loose semantic versioning rules that allows 2-4 version components followed by an
/// optional special version.
/// </summary>
public static bool TryParse(string version, out SemanticVersion value)
{
return TryParseInternal(version, SemanticVersionRegex, out value);
}
/// <summary>
/// Parses a version string using strict semantic versioning rules that allows exactly 3 components and an optional
/// special version.
/// </summary>
public static bool TryParseStrict(string version, out SemanticVersion value)
{
return TryParseInternal(version, StrictSemanticVersionRegex, out value);
}
private static bool TryParseInternal(string version, Regex regex, out SemanticVersion semVer)
{
semVer = null;
if (string.IsNullOrEmpty(version))
return false;
var match = regex.Match(version.Trim());
if (!match.Success || !Version.TryParse(match.Groups["Version"].Value, out var versionValue))
return false;
semVer = new SemanticVersion(NormalizeVersionValue(versionValue),
match.Groups["Release"].Value.TrimStart('-'), version.Replace(" ", ""));
return true;
}
/// <summary>
/// Attempts to parse the version token as a SemanticVersion.
/// </summary>
/// <returns>An instance of SemanticVersion if it parses correctly, null otherwise.</returns>
public static SemanticVersion ParseOptionalVersion(string version)
{
TryParse(version, out var semVer);
return semVer;
}
private static Version NormalizeVersionValue(Version version)
{
return new Version(version.Major,
version.Minor,
Math.Max(version.Build, 0),
Math.Max(version.Revision, 0));
}
public static bool operator ==(SemanticVersion version1, SemanticVersion version2)
{
if (ReferenceEquals(version1, null))
return ReferenceEquals(version2, null);
return version1.Equals(version2);
}
public static bool operator !=(SemanticVersion version1, SemanticVersion version2)
{
return !(version1 == version2);
}
public static bool operator <(SemanticVersion version1, SemanticVersion version2)
{
if (version1 == null)
throw new ArgumentNullException(nameof(version1));
return version1.CompareTo(version2) < 0;
}
public static bool operator <=(SemanticVersion version1, SemanticVersion version2)
{
return version1 == version2 || version1 < version2;
}
public static bool operator >(SemanticVersion version1, SemanticVersion version2)
{
if (version1 == null)
throw new ArgumentNullException(nameof(version1));
return version2 < version1;
}
public static bool operator >=(SemanticVersion version1, SemanticVersion version2)
{
return version1 == version2 || version1 > version2;
}
public override string ToString()
{
return _originalString;
}
public override bool Equals(object obj)
{
var semVer = obj as SemanticVersion;
return !ReferenceEquals(null, semVer) && Equals(semVer);
}
public override int GetHashCode()
{
var hashCode = Version.GetHashCode();
if (SpecialVersion != null)
hashCode = hashCode * 4567 + SpecialVersion.GetHashCode();
return hashCode;
}
}
}

103
Creator/Setup.nsi Normal file
View File

@ -0,0 +1,103 @@
!define APPNAME "Shutdown8"
!define EXECUTABLE "Shutdown8.exe"
!define COMPANYNAME "Bandisoft.com"
!define DESCRIPTION "NoDescription"
!define VERSION 1.8.0
!define HELPURL https://srv-lsimctrl01.enercon.de
!define INSTALLSIZE 155573
!define ISMANAGED 1
; exampleCmd: makensis.exe /DVERSION=1.0.0.5 /DNAME=WpfApp1 Setup.nsi
Name "${APPNAME}"
OutFile "${APPNAME}-${VERSION}.exe"
InstallDir "$LOCALAPPDATA\${APPNAME}"
RequestExecutionLevel user
SetCompressor /SOLID lzma
SilentUnInstall silent
; Subcaption 3 " "
XPStyle on
AutoCloseWindow true
ChangeUI all "${NSISDIR}\Contrib\UIs\sdbarker_tiny.exe"
Icon "${NSISDIR}\Contrib\Graphics\Icons\nsis3-install.ico"
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\nsis3-uninstall.ico"
ShowInstDetails nevershow
ShowUninstDetails nevershow
BrandingText "${COMPANYNAME}"
;--------------------------------
; The stuff to install
Section "install" ;No components page, name is not important
DetailPrint 'Installing ${APPNAME}. Please wait...'
SetShellVarContext current
SetDetailsPrint None
SetOutPath $INSTDIR\app-${VERSION}
; Put file there
File /r /x *.pdb /x *.obj /x *.pch /x *.vshost.exe /x *.vshost.exe.* Release\*.*
SetOutPath $INSTDIR
File "/oname=${Executable}" AppStub.exe
File Rabbit.Shared.dll
WriteINIStr $INSTDIR\app.ini Main Executable "${EXECUTABLE}"
WriteINIStr $INSTDIR\app.ini Main AppName "${APPNAME}"
WriteINIStr $INSTDIR\app.ini Main IsManaged ${ISMANAGED}
WriteUninstaller "$INSTDIR\uninstall.exe"
; Desktop
CreateShortCut "$DESKTOP\${APPNAME}.lnk" "$INSTDIR\${Executable}"
# Start Menu
CreateDirectory "$SMPROGRAMS\${COMPANYNAME}"
CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\${Executable}"
# Update pinned Taskbar
IfFileExists "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\${APPNAME}.lnk" 0 +2
CreateShortCut "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\${APPNAME}.lnk" "$INSTDIR\${Executable}"
SetOutPath $INSTDIR\app-${VERSION}
StrCpy $0 ${EXECUTABLE} -4
IfFileExists "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\$0.lnk" 0 +2
CreateShortCut "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\$0.lnk" "$INSTDIR\app-${VERSION}\${EXECUTABLE}"
# Registry information for add/remove programs
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayIcon" "$\"$INSTDIR\app-${VERSION}\${EXECUTABLE}$\""
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "${COMPANYNAME}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "${HELPURL}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "${VERSION}"
# There is no option for modifying or repairing the install
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoModify" 1
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoRepair" 1
# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
SectionEnd ; end the section
Function .onInstSuccess
IfSilent +2
Exec '"$INSTDIR\${Executable}"'
FunctionEnd
Section "uninstall"
DetailPrint 'Please wait...'
SetShellVarContext current
SetDetailsPrint None
SetAutoClose true
# Remove Start Menu launcher
Delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
Delete "$DESKTOP\${APPNAME}.lnk"
StrCpy $0 ${EXECUTABLE} -4
Delete "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\${APPNAME}.lnk"
Delete "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\$0.lnk"
# Try to remove the Start Menu folder - this will only happen if it is empty
RMDir "$SMPROGRAMS\${COMPANYNAME}"
# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe
# Try to remove the install directory - this will only happen if it is empty
RMDir /r /REBOOTOK $INSTDIR
# Remove uninstaller information from the registry
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
sectionEnd

522
Creator/SetupTmpl.cs Normal file
View File

@ -0,0 +1,522 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version: 15.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace KattekerCreator
{
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System;
/// <summary>
/// Class to produce the template output
/// </summary>
#line 1 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")]
public partial class SetupTmpl : SetupTmplBase
{
#line hidden
/// <summary>
/// Create the template output
/// </summary>
public virtual string TransformText()
{
this.Write("Unicode true\r\nManifestDPIAware true\r\n!define APPNAME \"");
#line 8 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(AppName));
#line default
#line hidden
this.Write("\"\r\n!define EXECUTABLE \"");
#line 9 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Executable));
#line default
#line hidden
this.Write("\"\r\n!define SOURCEPATH \"");
#line 10 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(SourcePath));
#line default
#line hidden
this.Write("\"\r\n!define COMPANYNAME \"");
#line 11 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(CompanyName));
#line default
#line hidden
this.Write("\"\r\n!define DESCRIPTION \"");
#line 12 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Description));
#line default
#line hidden
this.Write("\"\r\n!define VERSION ");
#line 13 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Version.ToString()));
#line default
#line hidden
this.Write("\r\n!define HELPURL ");
#line 14 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(HelpUrl));
#line default
#line hidden
this.Write("\r\n!define INSTALLSIZE ");
#line 15 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(InstallSize));
#line default
#line hidden
this.Write("\r\n!define ISMANAGED ");
#line 16 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(IsManaged ? 1 : 0));
#line default
#line hidden
this.Write("\r\n; exampleCmd: makensis.exe /DVERSION=1.0.0.5 /DNAME=WpfApp1 Setup.nsi\r\n\r\nName \"" +
"${APPNAME}\"\r\nOutFile \"");
#line 20 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(OutFile));
#line default
#line hidden
this.Write("\"\r\nInstallDir \"$LOCALAPPDATA\\${APPNAME}\"\r\nRequestExecutionLevel user\r\nSetCompress" +
"or /SOLID lzma\r\nSilentUnInstall silent\r\n; Subcaption 3 \" \"\r\nXPStyle on\r\nAutoClos" +
"eWindow true\r\nChangeUI all \"");
#line 28 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(UserInterface));
#line default
#line hidden
this.Write("\"\r\nIcon \"");
#line 29 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(IconPath));
#line default
#line hidden
this.Write("\"\r\nUninstallIcon \"");
#line 30 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(UninstallIcon));
#line default
#line hidden
this.Write("\"\r\nShowInstDetails nevershow \r\nShowUninstDetails nevershow \r\nBrandingText \"${COMP" +
"ANYNAME}\"\r\n\r\nVIProductVersion ");
#line 35 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(LegacyVersion.ToString(4)));
#line default
#line hidden
this.Write(@"
VIAddVersionKey ProductName ""${APPNAME}""
VIAddVersionKey Comments """"
VIAddVersionKey CompanyName ""${COMPANYNAME}""
VIAddVersionKey LegalCopyright ""${COMPANYNAME}""
VIAddVersionKey FileDescription ""${DESCRIPTION}""
VIAddVersionKey FileVersion ""${VERSION}""
VIAddVersionKey ProductVersion ""${VERSION}""
VIAddVersionKey OriginalFilename """);
#line 43 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(OutFile));
#line default
#line hidden
this.Write(@"""
;--------------------------------
; The stuff to install
Section ""install"" ;No components page, name is not important
DetailPrint 'Installing ${APPNAME}. Please wait...'
SetShellVarContext current
SetDetailsPrint None
IfSilent +2
RMDir /r $INSTDIR
SetOutPath $INSTDIR
; Create sub-directories
");
#line 56 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
foreach(var directory in Directories) {
#line default
#line hidden
#line 56 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture($" CreateDirectory \"$INSTDIR\\{directory}\"{Environment.NewLine}"));
#line default
#line hidden
#line 56 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
}
#line default
#line hidden
this.Write("\r\n ; Put file there\r\n");
#line 59 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
foreach(var file in Files) {
#line default
#line hidden
#line 59 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
this.Write(this.ToStringHelper.ToStringWithCulture($" File \"/oname={file.TargetPath}\" \"{file.SourcePath}\"{Environment.NewLine}"));
#line default
#line hidden
#line 59 "C:\Strukturberechnung_del\Repos\SquirrelKiller\Katteker\Creator\SetupTmpl.tt"
}
#line default
#line hidden
this.Write("\r\n WriteUninstaller \"$INSTDIR\\uninstall.exe\"\r\n ; Desktop\r\n CreateShortCu" +
"t \"$DESKTOP\\${APPNAME}.lnk\" \"$INSTDIR\\${EXECUTABLE}\"\r\n \r\n # Start Menu\r\n " +
" CreateDirectory \"$SMPROGRAMS\\${COMPANYNAME}\"\r\n CreateShortCut \"$SMPROGRAMS\\" +
"${COMPANYNAME}\\${APPNAME}.lnk\" \"$INSTDIR\\${EXECUTABLE}\"\r\n\r\n # Update pinned T" +
"askbar\r\n IfFileExists \"$APPDATA\\Microsoft\\Internet Explorer\\Quick Launch\\User" +
" Pinned\\TaskBar\\${APPNAME}.lnk\" 0 +2\r\n CreateShortCut \"$APPDATA\\Microsoft\\Int" +
"ernet Explorer\\Quick Launch\\User Pinned\\TaskBar\\${APPNAME}.lnk\" \"$INSTDIR\\${EXEC" +
"UTABLE}\"\r\n SetOutPath $INSTDIR\\app-${VERSION}\r\n StrCpy $0 ${EXECUTABLE} -4" +
"\r\n IfFileExists \"$APPDATA\\Microsoft\\Internet Explorer\\Quick Launch\\User Pinne" +
"d\\TaskBar\\$0.lnk\" 0 +2\r\n CreateShortCut \"$APPDATA\\Microsoft\\Internet Explorer" +
"\\Quick Launch\\User Pinned\\TaskBar\\$0.lnk\" \"$INSTDIR\\app-${VERSION}\\${EXECUTABLE}" +
"\"\r\n \r\n # Registry information for add/remove programs\r\n WriteRegStr HKC" +
"U \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"DisplayName\"" +
" \"${APPNAME}\"\r\n WriteRegStr HKCU \"Software\\Microsoft\\Windows\\CurrentVersion\\U" +
"ninstall\\${APPNAME}\" \"UninstallString\" \"$\\\"$INSTDIR\\uninstall.exe$\\\"\"\r\n Write" +
"RegStr HKCU \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"Qu" +
"ietUninstallString\" \"$\\\"$INSTDIR\\uninstall.exe$\\\" /S\"\r\n WriteRegStr HKCU \"Sof" +
"tware\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"InstallLocation\" \"" +
"$\\\"$INSTDIR$\\\"\"\r\n WriteRegStr HKCU \"Software\\Microsoft\\Windows\\CurrentVersion" +
"\\Uninstall\\${APPNAME}\" \"DisplayIcon\" \"$\\\"$INSTDIR\\app-${VERSION}\\${EXECUTABLE}$\\" +
"\"\"\r\n WriteRegStr HKCU \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${" +
"APPNAME}\" \"Publisher\" \"${COMPANYNAME}\"\r\n ; WriteRegStr HKCU \"Software\\Microso" +
"ft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"HelpLink\" \"${HELPURL}\"\r\n Wri" +
"teRegStr HKCU \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"" +
"DisplayVersion\" \"${VERSION}\"\r\n # There is no option for modifying or repairin" +
"g the install\r\n WriteRegDWORD HKCU \"Software\\Microsoft\\Windows\\CurrentVersion" +
"\\Uninstall\\${APPNAME}\" \"NoModify\" 1\r\n WriteRegDWORD HKCU \"Software\\Microsoft\\" +
"Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"NoRepair\" 1\r\n # Set the INSTALL" +
"SIZE constant (!defined at the top of this script) so Add/Remove Programs can ac" +
"curately report the size\r\n WriteRegDWORD HKCU \"Software\\Microsoft\\Windows\\Cur" +
"rentVersion\\Uninstall\\${APPNAME}\" \"EstimatedSize\" ${INSTALLSIZE}\r\nSectionEnd ; e" +
"nd the section\r\n\r\nFunction .onInstSuccess\r\n IfSilent +2\r\n Exec \'\"$INSTDIR\\" +
"${EXECUTABLE}\"\'\r\nFunctionEnd\r\n\r\nSection \"uninstall\"\r\n DetailPrint \'Please wai" +
"t...\'\r\n SetShellVarContext current\r\n SetDetailsPrint None\r\n SetAutoClos" +
"e true\r\n \r\n # Remove Start Menu launcher\r\n Delete \"$SMPROGRAMS\\${COMPAN" +
"YNAME}\\${APPNAME}.lnk\"\r\n Delete \"$DESKTOP\\${APPNAME}.lnk\"\r\n StrCpy $0 ${EX" +
"ECUTABLE} -4\r\n Delete \"$APPDATA\\Microsoft\\Internet Explorer\\Quick Launch\\User" +
" Pinned\\TaskBar\\${APPNAME}.lnk\"\r\n Delete \"$APPDATA\\Microsoft\\Internet Explore" +
"r\\Quick Launch\\User Pinned\\TaskBar\\$0.lnk\"\r\n # Try to remove the Start Menu f" +
"older - this will only happen if it is empty\r\n RMDir \"$SMPROGRAMS\\${COMPANYNA" +
"ME}\"\r\n\r\n # Always delete uninstaller as the last action\r\n delete $INSTDIR\\" +
"uninstall.exe\r\n\r\n # Try to remove the install directory - this will only happ" +
"en if it is empty\r\n RMDir /r /REBOOTOK $INSTDIR\r\n\r\n # Remove uninstaller i" +
"nformation from the registry\r\n DeleteRegKey HKCU \"Software\\Microsoft\\Windows\\" +
"CurrentVersion\\Uninstall\\${APPNAME}\"\r\nsectionEnd");
return this.GenerationEnvironment.ToString();
}
}
#line default
#line hidden
#region Base class
/// <summary>
/// Base class for this transformation
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")]
public class SetupTmplBase
{
#region Fields
private global::System.Text.StringBuilder generationEnvironmentField;
private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
private global::System.Collections.Generic.List<int> indentLengthsField;
private string currentIndentField = "";
private bool endsWithNewline;
private global::System.Collections.Generic.IDictionary<string, object> sessionField;
#endregion
#region Properties
/// <summary>
/// The string builder that generation-time code is using to assemble generated output
/// </summary>
protected System.Text.StringBuilder GenerationEnvironment
{
get
{
if ((this.generationEnvironmentField == null))
{
this.generationEnvironmentField = new global::System.Text.StringBuilder();
}
return this.generationEnvironmentField;
}
set
{
this.generationEnvironmentField = value;
}
}
/// <summary>
/// The error collection for the generation process
/// </summary>
public System.CodeDom.Compiler.CompilerErrorCollection Errors
{
get
{
if ((this.errorsField == null))
{
this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
}
return this.errorsField;
}
}
/// <summary>
/// A list of the lengths of each indent that was added with PushIndent
/// </summary>
private System.Collections.Generic.List<int> indentLengths
{
get
{
if ((this.indentLengthsField == null))
{
this.indentLengthsField = new global::System.Collections.Generic.List<int>();
}
return this.indentLengthsField;
}
}
/// <summary>
/// Gets the current indent we use when adding lines to the output
/// </summary>
public string CurrentIndent
{
get
{
return this.currentIndentField;
}
}
/// <summary>
/// Current transformation session
/// </summary>
public virtual global::System.Collections.Generic.IDictionary<string, object> Session
{
get
{
return this.sessionField;
}
set
{
this.sessionField = value;
}
}
#endregion
#region Transform-time helpers
/// <summary>
/// Write text directly into the generated output
/// </summary>
public void Write(string textToAppend)
{
if (string.IsNullOrEmpty(textToAppend))
{
return;
}
// If we're starting off, or if the previous text ended with a newline,
// we have to append the current indent first.
if (((this.GenerationEnvironment.Length == 0)
|| this.endsWithNewline))
{
this.GenerationEnvironment.Append(this.currentIndentField);
this.endsWithNewline = false;
}
// Check if the current text ends with a newline
if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
{
this.endsWithNewline = true;
}
// This is an optimization. If the current indent is "", then we don't have to do any
// of the more complex stuff further down.
if ((this.currentIndentField.Length == 0))
{
this.GenerationEnvironment.Append(textToAppend);
return;
}
// Everywhere there is a newline in the text, add an indent after it
textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
// If the text ends with a newline, then we should strip off the indent added at the very end
// because the appropriate indent will be added when the next time Write() is called
if (this.endsWithNewline)
{
this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
}
else
{
this.GenerationEnvironment.Append(textToAppend);
}
}
/// <summary>
/// Write text directly into the generated output
/// </summary>
public void WriteLine(string textToAppend)
{
this.Write(textToAppend);
this.GenerationEnvironment.AppendLine();
this.endsWithNewline = true;
}
/// <summary>
/// Write formatted text directly into the generated output
/// </summary>
public void Write(string format, params object[] args)
{
this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
}
/// <summary>
/// Write formatted text directly into the generated output
/// </summary>
public void WriteLine(string format, params object[] args)
{
this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
}
/// <summary>
/// Raise an error
/// </summary>
public void Error(string message)
{
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
error.ErrorText = message;
this.Errors.Add(error);
}
/// <summary>
/// Raise a warning
/// </summary>
public void Warning(string message)
{
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
error.ErrorText = message;
error.IsWarning = true;
this.Errors.Add(error);
}
/// <summary>
/// Increase the indent
/// </summary>
public void PushIndent(string indent)
{
if ((indent == null))
{
throw new global::System.ArgumentNullException("indent");
}
this.currentIndentField = (this.currentIndentField + indent);
this.indentLengths.Add(indent.Length);
}
/// <summary>
/// Remove the last indent that was added with PushIndent
/// </summary>
public string PopIndent()
{
string returnValue = "";
if ((this.indentLengths.Count > 0))
{
int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
if ((indentLength > 0))
{
returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
}
}
return returnValue;
}
/// <summary>
/// Remove any indentation
/// </summary>
public void ClearIndent()
{
this.indentLengths.Clear();
this.currentIndentField = "";
}
#endregion
#region ToString Helpers
/// <summary>
/// Utility class to produce culture-oriented representation of an object as a string.
/// </summary>
public class ToStringInstanceHelper
{
private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
/// <summary>
/// Gets or sets format provider to be used by ToStringWithCulture method.
/// </summary>
public System.IFormatProvider FormatProvider
{
get
{
return this.formatProviderField ;
}
set
{
if ((value != null))
{
this.formatProviderField = value;
}
}
}
/// <summary>
/// This is called from the compile/run appdomain to convert objects within an expression block to a string
/// </summary>
public string ToStringWithCulture(object objectToConvert)
{
if ((objectToConvert == null))
{
throw new global::System.ArgumentNullException("objectToConvert");
}
System.Type t = objectToConvert.GetType();
System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
typeof(System.IFormatProvider)});
if ((method == null))
{
return objectToConvert.ToString();
}
else
{
return ((string)(method.Invoke(objectToConvert, new object[] {
this.formatProviderField })));
}
}
}
private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
/// <summary>
/// Helper to produce culture-oriented representation of an object as a string
/// </summary>
public ToStringInstanceHelper ToStringHelper
{
get
{
return this.toStringHelperField;
}
}
#endregion
}
#endregion
}

121
Creator/SetupTmpl.tt Normal file
View File

@ -0,0 +1,121 @@
<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
Unicode true
ManifestDPIAware true
!define APPNAME "<#= AppName #>"
!define EXECUTABLE "<#= Executable #>"
!define SOURCEPATH "<#= SourcePath #>"
!define COMPANYNAME "<#= CompanyName #>"
!define DESCRIPTION "<#= Description #>"
!define VERSION <#= Version.ToString() #>
!define HELPURL <#= HelpUrl #>
!define INSTALLSIZE <#= InstallSize #>
!define ISMANAGED <#= IsManaged ? 1 : 0 #>
; exampleCmd: makensis.exe /DVERSION=1.0.0.5 /DNAME=WpfApp1 Setup.nsi
Name "${APPNAME}"
OutFile "<#= OutFile #>"
InstallDir "$LOCALAPPDATA\${APPNAME}"
RequestExecutionLevel user
SetCompressor /SOLID lzma
SilentUnInstall silent
; Subcaption 3 " "
XPStyle on
AutoCloseWindow true
ChangeUI all "<#= UserInterface #>"
Icon "<#= IconPath #>"
UninstallIcon "<#= UninstallIcon #>"
ShowInstDetails nevershow
ShowUninstDetails nevershow
BrandingText "${COMPANYNAME}"
VIProductVersion <#= LegacyVersion.ToString(4) #>
VIAddVersionKey ProductName "${APPNAME}"
VIAddVersionKey Comments ""
VIAddVersionKey CompanyName "${COMPANYNAME}"
VIAddVersionKey LegalCopyright "${COMPANYNAME}"
VIAddVersionKey FileDescription "${DESCRIPTION}"
VIAddVersionKey FileVersion "${VERSION}"
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey OriginalFilename "<#= OutFile #>"
;--------------------------------
; The stuff to install
Section "install" ;No components page, name is not important
DetailPrint 'Installing ${APPNAME}. Please wait...'
SetShellVarContext current
SetDetailsPrint None
IfSilent +2
RMDir /r $INSTDIR
SetOutPath $INSTDIR
; Create sub-directories
<# foreach(var directory in Directories) { #><#= $" CreateDirectory \"$INSTDIR\\{directory}\"{Environment.NewLine}" #><# } #>
; Put file there
<#foreach(var file in Files) { #><#= $" File \"/oname={file.TargetPath}\" \"{file.SourcePath}\"{Environment.NewLine}" #><# } #>
WriteUninstaller "$INSTDIR\uninstall.exe"
; Desktop
CreateShortCut "$DESKTOP\${APPNAME}.lnk" "$INSTDIR\${EXECUTABLE}"
# Start Menu
CreateDirectory "$SMPROGRAMS\${COMPANYNAME}"
CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\${EXECUTABLE}"
# Update pinned Taskbar
IfFileExists "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\${APPNAME}.lnk" 0 +2
CreateShortCut "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\${APPNAME}.lnk" "$INSTDIR\${EXECUTABLE}"
SetOutPath $INSTDIR\app-${VERSION}
StrCpy $0 ${EXECUTABLE} -4
IfFileExists "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\$0.lnk" 0 +2
CreateShortCut "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\$0.lnk" "$INSTDIR\app-${VERSION}\${EXECUTABLE}"
# Registry information for add/remove programs
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayIcon" "$\"$INSTDIR\app-${VERSION}\${EXECUTABLE}$\""
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "${COMPANYNAME}"
; WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "${HELPURL}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "${VERSION}"
# There is no option for modifying or repairing the install
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoModify" 1
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoRepair" 1
# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
SectionEnd ; end the section
Function .onInstSuccess
IfSilent +2
Exec '"$INSTDIR\${EXECUTABLE}"'
FunctionEnd
Section "uninstall"
DetailPrint 'Please wait...'
SetShellVarContext current
SetDetailsPrint None
SetAutoClose true
# Remove Start Menu launcher
Delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
Delete "$DESKTOP\${APPNAME}.lnk"
StrCpy $0 ${EXECUTABLE} -4
Delete "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\${APPNAME}.lnk"
Delete "$APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\$0.lnk"
# Try to remove the Start Menu folder - this will only happen if it is empty
RMDir "$SMPROGRAMS\${COMPANYNAME}"
# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe
# Try to remove the install directory - this will only happen if it is empty
RMDir /r /REBOOTOK $INSTDIR
# Remove uninstaller information from the registry
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
sectionEnd

84
Creator/SetupTmplCode.cs Normal file
View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Katteker;
namespace KattekerCreator
{
public partial class SetupTmpl
{
public string AppName
{
get => string.IsNullOrWhiteSpace(ReleaseChannel) ? _appName : $"{_appName}_{ReleaseChannel}";
set => _appName = value;
}
public string Executable { get; set; }
public string CompanyName { get; set; }
public string Description { get; set; }
public SemanticVersion Version { get; set; }
public Version LegacyVersion => Version.ToSystemVersion();
public string HelpUrl { get; set; }
public long InstallSize { get; set; }
public bool IsManaged { get; set; }
public string IconPath { get; set; }
public string SourcePath { get; set; } = string.Empty;
public List<PhysicalFile> Files { get; set; } = new List<PhysicalFile>();
private IEnumerable<string> Directories => DirectoriesToCreate();
public string UserInterface { get; set; }
public string OutFile { get; set; }
public string UninstallIcon { get; set; }
public string ReleaseChannel { get; set; }
private readonly List<DirSplit> _directoriesList = new List<DirSplit>();
private string _appName;
private IEnumerable<string> DirectoriesToCreate()
{
foreach (var physicalFile in Files)
{
var dirSplit = new DirSplit(physicalFile.TargetPath);
if (dirSplit.SplitCount > 1 && !_directoriesList.Contains(dirSplit))
{
_directoriesList.Add(dirSplit);
}
}
return _directoriesList.Select(x=> x.ToString());
}
private class DirSplit
{
private const char SplitChar = '\\';
private readonly string[] _splits;
public int SplitCount => _splits.Length;
public DirSplit(string path)
{
_splits = path.Split(SplitChar);
}
public override string ToString()
{
return string.Join(SplitChar.ToString(), _splits.Take(_splits.Length - 1));
}
public override bool Equals(object obj)
{
return string.Equals(ToString(), obj?.ToString());
}
protected bool Equals(DirSplit other)
{
return Equals(_splits, other._splits);
}
public override int GetHashCode()
{
return (_splits != null ? _splits.GetHashCode() : 0);
}
}
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

4
Creator/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Vestris.ResourceLib" version="1.6.422" targetFramework="net45" />
</packages>

19
Creator/reference.nuspec Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$id$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<copyright>$copyright$</copyright>
</metadata>
<files>
<file src="bin\$configuration$\*.dll" target="lib\net45" />
<file src="bin\$configuration$\*.config" target="lib\net45" exclude="bin\$configuration$\*.vshost.exe.config" />
<file src="bin\$configuration$\*.exe" target="lib\net45" exclude="bin\$configuration$\*.vshost.exe" />
<file src="..\packages\squirrel.windows.0.99.1.1\tools\Squirrel.exe" target="lib\net45" />
</files>
</package>