Skip to content

Commit

Permalink
version number is now stored in extra file, created automatic release…
Browse files Browse the repository at this point in the history
… zip creation script
  • Loading branch information
fabsenet committed Mar 30, 2017
1 parent 9005c72 commit 264ea9b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
20 changes: 10 additions & 10 deletions adrilight/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
using Newtonsoft.Json.Linq;
using NLog;
using Semver;
using System.Reflection;
using System.IO;

namespace adrilight {

public partial class MainForm : Form
{
private const string CURRENT_VERSION = "0.1.4";

private readonly ILogger _log = LogManager.GetCurrentClassLogger();

private NotifyIcon _mNotifyIcon;
Expand All @@ -31,6 +31,8 @@ public partial class MainForm : Form
public MainForm() {
_log.Debug("Creating Mainform");
InitializeComponent();
Text += " " + Program.VersionNumber;

InitTrayIcon();

Application.ApplicationExit += OnApplicationExit;
Expand All @@ -46,23 +48,21 @@ private void StartVersionCheck()
{
try
{
var currentVersion = SemVersion.Parse(CURRENT_VERSION);

dynamic latestRelease = TryGetLatestReleaseData().Result;
if (latestRelease == null) return;

string tagName = latestRelease.tag_name;
var latestVersionNumber = SemVersion.Parse(tagName.TrimStart('v','V'));
var latestVersionNumber = SemVersion.Parse(tagName.TrimStart('v', 'V'));

if (latestVersionNumber > currentVersion)
if (latestVersionNumber > Program.VersionNumber)
{
Invoke((MethodInvoker) delegate
Invoke((MethodInvoker)delegate
{
var url = latestRelease.html_url as string;
var shouldOpenUrl = MessageBox.Show($"New version of adrilight is available! The new version is {latestVersionNumber} (you are running {currentVersion}). Press OK to open the download page."
, "New Adrilight Version!", MessageBoxButtons.OKCancel) == DialogResult.OK;
var shouldOpenUrl = MessageBox.Show($"New version of adrilight is available! The new version is {latestVersionNumber} (you are running {Program.VersionNumber}). Press OK to open the download page."
, "New Adrilight Version!", MessageBoxButtons.OKCancel) == DialogResult.OK;

if (url!=null && shouldOpenUrl)
if (url != null && shouldOpenUrl)
{
Process.Start(url);
}
Expand Down
19 changes: 17 additions & 2 deletions adrilight/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using NLog;
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
Expand All @@ -16,7 +18,7 @@ static class Program {
[STAThread]
static void Main()
{
_log.Debug("Main() started.");
_log.Debug($"adrilight {VersionNumber}: Main() started.");

Settings.Refresh();

Expand All @@ -32,7 +34,7 @@ static void Main()

private static void ApplicationOnThreadException(object sender, Exception ex)
{
_log.Fatal(ex, $"ApplicationOnThreadException from sender={sender}");
_log.Fatal(ex, $"ApplicationOnThreadException from sender={sender}, adrilight version={VersionNumber}");

var sb = new StringBuilder();
sb.AppendLine($"Sender: {sender}");
Expand All @@ -53,5 +55,18 @@ private static void ApplicationOnThreadException(object sender, Exception ex)
MessageBox.Show(sb.ToString(), "unhandled exception :-(");
Application.Exit();
}

public static string VersionNumber { get; } = GetVersionNumber();

private static string GetVersionNumber()
{
var assembly = Assembly.GetExecutingAssembly();
string currentVersion;
using (var versionStream = assembly.GetManifestResourceStream("adrilight.version.txt"))
{
currentVersion = new StreamReader(versionStream).ReadToEnd().Trim();
}
return currentVersion;
}
}
}
3 changes: 3 additions & 0 deletions adrilight/adrilight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<EmbeddedResource Include="Overlay.resx">
<DependentUpon>Overlay.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="..\version.txt">
<Link>version.txt</Link>
</EmbeddedResource>
<Content Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
3 changes: 3 additions & 0 deletions create_release.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
powershell -ExecutionPolicy RemoteSigned -File create_release.ps1

pause
27 changes: 27 additions & 0 deletions create_release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$version = gc .\version.txt

del ".\Release\adrilight_$version.zip" -Force -ErrorAction SilentlyContinue
rm ".\Release\adrilight_$version" -Force -Recurse -ErrorAction SilentlyContinue
md ".\Release\adrilight_$version\PC" -Force

#find msbuild
$_decSep = [System.Threading.Thread]::CurrentThread.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator;
$msbuild = $(Get-ChildItem -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSBuild\ToolsVersions\" |
Where { $_.Name -match '\\\d+.\d+$' } |
Sort-Object -property @{Expression={[System.Convert]::ToDecimal($_.Name.Substring($_.Name.LastIndexOf("\") + 1).Replace(".",$_decSep).Replace(",",$_decSep))}} -Descending |
Select-Object -First 1).GetValue("MSBuildToolsPath") + "msbuild.exe"

if((Test-Path -Path $msbuild) -eq $false) {Write-Error "failed to find msbuild file"; exit}

& $msbuild /m .\adrilight.sln /t:Clean /p:Configuration=Release
& $msbuild /m .\adrilight.sln /t:Rebuild /p:Configuration=Release

dir Arduino -Recurse | Copy -Destination ".\Release\adrilight_$version\Arduino\"
dir .\adrilight\bin\Release -Exclude "*.pdb","*vshost*","logs" | Copy -Destination ".\Release\adrilight_$version\PC\"

Compress-Archive -Path ".\Release\adrilight_$version\*" -DestinationPath ".\Release\adrilight_$version.zip" -Force -CompressionLevel Optimal

write-host
Write-Host "adrilight_$version.zip created!" -ForegroundColor Green
Write-Host "full path:" -ForegroundColor Gray
Write-Host (dir ".\Release\adrilight_$version.zip").FullName -ForegroundColor Yellow
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.4

0 comments on commit 264ea9b

Please sign in to comment.