Compare commits

...

3 Commits

14 changed files with 127 additions and 89 deletions

View File

@ -0,0 +1,28 @@
using System;
using System.Threading;
namespace KattekerCreator.Helper
{
public class TemporaryDirectory : IDisposable
{
public string Path { get; }
public TemporaryDirectory(string path)
{
Path = path;
}
void IDisposable.Dispose()
{
try
{
Thread.Sleep(100);
System.IO.Directory.Delete(Path, true);
}
catch
{
//ignore.
}
}
}
}

View File

@ -19,7 +19,7 @@ namespace KattekerCreator.Helper
return false; return false;
} }
public static string CreateTempDirectory() public static TemporaryDirectory CreateTempDirectory()
{ {
string result; string result;
do do
@ -29,7 +29,7 @@ namespace KattekerCreator.Helper
} while (Directory.Exists(result)); } while (Directory.Exists(result));
Directory.CreateDirectory(result); Directory.CreateDirectory(result);
return result; return new TemporaryDirectory(result);
} }
public static bool IsFilesizeWrong(string filename) public static bool IsFilesizeWrong(string filename)

View File

@ -52,6 +52,7 @@
<Compile Include="ApplicationArguments.cs" /> <Compile Include="ApplicationArguments.cs" />
<Compile Include="AssemblyFileInfo.cs" /> <Compile Include="AssemblyFileInfo.cs" />
<Compile Include="Helper\Log.cs" /> <Compile Include="Helper\Log.cs" />
<Compile Include="Helper\TemporaryDirectory.cs" />
<Compile Include="IconExtractor\IconExtractor.cs" /> <Compile Include="IconExtractor\IconExtractor.cs" />
<Compile Include="IconExtractor\IconUtil.cs" /> <Compile Include="IconExtractor\IconUtil.cs" />
<Compile Include="IconExtractor\NativeMethods.cs" /> <Compile Include="IconExtractor\NativeMethods.cs" />

View File

@ -10,11 +10,12 @@ namespace KattekerCreator
{ {
public class Program public class Program
{ {
private const string Executable = @"C:\Program Files (x86)\NSIS\makensis.exe"; //private const string MakeNsis = @"C:\Program Files (x86)\NSIS\makensis.exe";
private readonly string _baseDirectory = AppDomain.CurrentDomain.BaseDirectory; private readonly string _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
private string MakeNsis => Path.Combine(_baseDirectory, "NSIS", "makensis.exe");
private ApplicationArguments _appArguments; private ApplicationArguments _appArguments;
private AssemblyFileInfo _assemblyFileInfo; private AssemblyFileInfo _assemblyFileInfo;
private string _tempDir; private TemporaryDirectory _tempDir;
private Releases _releases; private Releases _releases;
private static int Main(string[] args) private static int Main(string[] args)
@ -50,31 +51,33 @@ namespace KattekerCreator
_appArguments = parser.GetObject(); _appArguments = parser.GetObject();
//Create tempdir //Create tempdir
_tempDir = Utils.CreateTempDirectory(); using (_tempDir = Utils.CreateTempDirectory())
_releases = new Releases(_appArguments.OutputDir);
parser.ShowProgramArguments();
//Modify AppStub
var appStubFile = ModifyAppStub();
//Acquire infos from Executable.
_assemblyFileInfo = new AssemblyFileInfo(_appArguments, _tempDir);
var configFile = CreateConfigFile();
//Generate NSIS-Script
var additionalFiles = new[]
{ {
new PhysicalFile(appStubFile, Path.GetFileName(_appArguments.ProgramFile)), _releases = new Releases(_appArguments.OutputDir);
new PhysicalFile(configFile, Path.Combine($"app-{_assemblyFileInfo.AssemblyVersion}", Path.GetFileName(configFile) ?? string.Empty)) parser.ShowProgramArguments();
}; //Modify AppStub
var templateFile = GenerateNsisTemplate(additionalFiles); var appStubFile = ModifyAppStub();
//Start makensis.exe //Acquire infos from Executable.
var setupFilePath = CompileSetupScript(templateFile); _assemblyFileInfo = new AssemblyFileInfo(_appArguments, _tempDir.Path);
//Copy to Output-Folder var configFile = CreateConfigFile();
CopyToOutputFolder(setupFilePath);
//Create/Modify RELEASE File //Generate NSIS-Script
var releaseEntry = AddPackageToReleaseFile(setupFilePath); var additionalFiles = new[]
//Copy installer as setup.exe {
CopyAsSetup(setupFilePath, releaseEntry); new PhysicalFile(appStubFile, Path.GetFileName(_appArguments.ProgramFile)),
return 0; new PhysicalFile(configFile, Path.Combine($"app-{_assemblyFileInfo.AssemblyVersion}", Path.GetFileName(configFile) ?? string.Empty))
};
var templateFile = GenerateNsisTemplate(additionalFiles);
//Start makensis.exe
var setupFilePath = CompileSetupScript(templateFile);
//Copy to Output-Folder
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) private void CopyAsSetup(string setupFilePath, ReleaseEntry releaseEntry)
@ -117,15 +120,15 @@ namespace KattekerCreator
File.Copy(setupFilePath, Path.Combine(_appArguments.OutputDir, setupFile), true); File.Copy(setupFilePath, Path.Combine(_appArguments.OutputDir, setupFile), true);
} }
private static string CompileSetupScript(string templateFile) private string CompileSetupScript(string templateFile)
{ {
if (!File.Exists(Executable)) throw new FileNotFoundException("NSIS not installed properly."); if (!File.Exists(MakeNsis)) throw new FileNotFoundException("NSIS not installed properly.");
int exitcode; int exitcode;
using (var p = new Process()) using (var p = new Process())
{ {
p.StartInfo = new ProcessStartInfo p.StartInfo = new ProcessStartInfo
{ {
FileName = Executable, FileName = MakeNsis,
Arguments = $"\"{templateFile}\"", Arguments = $"\"{templateFile}\"",
UseShellExecute = false UseShellExecute = false
}; };
@ -133,20 +136,21 @@ namespace KattekerCreator
p.Start(); p.Start();
p.WaitForExit(); p.WaitForExit();
exitcode = p.ExitCode; exitcode = p.ExitCode;
Log.WriteInfoLine($"{Path.GetFileName(Executable)} has exited with Exitcode: {exitcode} (Took: {sw.ElapsedMilliseconds}ms)"); Log.WriteInfoLine($"{Path.GetFileName(MakeNsis)} has exited with Exitcode: {exitcode} (Took: {sw.ElapsedMilliseconds}ms)");
} }
if (exitcode != 0) throw new Exception($"{Path.GetFileName(Executable)} has exited with Exitcode: {exitcode}"); if (exitcode != 0) throw new Exception($"{Path.GetFileName(MakeNsis)} has exited with Exitcode: {exitcode}");
return Path.ChangeExtension(templateFile, "exe"); return Path.ChangeExtension(templateFile, "exe");
} }
private string CreateConfigFile() private string CreateConfigFile()
{ {
var pathToFile = Path.Combine(_tempDir, Constants.KattekerConfig); var pathToFile = Path.Combine(_tempDir.Path, Constants.KattekerConfig);
var kattekerConfig = new KattekerConfig var kattekerConfig = new KattekerConfig
{ {
Publish = _appArguments.PublishDir ?? _appArguments.OutputDir, Publish = _appArguments.PublishDir ?? _appArguments.OutputDir,
Changelog = Path.GetFileName(_appArguments.ChangeLog) Changelog = Path.GetFileName(_appArguments.ChangeLog),
Channel = _appArguments.Channel
}; };
kattekerConfig.WriteToFile(pathToFile); kattekerConfig.WriteToFile(pathToFile);
return pathToFile; return pathToFile;
@ -155,7 +159,7 @@ namespace KattekerCreator
private string ModifyAppStub() private string ModifyAppStub()
{ {
var baseFile = new FileInfo(Path.Combine(_baseDirectory, Constants.ExecutionStub)); var baseFile = new FileInfo(Path.Combine(_baseDirectory, Constants.ExecutionStub));
var targetFile = baseFile.CopyTo(Path.Combine(_tempDir, Constants.ExecutionStub)); var targetFile = baseFile.CopyTo(Path.Combine(_tempDir.Path, Constants.ExecutionStub));
Utils.CopyResources(_appArguments.ProgramFile, targetFile.FullName); Utils.CopyResources(_appArguments.ProgramFile, targetFile.FullName);
return targetFile.FullName; return targetFile.FullName;
} }
@ -166,7 +170,7 @@ namespace KattekerCreator
{ {
try try
{ {
var outFile = Path.Combine(_tempDir, GenerateFilename(_assemblyFileInfo.ProductName, _assemblyFileInfo.AssemblyVersion.ToString(), "nsi")); var outFile = Path.Combine(_tempDir.Path, GenerateFilename(_assemblyFileInfo.ProductName, _assemblyFileInfo.AssemblyVersion.ToString(), "nsi"));
var setupTmpl = new SetupTmpl var setupTmpl = new SetupTmpl
{ {
Executable = _assemblyFileInfo.FileInfo.Name, Executable = _assemblyFileInfo.FileInfo.Name,

View File

@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.1.0")]

View File

@ -34,6 +34,9 @@
<DocumentationFile>bin\Release\Katteker.UserInterface.xml</DocumentationFile> <DocumentationFile>bin\Release\Katteker.UserInterface.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Katteker, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Katteker.1.1.0\lib\net45\Katteker.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -59,6 +62,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
<None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
@ -70,12 +74,6 @@
<DependentUpon>UpdateWindow.cs</DependentUpon> <DependentUpon>UpdateWindow.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </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" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent> <PostBuildEvent>

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0")] [assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.0.0")] [assembly: AssemblyFileVersion("1.1.4")]

View File

@ -90,30 +90,27 @@ namespace Katteker
} }
changelogContent = changelogContent.ChangelogAsHtml(Path.GetExtension(Changelog)); changelogContent = changelogContent.ChangelogAsHtml(Path.GetExtension(Changelog));
Invoke(new Action(() => changelogBrowser.DocumentText = changelogContent)); InvokeOnGui(() => changelogBrowser.DocumentText = changelogContent);
if (_entry == null) if (_entry == null)
{ {
Invoke(new Action(() => { WriteTitle(Resources.No_update_available); })); WriteTitle(Resources.No_update_available);
} }
else else
{ {
var latest = _entry.Version; var latest = _entry.Version;
Invoke(new Action(() => WriteTitle(Resources.You_can_update_to_Version + latest);
{ InvokeOnGui(() => updBtn.Visible = true);
WriteTitle(Resources.You_can_update_to_Version + latest);
updBtn.Visible = true;
}));
} }
} }
private async void UpdBtn_Click(object sender, EventArgs e) private async void UpdBtn_Click(object sender, EventArgs e)
{ {
Invoke(new Action(() => progressBar1.Visible = true)); InvokeOnGui(() => progressBar1.Visible = true);
try try
{ {
var progress = new Progress<int>(x => Invoke(new Action(() => { progressBar1.Value = x; }))); var progress = new Progress<int>(x => InvokeOnGui(() => progressBar1.Value = x));
await _updateManager.UpdateAppAsync(progress).ConfigureAwait(false); await _updateManager.UpdateAppAsync(progress).ConfigureAwait(false);
WriteTitle(Resources.You_re_up_to_date); WriteTitle(Resources.You_re_up_to_date);
@ -124,8 +121,12 @@ namespace Katteker
MessageBoxIcon.Question); MessageBoxIcon.Question);
if (messResult == DialogResult.Yes) if (messResult == DialogResult.Yes)
{ {
DialogResult = DialogResult.OK; InvokeOnGui(() =>
Close(); {
DialogResult = DialogResult.OK;
Close();
});
return;
} }
} }
catch (Exception ex) catch (Exception ex)
@ -134,23 +135,34 @@ namespace Katteker
Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error); Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error);
WriteTitle(Resources.Updater); WriteTitle(Resources.Updater);
} }
finally
InvokeOnGui(() =>
{ {
Invoke(new Action(() => progressBar1.Visible = false;
{ updBtn.Visible = false;
progressBar1.Visible = false; });
updBtn.Visible = false;
}));
}
} }
private void WriteTitle(string text) private void WriteTitle(string text)
{ {
Invoke(new Action(() => InvokeOnGui(() =>
{ {
Text = text; Text = text;
titlebar.Text = text; titlebar.Text = text;
})); });
}
private void InvokeOnGui(Action action)
{
if (Disposing || IsDisposed) return;
if (InvokeRequired)
{
Invoke(action);
}
else
{
action();
}
} }
} }
} }

View File

@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -13,7 +12,6 @@ namespace Katteker
public static class UserInterface public static class UserInterface
{ {
private static UpdateManager _manager; private static UpdateManager _manager;
private static Action _restartApp;
/// <summary> /// <summary>
/// Checks for Updates. /// Checks for Updates.
@ -40,8 +38,7 @@ namespace Katteker
} }
var releases = (await _manager.CheckForUpdateAsync().ConfigureAwait(false)).ToArray(); var releases = (await _manager.CheckForUpdateAsync().ConfigureAwait(false)).ToArray();
_restartApp = () => _manager.RestartApp(); if (releases.Length > 0 || !isStartup)
if (releases.Any() || !isStartup)
{ {
var thread = new Thread(ThreadProcess); var thread = new Thread(ThreadProcess);
thread.SetApartmentState(ApartmentState.STA); thread.SetApartmentState(ApartmentState.STA);
@ -58,7 +55,7 @@ namespace Katteker
var dialogResult = window.ShowDialog(); var dialogResult = window.ShowDialog();
if (dialogResult == DialogResult.OK) if (dialogResult == DialogResult.OK)
{ {
_restartApp?.Invoke(); _manager.RestartApp();
} }
} }
} }

View File

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

View File

@ -60,33 +60,21 @@
<Content Include="testdata\Example.exe"> <Content Include="testdata\Example.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="testdata\Example.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Example.vshost.exe"> <Content Include="testdata\Example.vshost.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="testdata\Katteker.dll"> <Content Include="testdata\Katteker.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="testdata\Katteker.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Katteker.UserInterface.dll"> <Content Include="testdata\Katteker.UserInterface.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="testdata\Katteker.UserInterface.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Katteker.UserInterface.xml"> <Content Include="testdata\Katteker.UserInterface.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="testdata\Microsoft.Practices.ServiceLocation.dll"> <Content Include="testdata\Microsoft.Practices.ServiceLocation.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="testdata\Microsoft.Practices.ServiceLocation.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Microsoft.Practices.ServiceLocation.xml"> <Content Include="testdata\Microsoft.Practices.ServiceLocation.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>

View File

@ -7,7 +7,7 @@ namespace Katteker
/// <summary> /// <summary>
/// Configuration of a Katteker-Deployment /// Configuration of a Katteker-Deployment
/// </summary> /// </summary>
[Serializable] [Serializable]
public class KattekerConfig public class KattekerConfig
{ {
/// <summary> /// <summary>
@ -20,6 +20,11 @@ namespace Katteker
/// </summary> /// </summary>
public string Changelog { get; set; } public string Changelog { get; set; }
/// <summary>
/// Channel of the application. (Alpha, Beta and so on...)
/// </summary>
public string Channel { get; set; }
/// <summary> /// <summary>
/// Read file and deserialize content. /// Read file and deserialize content.
/// </summary> /// </summary>

View File

@ -32,6 +32,6 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben: // indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.4")] [assembly: AssemblyVersion("1.1.1")]
[assembly: AssemblyFileVersion("1.0.4")] [assembly: AssemblyFileVersion("1.1.1")]
[assembly: InternalsVisibleTo("Katteker.Test")] [assembly: InternalsVisibleTo("Katteker.Test")]

View File

@ -55,7 +55,8 @@ namespace Katteker
_config = ReadConfigFile(); _config = ReadConfigFile();
urlOrPath = urlOrPath ?? _config.Publish; urlOrPath = urlOrPath ?? _config.Publish;
var appName = applicationName ?? Utility.GetApplicationName(); var appName = applicationName ?? Utility.GetApplicationName();
var rootAppDirectory = Path.Combine(rootDirectory ?? Utility.GetLocalAppDataDirectory(), appName); var channel = string.IsNullOrWhiteSpace(_config.Channel) ? string.Empty : $"_{_config.Channel}";
var rootAppDirectory = Path.Combine(rootDirectory ?? Utility.GetLocalAppDataDirectory(), appName + channel);
return new UpdateManager(urlOrPath, appName, rootAppDirectory); return new UpdateManager(urlOrPath, appName, rootAppDirectory);
} }