Skip to content

Commit ace7ee6

Browse files
committed
Allow checking for update
1 parent fe10b94 commit ace7ee6

4 files changed

Lines changed: 222 additions & 14 deletions

File tree

app/Project Tracker/Project Tracker/MainWindow.xaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<Label x:Name="versionLabel" Content="" HorizontalAlignment="Left" Margin="60,69,0,0" VerticalAlignment="Top" Foreground="#FFB8B8B8" FontSize="14" />
7878
</Grid>
7979
</Border>
80-
80+
8181
<!-- We need this to be 10 from each side in the code -->
8282
<Border HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="0" CornerRadius="4,4,4,4" BorderBrush="Black" Background="#FF9B9B9B" Width="325" Height="4" Margin="10,98,0,0" />
8383

@@ -299,6 +299,20 @@
299299
</Grid>
300300
</ScrollViewer>
301301
</Grid>
302+
303+
<!-- The settings menu -->
304+
<Grid x:Name="settingsGrid" Margin="350,100,0,0" Visibility="Hidden">
305+
<Button x:Name="updateButton1" Content="Check for an update" HorizontalAlignment="Left" Margin="20,25,0,0" VerticalAlignment="Top" Width="210" Height="48" Cursor="Hand" FontSize="20" PreviewMouseDown="UpdateButtonMouseDown"/>
306+
<Label x:Name="currentVersionLabel" Content="Installed version: " HorizontalAlignment="Left" Margin="20,78,0,0" VerticalAlignment="Top" FontSize="16"/>
307+
<Label x:Name="latestVersionLabel" Content="Latest version: unavailable" HorizontalAlignment="Left" Margin="20,109,0,0" VerticalAlignment="Top" FontSize="16"/>
308+
<Label Content="Next version details" HorizontalAlignment="Left" Margin="20,300,0,0" VerticalAlignment="Top" FontSize="36"/>
309+
<Label x:Name="nextVersionLabel" Content="Downloading next version information..." HorizontalAlignment="Left" Margin="20,358,0,0" VerticalAlignment="Top" FontSize="24"/>
310+
<Label x:Name="nextVersionReleaseLabel" Visibility="Hidden" Content="Release date: " HorizontalAlignment="Left" Margin="20,400,0,0" VerticalAlignment="Top" FontSize="24"/>
311+
<Label x:Name="nextVersionFeaturesLabel" Visibility="Hidden" Content="Features:" HorizontalAlignment="Left" Margin="20,460,0,0" VerticalAlignment="Top" FontSize="30"/>
312+
<Label x:Name="nextVersionUpdateOneLabel" Visibility="Hidden" Content="1. " HorizontalAlignment="Left" Margin="20,510,0,0" VerticalAlignment="Top" FontSize="24"/>
313+
<Label x:Name="nextVersionUpdateTwoLabel" Visibility="Hidden" Content="2. " HorizontalAlignment="Left" Margin="20,552,0,0" VerticalAlignment="Top" FontSize="24"/>
314+
<Label x:Name="nextVersionUpdateThreeLabel" Visibility="Hidden" Content="3. " HorizontalAlignment="Left" Margin="20,594,0,0" VerticalAlignment="Top" FontSize="24"/>
315+
</Grid>
302316

303317
<!-- Incomplete vs complete grid -->
304318
<Grid x:Name="completeGrid" Margin="391,136,0,0" Visibility="Hidden">

app/Project Tracker/Project Tracker/MainWindow.xaml.cs

Lines changed: 188 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Net;
77
using System.Text;
88
using System.Threading;
9+
using System.Threading.Tasks;
910
using System.Windows;
1011
using System.Windows.Controls;
1112
using System.Windows.Input;
@@ -47,6 +48,12 @@ public partial class MainWindow : UWPHost.Window {
4748
private readonly string VERSION_MANIFEST_URL =
4849
"https://raw.githubusercontent.com/CyanCoding/Project-Tracker/master/install-resources/version.json";
4950

51+
private readonly string NEXT_VERSION_MANIFEST_URL =
52+
"https://raw.githubusercontent.com/CyanCoding/Project-Tracker/cyancoding-settings-branch/install-resources/next-version.json";
53+
54+
private readonly string NEXT_VERSION_INFO = Environment.GetFolderPath
55+
(Environment.SpecialFolder.LocalApplicationData) + "/Project Tracker/next-version.json";
56+
5057
private int addingType = 0;
5158
private string duration;
5259
private string icon;
@@ -60,6 +67,7 @@ public partial class MainWindow : UWPHost.Window {
6067
private bool isSettingsWindowDisplaying = false;
6168
private int itemIndex = 0;
6269
private int itemsAdded = 0;
70+
private bool updateResponse = false;
6371
// The amount of items added to the scrollviewer
6472
private string percent;
6573

@@ -1212,6 +1220,8 @@ private void SetSelectedProject() {
12121220
isSettingsWindowDisplaying = false;
12131221
}
12141222

1223+
settingsGrid.Visibility = Visibility.Hidden;
1224+
12151225
border1.Style = (Style)TryFindResource("hoverOver");
12161226
border2.Style = (Style)TryFindResource("hoverOver");
12171227
border3.Style = (Style)TryFindResource("hoverOver");
@@ -1359,7 +1369,7 @@ private void SetSelectedProject() {
13591369
}
13601370
}
13611371
else if (!isSettingsWindowDisplaying) { // There's no projects
1362-
// Hide all items
1372+
// Hide all items
13631373
displayingTitle.Visibility = Visibility.Hidden;
13641374
displayingImage.Visibility = Visibility.Hidden;
13651375
settingsImage.Visibility = Visibility.Hidden;
@@ -1445,8 +1455,6 @@ private void settingsImage_PreviewMouseDown(object sender, MouseButtonEventArgs
14451455
/// Startup function that runs when code execution starts.
14461456
/// </summary>
14471457
private void Startup() {
1448-
// Item positioning
1449-
14501458
if (!Directory.Exists(APPDATA_DIRECTORY)) { // Create AppData directory
14511459
Directory.CreateDirectory(APPDATA_DIRECTORY);
14521460
}
@@ -1514,16 +1522,27 @@ private void Startup() {
15141522
if (File.Exists(VERSION_INFO)) {
15151523
File.Delete(VERSION_INFO);
15161524
}
1517-
1518-
// Download latest version information
1519-
try {
1520-
WebClient client = new WebClient();
1521-
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Update);
1522-
client.DownloadFileAsync(new Uri(VERSION_MANIFEST_URL), VERSION_INFO);
1523-
}
1524-
catch (WebException) {
1525-
// Couldn't download update file. Possible their wifi isn't working
1525+
if (File.Exists(NEXT_VERSION_INFO)) {
1526+
File.Delete(NEXT_VERSION_INFO);
15261527
}
1528+
1529+
Thread thread = new Thread(() =>
1530+
{
1531+
Dispatcher.Invoke(new Action(() =>
1532+
{
1533+
// Download latest version information
1534+
try {
1535+
WebClient client = new WebClient();
1536+
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Update);
1537+
client.DownloadFileAsync(new Uri(VERSION_MANIFEST_URL), VERSION_INFO);
1538+
}
1539+
catch (WebException) {
1540+
// Couldn't download update file. Possible their wifi isn't working
1541+
}
1542+
}));
1543+
});
1544+
thread.Start();
1545+
15271546
}
15281547

15291548
/// <summary>
@@ -1619,15 +1638,50 @@ private void TypeImagePressed(object sender, MouseButtonEventArgs e) {
16191638
/// Notifies the user of an update if one is available.
16201639
/// </summary>
16211640
private void Update(object sender, AsyncCompletedEventArgs e) {
1641+
// Download future version information
1642+
try {
1643+
WebClient client = new WebClient();
1644+
client.DownloadFileCompleted += new AsyncCompletedEventHandler(NextVersionDownloadComplete);
1645+
client.DownloadFileAsync(new Uri(NEXT_VERSION_MANIFEST_URL), NEXT_VERSION_INFO);
1646+
}
1647+
catch (WebException) {
1648+
// Couldn't download update file. Possible their wifi isn't working
1649+
nextVersionLabel.Content = "Couldn't get next release data.";
1650+
latestVersionLabel.Content = "Latest version: unavailable";
1651+
nextVersionReleaseLabel.Visibility = Visibility.Hidden;
1652+
nextVersionFeaturesLabel.Visibility = Visibility.Hidden;
1653+
nextVersionUpdateOneLabel.Visibility = Visibility.Hidden;
1654+
nextVersionUpdateTwoLabel.Visibility = Visibility.Hidden;
1655+
nextVersionUpdateThreeLabel.Visibility = Visibility.Hidden;
1656+
updateResponse = true;
1657+
}
1658+
16221659
string json = File.ReadAllText(VERSION_INFO);
16231660

1661+
if (json == "" && isSettingsWindowDisplaying) { // Didn't download the entire file properly
1662+
System.Windows.Forms.MessageBox.Show("Please connect to the Internet to check for an update.",
1663+
"No Internet Connection",
1664+
System.Windows.Forms.MessageBoxButtons.OK,
1665+
System.Windows.Forms.MessageBoxIcon.Error);
1666+
updateResponse = true;
1667+
latestVersionLabel.Content = "Latest version: unavailable";
1668+
return;
1669+
}
1670+
else if (json == "") {
1671+
nextVersionLabel.Content = "Couldn't get next release data.";
1672+
updateResponse = true;
1673+
return;
1674+
}
1675+
16241676
UpdateManifest.Rootobject update =
16251677
JsonConvert.DeserializeObject<UpdateManifest.Rootobject>(json);
16261678

1679+
latestVersionLabel.Visibility = Visibility.Visible;
1680+
latestVersionLabel.Content = "Latest version: " + update.Version;
1681+
16271682
if (float.Parse(CURRENT_VERSION) < float.Parse(update.Version)) { // Update is available
16281683
Thread thread = new Thread(() =>
16291684
{
1630-
Thread.Sleep(5000);
16311685
Dispatcher.Invoke(new Action(() =>
16321686
{
16331687
updateGrid.Visibility = Visibility.Visible;
@@ -1641,9 +1695,76 @@ private void Update(object sender, AsyncCompletedEventArgs e) {
16411695
}));
16421696
});
16431697
thread.Start();
1698+
updateResponse = true;
1699+
}
1700+
else if (isSettingsWindowDisplaying) {
1701+
System.Windows.Forms.MessageBox.Show("You're running the latest version of the Project Tracker!",
1702+
"No New Update",
1703+
System.Windows.Forms.MessageBoxButtons.OK,
1704+
System.Windows.Forms.MessageBoxIcon.Information);
1705+
updateResponse = true;
16441706
}
16451707
}
16461708

1709+
/// <summary>
1710+
/// Runs when the next version file has been downloaded.
1711+
/// Sets the next update info in the settings.
1712+
/// </summary>
1713+
private void NextVersionDownloadComplete(object sender, AsyncCompletedEventArgs e) {
1714+
string json = File.ReadAllText(NEXT_VERSION_INFO);
1715+
1716+
if (json == "" && isSettingsWindowDisplaying) { // Didn't download the entire file properly
1717+
// Couldn't download update file. Possible their wifi isn't working
1718+
nextVersionLabel.Content = "Couldn't get next release data.";
1719+
latestVersionLabel.Content = "Latest version: unavailable";
1720+
nextVersionReleaseLabel.Visibility = Visibility.Hidden;
1721+
nextVersionFeaturesLabel.Visibility = Visibility.Hidden;
1722+
nextVersionUpdateOneLabel.Visibility = Visibility.Hidden;
1723+
nextVersionUpdateTwoLabel.Visibility = Visibility.Hidden;
1724+
nextVersionUpdateThreeLabel.Visibility = Visibility.Hidden;
1725+
updateResponse = true;
1726+
return;
1727+
}
1728+
else if (json == "") {
1729+
updateResponse = true;
1730+
return;
1731+
}
1732+
1733+
NextVersionManifest.Rootobject nextVersionInfo =
1734+
JsonConvert.DeserializeObject<NextVersionManifest.Rootobject>(json);
1735+
nextVersionLabel.Visibility = Visibility.Visible;
1736+
nextVersionLabel.Content = "Version: " + nextVersionInfo.Version;
1737+
1738+
nextVersionReleaseLabel.Visibility = Visibility.Visible;
1739+
if (nextVersionInfo.ReleaseDateConfirmed == "false") {
1740+
nextVersionReleaseLabel.Content = "Estimated release date: " + nextVersionInfo.EstimatedRelease;
1741+
}
1742+
else {
1743+
nextVersionReleaseLabel.Content = "Release date: " + nextVersionInfo.EstimatedRelease;
1744+
}
1745+
1746+
nextVersionUpdateOneLabel.Visibility = Visibility.Visible;
1747+
nextVersionUpdateTwoLabel.Visibility = Visibility.Hidden;
1748+
nextVersionUpdateThreeLabel.Visibility = Visibility.Hidden;
1749+
1750+
if (nextVersionInfo.NewFeatures[0] == "") {
1751+
nextVersionUpdateOneLabel.Content = "Feature list coming soon...";
1752+
}
1753+
else {
1754+
nextVersionUpdateOneLabel.Content = "1. " + nextVersionInfo.NewFeatures[0];
1755+
}
1756+
1757+
if (nextVersionInfo.NewFeatures[1] != "") {
1758+
nextVersionUpdateTwoLabel.Visibility = Visibility.Visible;
1759+
nextVersionUpdateTwoLabel.Content = "2. " + nextVersionInfo.NewFeatures[1];
1760+
}
1761+
1762+
if (nextVersionInfo.NewFeatures[2] != "") {
1763+
nextVersionUpdateThreeLabel.Visibility = Visibility.Visible;
1764+
nextVersionUpdateThreeLabel.Content = "3. " + nextVersionInfo.NewFeatures[2];
1765+
}
1766+
updateResponse = true;
1767+
}
16471768
/// <summary>
16481769
/// Runs when the user presses the update button when an update is available.
16491770
/// </summary>
@@ -2024,9 +2145,63 @@ private void SettingsButtonMouseDown(object sender, MouseButtonEventArgs e) {
20242145
// Set values
20252146
displayingImage.Source = (ImageSource)TryFindResource("settingsDrawingImage");
20262147
displayingTitle.Content = "Settings";
2148+
currentVersionLabel.Content = "Installed version: " + CURRENT_VERSION;
2149+
20272150
isSettingsWindowDisplaying = true;
20282151
selectedIndex = 0;
20292152
SetSelectedProject();
2153+
settingsGrid.Visibility = Visibility.Visible;
2154+
2155+
}
2156+
2157+
private void UpdateButtonMouseDown(object sender, MouseButtonEventArgs e) {
2158+
updateButton1.IsEnabled = false;
2159+
2160+
if (File.Exists(VERSION_INFO)) {
2161+
File.Delete(VERSION_INFO);
2162+
}
2163+
if (File.Exists(NEXT_VERSION_INFO)) {
2164+
File.Delete(NEXT_VERSION_INFO);
2165+
}
2166+
2167+
DisableUpdateButton();
2168+
// Download latest version information
2169+
try {
2170+
updateButton1.IsEnabled = false;
2171+
updateResponse = false;
2172+
2173+
WebClient updateClient = new WebClient();
2174+
updateClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Update);
2175+
updateClient.DownloadFileAsync(new Uri(VERSION_MANIFEST_URL), VERSION_INFO);
2176+
}
2177+
catch (WebException) {
2178+
// Couldn't download update file. Possible their wifi isn't working
2179+
updateResponse = true;
2180+
}
2181+
}
2182+
2183+
2184+
/// <summary>
2185+
/// Waits for 15 seconds before allowing the user to check for an update again.
2186+
/// </summary>
2187+
/// <returns></returns>
2188+
private async Task DisableUpdateButton() {
2189+
for (int i = 15; i >= 0; i--) {
2190+
updateButton1.Content = i.ToString();
2191+
await Task.Delay(1000);
2192+
}
2193+
if (updateResponse) {
2194+
updateButton1.Content = "Check for an update";
2195+
updateButton1.IsEnabled = true;
2196+
}
2197+
else {
2198+
updateButton1.Content = "Please wait...";
2199+
while (!updateResponse) {
2200+
await Task.Delay(1000);
2201+
}
2202+
updateButton1.Content = "Check for an update";
2203+
updateButton1.IsEnabled = true;
2204+
}
20302205
}
20312206
}
20322207
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Project_Tracker {
8+
class NextVersionManifest {
9+
10+
public class Rootobject {
11+
public string Version { get; set; }
12+
public string EstimatedRelease { get; set; }
13+
public string ReleaseDateConfirmed { get; set; }
14+
public string[] NewFeatures { get; set; }
15+
}
16+
17+
}
18+
}

app/Project Tracker/Project Tracker/Project Tracker.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<Generator>MSBuild:Compile</Generator>
7171
<SubType>Designer</SubType>
7272
</ApplicationDefinition>
73+
<Compile Include="NextVersionManifest.cs" />
7374
<Compile Include="SettingsManifest.cs" />
7475
<Compile Include="UpdateManifest.cs" />
7576
<Compile Include="UpdateWindow.xaml.cs">

0 commit comments

Comments
 (0)