Compare commits
3 Commits
64a2c35c0c
...
ff424c6c14
Author | SHA1 | Date | |
---|---|---|---|
ff424c6c14 | |||
45768d89a6 | |||
c4132b4061 |
@ -144,7 +144,7 @@ namespace KattekerCreator
|
|||||||
var pathToFile = Path.Combine(_tempDir, Constants.KattekerConfig);
|
var pathToFile = Path.Combine(_tempDir, Constants.KattekerConfig);
|
||||||
var kattekerConfig = new KattekerConfig
|
var kattekerConfig = new KattekerConfig
|
||||||
{
|
{
|
||||||
PublishDir = _appArguments.PublishDir ?? _appArguments.OutputDir,
|
Publish = _appArguments.PublishDir ?? _appArguments.OutputDir,
|
||||||
Changelog = _appArguments.ChangeLog
|
Changelog = _appArguments.ChangeLog
|
||||||
};
|
};
|
||||||
kattekerConfig.WriteToFile(pathToFile);
|
kattekerConfig.WriteToFile(pathToFile);
|
||||||
|
@ -8,11 +8,20 @@
|
|||||||
Title="MainWindow"
|
Title="MainWindow"
|
||||||
Width="800"
|
Width="800"
|
||||||
Height="450"
|
Height="450"
|
||||||
Background="Chartreuse"
|
Background="#E20074"
|
||||||
ContentRendered="MainWindow_OnContentRendered"
|
ContentRendered="MainWindow_OnContentRendered"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Button Margin="10" FontSize="24" Content="Update" Click="ButtonBase_OnClick"></Button>
|
<Button Margin="10" FontSize="24" Content="Update" Click="ButtonBase_OnClick"></Button>
|
||||||
<TextBlock Text=":-(" FontSize="60" HorizontalAlignment="Center" />
|
<TextBlock Margin="20" Text=":-)" FontSize="60" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5" >
|
||||||
|
<TextBlock.RenderTransform>
|
||||||
|
<TransformGroup>
|
||||||
|
<ScaleTransform/>
|
||||||
|
<SkewTransform/>
|
||||||
|
<RotateTransform Angle="90"/>
|
||||||
|
<TranslateTransform/>
|
||||||
|
</TransformGroup>
|
||||||
|
</TextBlock.RenderTransform>
|
||||||
|
</TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
@ -49,5 +49,5 @@ using System.Windows;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.48")]
|
[assembly: AssemblyVersion("1.0.53")]
|
||||||
[assembly: AssemblyFileVersion("1.0.48")]
|
[assembly: AssemblyFileVersion("1.0.53")]
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
<package id="CommonMark.NET" version="0.15.1" targetFramework="net45" />
|
|
||||||
</packages>
|
|
@ -5,8 +5,17 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Katteker
|
namespace Katteker
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Helps handle the Changelog.
|
||||||
|
/// </summary>
|
||||||
public static class ChangelogHelper
|
public static class ChangelogHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Format the Changelog as Html compilant file.s
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
/// <param name="extension"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static string ChangelogAsHtml(this string text, string extension)
|
public static string ChangelogAsHtml(this string text, string extension)
|
||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
@ -27,6 +36,12 @@ namespace Katteker
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Load changelog from Web or use the local file, if it fails.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static async Task<string> LoadChangelogAsync(string filename, string path)
|
public static async Task<string> LoadChangelogAsync(string filename, string path)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(filename) || !string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(filename) || !string.IsNullOrEmpty(path))
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
namespace Katteker
|
namespace Katteker
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A bunch of constants.
|
||||||
|
/// </summary>
|
||||||
public static class Constants
|
public static class Constants
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
<Compile Include="ReleaseEntry.cs" />
|
<Compile Include="ReleaseEntry.cs" />
|
||||||
<Compile Include="Releases.cs" />
|
<Compile Include="Releases.cs" />
|
||||||
<Compile Include="Utility.cs" />
|
<Compile Include="Utility.cs" />
|
||||||
<Compile Include="VersionExtension.cs" />
|
<Compile Include="VersionUtils.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -4,16 +4,31 @@ using System.Runtime.Serialization.Json;
|
|||||||
|
|
||||||
namespace Katteker
|
namespace Katteker
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration of a Katteker-Deployment
|
||||||
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class KattekerConfig
|
public class KattekerConfig
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Publish path
|
||||||
|
/// </summary>
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string PublishDir { get; set; }
|
public string Publish { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the changelog file.
|
||||||
|
/// </summary>
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Changelog { get; set; }
|
public string Changelog { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read file and deserialize content.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">path of the file.</param>
|
||||||
|
/// <returns>this object</returns>
|
||||||
|
/// <exception cref="FileNotFoundException"></exception>
|
||||||
public static KattekerConfig ReadFromFile(string path)
|
public static KattekerConfig ReadFromFile(string path)
|
||||||
{
|
{
|
||||||
if (!File.Exists(path)) throw new FileNotFoundException();
|
if (!File.Exists(path)) throw new FileNotFoundException();
|
||||||
@ -25,6 +40,10 @@ namespace Katteker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serialize object and write to file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">path of the file.</param>
|
||||||
public void WriteToFile(string path)
|
public void WriteToFile(string path)
|
||||||
{
|
{
|
||||||
if (File.Exists(path)) File.Delete(path);
|
if (File.Exists(path)) File.Delete(path);
|
||||||
|
@ -31,5 +31,5 @@ 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.3")]
|
[assembly: AssemblyVersion("1.0.4")]
|
||||||
[assembly: AssemblyFileVersion("1.0.3")]
|
[assembly: AssemblyFileVersion("1.0.4")]
|
||||||
|
@ -5,12 +5,18 @@ using Semver;
|
|||||||
|
|
||||||
namespace Katteker
|
namespace Katteker
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Entry of a Release.
|
||||||
|
/// </summary>
|
||||||
public class ReleaseEntry : IComparable<ReleaseEntry>, IComparable
|
public class ReleaseEntry : IComparable<ReleaseEntry>, IComparable
|
||||||
{
|
{
|
||||||
private const string FilenameRegex = @"(^.*)-((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?).*-(full|delta)";
|
private const string FilenameRegex = @"(^.*)-((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?).*-(full|delta)";
|
||||||
|
|
||||||
private const char Seperator = '|';
|
private const char Seperator = '|';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct a new release entry.
|
||||||
|
/// </summary>
|
||||||
public ReleaseEntry(string filename, SemVersion version, long fileSize, bool isDelta, string sha1)
|
public ReleaseEntry(string filename, SemVersion version, long fileSize, bool isDelta, string sha1)
|
||||||
{
|
{
|
||||||
Filename = filename;
|
Filename = filename;
|
||||||
@ -20,6 +26,10 @@ namespace Katteker
|
|||||||
SHA1 = sha1;
|
SHA1 = sha1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct release entry from string.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||||
public ReleaseEntry(string line)
|
public ReleaseEntry(string line)
|
||||||
{
|
{
|
||||||
var elements = line?.Split(Seperator);
|
var elements = line?.Split(Seperator);
|
||||||
@ -34,23 +44,53 @@ namespace Katteker
|
|||||||
IsDelta = fileSegments.Groups[3].Value != "full";
|
IsDelta = fileSegments.Groups[3].Value != "full";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// cunstruct release entry from application name and version.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationName"></param>
|
||||||
|
/// <param name="version"></param>
|
||||||
public ReleaseEntry(string applicationName, SemVersion version)
|
public ReleaseEntry(string applicationName, SemVersion version)
|
||||||
{
|
{
|
||||||
ApplicationName = applicationName;
|
ApplicationName = applicationName;
|
||||||
Version = version;
|
Version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Version
|
||||||
|
/// </summary>
|
||||||
public SemVersion Version { get; }
|
public SemVersion Version { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Hashsum of the file.
|
||||||
|
/// </summary>
|
||||||
public string SHA1 { get; }
|
public string SHA1 { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// filename
|
||||||
|
/// </summary>
|
||||||
public string Filename { get; }
|
public string Filename { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Size of the file.
|
||||||
|
/// </summary>
|
||||||
public long Filesize { get; }
|
public long Filesize { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Is true if the update is delta file. False otherwise.
|
||||||
|
/// </summary>
|
||||||
public bool IsDelta { get; }
|
public bool IsDelta { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the application.
|
||||||
|
/// </summary>
|
||||||
public string ApplicationName { get; }
|
public string ApplicationName { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Format the release entry as line for release file.
|
||||||
|
/// </summary>
|
||||||
public string EntryAsString => $"{SHA1}{Seperator}{Filename}{Seperator}{Filesize}";
|
public string EntryAsString => $"{SHA1}{Seperator}{Filename}{Seperator}{Filesize}";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override string ToString() => $"{ApplicationName} {Version}";
|
public override string ToString() => $"{ApplicationName} {Version}";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public int CompareTo(object obj) => CompareTo(obj as ReleaseEntry);
|
public int CompareTo(object obj) => CompareTo(obj as ReleaseEntry);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public int CompareTo(ReleaseEntry other)
|
public int CompareTo(ReleaseEntry other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(this, other)) return 0;
|
if (ReferenceEquals(this, other)) return 0;
|
||||||
@ -60,13 +100,20 @@ namespace Katteker
|
|||||||
return string.Compare(Filename, other.Filename, StringComparison.Ordinal);
|
return string.Compare(Filename, other.Filename, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override bool Equals(object obj) => Equals(obj as ReleaseEntry);
|
public override bool Equals(object obj) => Equals(obj as ReleaseEntry);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the instances are equal. False otherwise.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other"></param>
|
||||||
|
/// <returns></returns>
|
||||||
protected bool Equals(ReleaseEntry other)
|
protected bool Equals(ReleaseEntry other)
|
||||||
{
|
{
|
||||||
return Equals(Version, other.Version) && string.Equals(SHA1, other.SHA1) && string.Equals(Filename, other.Filename) && Filesize == other.Filesize && IsDelta == other.IsDelta;
|
return Equals(Version, other.Version) && string.Equals(SHA1, other.SHA1) && string.Equals(Filename, other.Filename) && Filesize == other.Filesize && IsDelta == other.IsDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
unchecked
|
unchecked
|
||||||
@ -80,14 +127,14 @@ namespace Katteker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(ReleaseEntry left, ReleaseEntry right)
|
/// <summary>
|
||||||
{
|
/// Returns true if the left and right instances are equal.
|
||||||
return Equals(left, right);
|
/// </summary>
|
||||||
}
|
public static bool operator ==(ReleaseEntry left, ReleaseEntry right) => Equals(left, right);
|
||||||
|
|
||||||
public static bool operator !=(ReleaseEntry left, ReleaseEntry right)
|
/// <summary>
|
||||||
{
|
/// Returns true if the left and right instances are not equal.
|
||||||
return !Equals(left, right);
|
/// </summary>
|
||||||
}
|
public static bool operator !=(ReleaseEntry left, ReleaseEntry right) => !Equals(left, right);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,6 +6,9 @@ using Semver;
|
|||||||
|
|
||||||
namespace Katteker
|
namespace Katteker
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class represents the release file which will published.
|
||||||
|
/// </summary>
|
||||||
public class Releases : IEnumerable<ReleaseEntry>
|
public class Releases : IEnumerable<ReleaseEntry>
|
||||||
{
|
{
|
||||||
private readonly string _filePath;
|
private readonly string _filePath;
|
||||||
@ -17,6 +20,9 @@ namespace Katteker
|
|||||||
ReleaseEntries = new SortedList<SemVersion, ReleaseEntry>();
|
ReleaseEntries = new SortedList<SemVersion, ReleaseEntry>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with the path as paramter.
|
||||||
|
/// </summary>
|
||||||
public Releases(string path) : this()
|
public Releases(string path) : this()
|
||||||
{
|
{
|
||||||
_filePath = Path.Combine(path, Constants.Release);
|
_filePath = Path.Combine(path, Constants.Release);
|
||||||
@ -24,6 +30,9 @@ namespace Katteker
|
|||||||
AddRange(File.ReadAllLines(_filePath));
|
AddRange(File.ReadAllLines(_filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with the enumerable content.
|
||||||
|
/// </summary>
|
||||||
public Releases(IEnumerable<string> content) : this()
|
public Releases(IEnumerable<string> content) : this()
|
||||||
{
|
{
|
||||||
AddRange(content);
|
AddRange(content);
|
||||||
@ -38,6 +47,9 @@ namespace Katteker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write release file to disk.
|
||||||
|
/// </summary>
|
||||||
public void WriteReleaseFile()
|
public void WriteReleaseFile()
|
||||||
{
|
{
|
||||||
File.WriteAllLines(_filePath, ReleaseEntries.Select(x => x.Value.EntryAsString));
|
File.WriteAllLines(_filePath, ReleaseEntries.Select(x => x.Value.EntryAsString));
|
||||||
@ -61,20 +73,23 @@ namespace Katteker
|
|||||||
{
|
{
|
||||||
ReleaseEntries.Remove(version);
|
ReleaseEntries.Remove(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReleaseEntries.Add(version, entry);
|
ReleaseEntries.Add(version, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is true if the entry is the last entry.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entry"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool IsLatestEntry(ReleaseEntry entry) => entry.Equals(ReleaseEntries.LastOrDefault().Value);
|
public bool IsLatestEntry(ReleaseEntry entry) => entry.Equals(ReleaseEntries.LastOrDefault().Value);
|
||||||
public IEnumerator<ReleaseEntry> GetEnumerator()
|
|
||||||
{
|
|
||||||
return ReleaseEntries.Values.GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
/// <inheritdoc />
|
||||||
{
|
public IEnumerator<ReleaseEntry> GetEnumerator() => ReleaseEntries.Values.GetEnumerator();
|
||||||
return GetEnumerator();
|
|
||||||
}
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,15 +2,27 @@
|
|||||||
|
|
||||||
namespace Katteker
|
namespace Katteker
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Info about the updates.
|
||||||
|
/// </summary>
|
||||||
public class UpdateInfo
|
public class UpdateInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Currently installed version.
|
||||||
|
/// </summary>
|
||||||
public ReleaseEntry CurrentlyInstalledVersion { get; }
|
public ReleaseEntry CurrentlyInstalledVersion { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases to apply.
|
||||||
|
/// </summary>
|
||||||
public List<ReleaseEntry> ReleasesToApply { get; } = new List<ReleaseEntry>();
|
public List<ReleaseEntry> ReleasesToApply { get; } = new List<ReleaseEntry>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
public UpdateInfo(string applicationName, Releases releases)
|
public UpdateInfo(string applicationName, Releases releases)
|
||||||
{
|
{
|
||||||
CurrentlyInstalledVersion = new ReleaseEntry(applicationName, VersionExtension.GetCurrentVersion);
|
CurrentlyInstalledVersion = new ReleaseEntry(applicationName, VersionUtils.GetCurrentVersion());
|
||||||
foreach (var release in releases)
|
foreach (var release in releases)
|
||||||
{
|
{
|
||||||
if (applicationName.Equals(release.ApplicationName) && release.Version > CurrentlyInstalledVersion.Version)
|
if (applicationName.Equals(release.ApplicationName) && release.Version > CurrentlyInstalledVersion.Version)
|
||||||
|
@ -53,7 +53,7 @@ namespace Katteker
|
|||||||
public static UpdateManager Create(string urlOrPath = null, string applicationName = null, string rootDirectory = null)
|
public static UpdateManager Create(string urlOrPath = null, string applicationName = null, string rootDirectory = null)
|
||||||
{
|
{
|
||||||
_config = ReadConfigFile();
|
_config = ReadConfigFile();
|
||||||
urlOrPath = urlOrPath ?? _config.PublishDir;
|
urlOrPath = urlOrPath ?? _config.Publish;
|
||||||
var appName = applicationName ?? Utility.GetApplicationName();
|
var appName = applicationName ?? Utility.GetApplicationName();
|
||||||
var rootAppDirectory = Path.Combine(rootDirectory ?? Utility.GetLocalAppDataDirectory(), appName);
|
var rootAppDirectory = Path.Combine(rootDirectory ?? Utility.GetLocalAppDataDirectory(), appName);
|
||||||
return new UpdateManager(urlOrPath, appName, rootAppDirectory);
|
return new UpdateManager(urlOrPath, appName, rootAppDirectory);
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
using Semver;
|
|
||||||
|
|
||||||
namespace Katteker
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for the App-Version.
|
|
||||||
/// </summary>
|
|
||||||
public static class VersionExtension
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Get the current Version of Application.
|
|
||||||
/// </summary>
|
|
||||||
public static SemVersion GetCurrentVersion
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var assemblyVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(3);
|
|
||||||
var getCurrentVersion = SemVersion.Parse(assemblyVersion);
|
|
||||||
var informalVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
|
||||||
if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion))
|
|
||||||
return semVersion;
|
|
||||||
return getCurrentVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert to cenventional System.Version instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Version ToSystemVersion(this SemVersion value) => new Version(value.Major, value.Minor, value.Patch, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the current Version of Application.
|
|
||||||
/// </summary>
|
|
||||||
public static string GetFullVersion => GetCurrentVersion.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
37
Katteker/VersionUtils.cs
Normal file
37
Katteker/VersionUtils.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using Semver;
|
||||||
|
|
||||||
|
namespace Katteker
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Utils for the App-Version.
|
||||||
|
/// </summary>
|
||||||
|
public static class VersionUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the current Version of Application.
|
||||||
|
/// </summary>
|
||||||
|
public static SemVersion GetCurrentVersion()
|
||||||
|
{
|
||||||
|
var assemblyVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(3);
|
||||||
|
var getCurrentVersion = SemVersion.Parse(assemblyVersion);
|
||||||
|
var informalVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
||||||
|
if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion))
|
||||||
|
return semVersion;
|
||||||
|
return getCurrentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the System.Version representation of a semantic version.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Version ToSystemVersion(this SemVersion value) => new Version(value.Major, value.Minor, value.Patch, 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the current Version of Application.
|
||||||
|
/// </summary>
|
||||||
|
public static string GetFullVersion => GetCurrentVersion().ToString();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user