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;
}
public static string CreateTempDirectory()
public static TemporaryDirectory CreateTempDirectory()
{
string result;
do
@ -29,7 +29,7 @@ namespace KattekerCreator.Helper
} while (Directory.Exists(result));
Directory.CreateDirectory(result);
return result;
return new TemporaryDirectory(result);
}
public static bool IsFilesizeWrong(string filename)

View File

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

View File

@ -10,11 +10,12 @@ namespace KattekerCreator
{
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 string MakeNsis => Path.Combine(_baseDirectory, "NSIS", "makensis.exe");
private ApplicationArguments _appArguments;
private AssemblyFileInfo _assemblyFileInfo;
private string _tempDir;
private TemporaryDirectory _tempDir;
private Releases _releases;
private static int Main(string[] args)
@ -50,31 +51,33 @@ namespace KattekerCreator
_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, _tempDir);
var configFile = CreateConfigFile();
//Generate NSIS-Script
var additionalFiles = new[]
using (_tempDir = Utils.CreateTempDirectory())
{
new PhysicalFile(appStubFile, Path.GetFileName(_appArguments.ProgramFile)),
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;
_releases = new Releases(_appArguments.OutputDir);
parser.ShowProgramArguments();
//Modify AppStub
var appStubFile = ModifyAppStub();
//Acquire infos from Executable.
_assemblyFileInfo = new AssemblyFileInfo(_appArguments, _tempDir.Path);
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) ?? 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)
@ -117,15 +120,15 @@ namespace KattekerCreator
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;
using (var p = new Process())
{
p.StartInfo = new ProcessStartInfo
{
FileName = Executable,
FileName = MakeNsis,
Arguments = $"\"{templateFile}\"",
UseShellExecute = false
};
@ -133,20 +136,21 @@ namespace KattekerCreator
p.Start();
p.WaitForExit();
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");
}
private string CreateConfigFile()
{
var pathToFile = Path.Combine(_tempDir, Constants.KattekerConfig);
var pathToFile = Path.Combine(_tempDir.Path, Constants.KattekerConfig);
var kattekerConfig = new KattekerConfig
{
Publish = _appArguments.PublishDir ?? _appArguments.OutputDir,
Changelog = Path.GetFileName(_appArguments.ChangeLog)
Changelog = Path.GetFileName(_appArguments.ChangeLog),
Channel = _appArguments.Channel
};
kattekerConfig.WriteToFile(pathToFile);
return pathToFile;
@ -155,7 +159,7 @@ namespace KattekerCreator
private string ModifyAppStub()
{
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);
return targetFile.FullName;
}
@ -166,7 +170,7 @@ namespace KattekerCreator
{
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
{
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
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]

View File

@ -34,6 +34,9 @@
<DocumentationFile>bin\Release\Katteker.UserInterface.xml</DocumentationFile>
</PropertyGroup>
<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="System" />
<Reference Include="System.Core" />
@ -59,6 +62,7 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
@ -70,12 +74,6 @@
<DependentUpon>UpdateWindow.cs</DependentUpon>
</EmbeddedResource>
</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" />
<PropertyGroup>
<PostBuildEvent>

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// 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")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]

View File

@ -90,30 +90,27 @@ namespace Katteker
}
changelogContent = changelogContent.ChangelogAsHtml(Path.GetExtension(Changelog));
Invoke(new Action(() => changelogBrowser.DocumentText = changelogContent));
InvokeOnGui(() => changelogBrowser.DocumentText = changelogContent);
if (_entry == null)
{
Invoke(new Action(() => { WriteTitle(Resources.No_update_available); }));
WriteTitle(Resources.No_update_available);
}
else
{
var latest = _entry.Version;
Invoke(new Action(() =>
{
WriteTitle(Resources.You_can_update_to_Version + latest);
updBtn.Visible = true;
}));
WriteTitle(Resources.You_can_update_to_Version + latest);
InvokeOnGui(() => updBtn.Visible = true);
}
}
private async void UpdBtn_Click(object sender, EventArgs e)
{
Invoke(new Action(() => progressBar1.Visible = true));
InvokeOnGui(() => progressBar1.Visible = true);
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);
WriteTitle(Resources.You_re_up_to_date);
@ -124,8 +121,12 @@ namespace Katteker
MessageBoxIcon.Question);
if (messResult == DialogResult.Yes)
{
DialogResult = DialogResult.OK;
Close();
InvokeOnGui(() =>
{
DialogResult = DialogResult.OK;
Close();
});
return;
}
}
catch (Exception ex)
@ -134,23 +135,34 @@ namespace Katteker
Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error);
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)
{
Invoke(new Action(() =>
InvokeOnGui(() =>
{
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.Tasks;
using System.Windows.Forms;
@ -13,7 +12,6 @@ namespace Katteker
public static class UserInterface
{
private static UpdateManager _manager;
private static Action _restartApp;
/// <summary>
/// Checks for Updates.
@ -40,8 +38,7 @@ namespace Katteker
}
var releases = (await _manager.CheckForUpdateAsync().ConfigureAwait(false)).ToArray();
_restartApp = () => _manager.RestartApp();
if (releases.Any() || !isStartup)
if (releases.Length > 0 || !isStartup)
{
var thread = new Thread(ThreadProcess);
thread.SetApartmentState(ApartmentState.STA);
@ -58,7 +55,7 @@ namespace Katteker
var dialogResult = window.ShowDialog();
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">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Example.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Example.vshost.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Katteker.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Katteker.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Katteker.UserInterface.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Katteker.UserInterface.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Katteker.UserInterface.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Microsoft.Practices.ServiceLocation.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Microsoft.Practices.ServiceLocation.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="testdata\Microsoft.Practices.ServiceLocation.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@ -7,7 +7,7 @@ namespace Katteker
/// <summary>
/// Configuration of a Katteker-Deployment
/// </summary>
[Serializable]
[Serializable]
public class KattekerConfig
{
/// <summary>
@ -20,6 +20,11 @@ namespace Katteker
/// </summary>
public string Changelog { get; set; }
/// <summary>
/// Channel of the application. (Alpha, Beta and so on...)
/// </summary>
public string Channel { get; set; }
/// <summary>
/// Read file and deserialize content.
/// </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,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.4")]
[assembly: AssemblyFileVersion("1.0.4")]
[assembly: AssemblyVersion("1.1.1")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: InternalsVisibleTo("Katteker.Test")]

View File

@ -55,7 +55,8 @@ namespace Katteker
_config = ReadConfigFile();
urlOrPath = urlOrPath ?? _config.Publish;
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);
}