Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.

Commit 3591453

Browse files
committed
add update checker (from Settings tab, Check Updates button), add prebuild event script to fetch latest release into PreviousVersion.txt file, fix missing status label
1 parent 43afba0 commit 3591453

File tree

5 files changed

+101
-10
lines changed

5 files changed

+101
-10
lines changed

Diff for: UnityLauncher/Form1.Designer.cs

+23-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: UnityLauncher/Form1.cs

+39-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Net;
9+
using System.Reflection;
910
using System.Text;
1011
using System.Text.RegularExpressions;
1112
using System.Windows.Forms;
@@ -17,8 +18,12 @@ public partial class Form1 : Form
1718
{
1819
public static Dictionary<string, string> unityList = new Dictionary<string, string>();
1920
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
20-
bool isDownloadUnityList = false;
2121
const string launcherArgumentsFile = "LauncherArguments.txt";
22+
const string githubReleaseCheckURL = "https://api.github.com/repos/unitycoder/unitylauncher/releases/latest";
23+
const string githubReleasesURL = "https://github.com/unitycoder/UnityLauncher/releases";
24+
25+
bool isDownloadUnityList = false;
26+
string previousGitRelease = null;
2227

2328

2429
public Form1()
@@ -91,6 +96,15 @@ void Start()
9196

9297
// subscribe to columnwidthchange event, so that can save column sizes
9398
this.gridRecent.ColumnWidthChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(this.gridRecent_ColumnWidthChanged);
99+
100+
101+
// get previous version build info string
102+
// this string is release tag for latest release when this app was compiled
103+
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UnityLauncher." + "PreviousVersion.txt"))
104+
using (StreamReader reader = new StreamReader(stream))
105+
{
106+
previousGitRelease = reader.ReadToEnd().Trim();
107+
}
94108
}
95109

96110
void LoadSettings()
@@ -952,6 +966,11 @@ private void gridRecent_CellEndEdit(object sender, DataGridViewCellEventArgs e)
952966
// gridRecent.Rows[previousRow].Selected = true;
953967
}
954968

969+
private void btnCheckUpdates_Click(object sender, EventArgs e)
970+
{
971+
CheckUpdates();
972+
}
973+
955974
#endregion UI events
956975

957976
// displays version selector to upgrade project
@@ -1068,5 +1087,23 @@ string GetSelectedRowData(string key)
10681087
}
10691088
return path;
10701089
}
1090+
1091+
void CheckUpdates()
1092+
{
1093+
var result = Tools.CheckUpdates(githubReleaseCheckURL, previousGitRelease);
1094+
if (string.IsNullOrEmpty(result) == false)
1095+
{
1096+
SetStatus("Update available: " + result);
1097+
DialogResult dialogResult = MessageBox.Show("Update " + result + " is available, open download page?", "UnityLauncher - Check Update", MessageBoxButtons.YesNo);
1098+
if (dialogResult == DialogResult.Yes) // open download page
1099+
{
1100+
Tools.OpenURL(githubReleasesURL);
1101+
}
1102+
}
1103+
else
1104+
{
1105+
SetStatus("No updates available..");
1106+
}
1107+
}
10711108
}
1072-
}
1109+
}

Diff for: UnityLauncher/PreviousVersion.txt

14 Bytes
Binary file not shown.

Diff for: UnityLauncher/Tools.cs

+35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.IO;
66
using System.Linq;
7+
using System.Net;
78
using System.Text;
89
using System.Text.RegularExpressions;
910
using System.Threading.Tasks;
@@ -324,5 +325,39 @@ public static bool LaunchExplorer(string folder)
324325
return result;
325326
}
326327

328+
public static string CheckUpdates(string githubReleaseURL, string previousGitRelease)
329+
{
330+
string result = null;
331+
using (WebClient client = new WebClient())
332+
{
333+
client.Headers.Add("user-agent", "MuskBrowser");
334+
string json = client.DownloadString(githubReleaseURL);
335+
var arr = json.Split(new string[] { "\"tag_name\":" }, StringSplitOptions.None);
336+
337+
// have tagname
338+
if (arr.Length > 1)
339+
{
340+
var arr2 = arr[1].Trim().Split('"');
341+
// have "
342+
if (arr2.Length > 1)
343+
{
344+
var currentlyAvailableLatestReleaseTag = arr2[1];
345+
// compare with this build release version
346+
if (currentlyAvailableLatestReleaseTag != previousGitRelease)
347+
{
348+
result = currentlyAvailableLatestReleaseTag;
349+
Console.WriteLine("update available: [" + currentlyAvailableLatestReleaseTag + "] / [" + previousGitRelease + "]");
350+
}
351+
else
352+
{
353+
Console.WriteLine("no update available: [" + currentlyAvailableLatestReleaseTag + "] / [" + previousGitRelease + "]");
354+
}
355+
}
356+
}
357+
}
358+
return result;
359+
}
360+
361+
327362
}
328363
}

Diff for: UnityLauncher/UnityLauncher.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@
127127
</BootstrapperPackage>
128128
</ItemGroup>
129129
<ItemGroup>
130+
<EmbeddedResource Include="PreviousVersion.txt" />
130131
<Content Include="unitylauncher.ico" />
131132
</ItemGroup>
132133
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
134+
<PropertyGroup>
135+
<PreBuildEvent>powershell.exe -command "$web = New-Object System.Net.WebClient;$web.Headers['User-Agent'] = 'DefinitelyBrowser';$results = $web.DownloadString('https://api.github.com/repos/unitycoder/unitylauncher/releases/latest');$results = $results | ConvertFrom-Json;$results = $results | select -expand tag_name;echo $results | Out-File $(ProjectDir)PreviousVersion.txt;"</PreBuildEvent>
136+
</PropertyGroup>
133137
</Project>

0 commit comments

Comments
 (0)