Compare commits

...

2 Commits

Author SHA1 Message Date
Holger Boerchers
26343921f7 Merge branch 'master' of https://git.boerchers.org/holger/Katteker 2018-05-26 23:18:45 +02:00
Holger Boerchers
d87adfc7f0 Refactored ChangelogHelper 2018-05-26 23:18:39 +02:00
2 changed files with 45 additions and 30 deletions

View File

@ -10,7 +10,7 @@ namespace KattekerCreator
{ {
public class Program public class Program
{ {
private const string _executable = @"C:\Program Files (x86)\NSIS\makensis.exe"; private const string Executable = @"C:\Program Files (x86)\NSIS\makensis.exe";
private readonly string _baseDirectory = AppDomain.CurrentDomain.BaseDirectory; private readonly string _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
private ApplicationArguments _appArguments; private ApplicationArguments _appArguments;
private AssemblyFileInfo _assemblyFileInfo; private AssemblyFileInfo _assemblyFileInfo;
@ -119,13 +119,13 @@ namespace KattekerCreator
private static string CompileSetupScript(string templateFile) private static string CompileSetupScript(string templateFile)
{ {
if (!File.Exists(_executable)) throw new FileNotFoundException("NSIS not installed properly."); if (!File.Exists(Executable)) 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 = Executable,
Arguments = $"\"{templateFile}\"", Arguments = $"\"{templateFile}\"",
UseShellExecute = false UseShellExecute = false
}; };
@ -133,10 +133,10 @@ 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(Executable)} 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(Executable)} has exited with Exitcode: {exitcode}");
return Path.ChangeExtension(templateFile, "exe"); return Path.ChangeExtension(templateFile, "exe");
} }

View File

@ -48,7 +48,16 @@ namespace Katteker
{ {
if (!path.EndsWith("/", StringComparison.Ordinal)) if (!path.EndsWith("/", StringComparison.Ordinal))
path += "/"; path += "/";
var webReq = WebRequest.Create(path + filename); var changelog = await ReadFromRemoteFile(path + filename) ?? ReadFromLocalFile(filename);
return changelog;
}
return null;
}
private static async Task<string> ReadFromRemoteFile(string path)
{
var webReq = WebRequest.Create(path);
try try
{ {
using (var response = await webReq.GetResponseAsync().ConfigureAwait(false)) using (var response = await webReq.GetResponseAsync().ConfigureAwait(false))
@ -58,24 +67,30 @@ namespace Katteker
} }
} }
catch (Exception) catch (Exception)
{
// ignore;
}
return null;
}
private static string ReadFromLocalFile(string filename)
{ {
try try
{ {
var changelogFilename = Path.GetFileName(filename); var changelogFilename = Path.GetFileName(filename);
if (changelogFilename == null) return null; if (changelogFilename == null) return null;
var currentChangelogPath = Path.Combine(Environment.CurrentDirectory, changelogFilename); var currentChangelogPath = Path.Combine(Environment.CurrentDirectory, changelogFilename);
if (File.Exists(currentChangelogPath)) if (File.Exists(currentChangelogPath))
{ {
return File.ReadAllText(currentChangelogPath); return File.ReadAllText(currentChangelogPath);
} }
} }
catch (Exception) catch (Exception)
{ {
// ignore; // ignore;
} }
}
}
return null; return null;
} }