Skip to content

Commit ed5acb1

Browse files
committed
Added version checker
1 parent f780a1d commit ed5acb1

File tree

5 files changed

+148
-43
lines changed

5 files changed

+148
-43
lines changed

LightroomSync/Config.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ internal class Config
1212
public string LocalFolder { get; set; }
1313
public string NetworkFolder { get; set; }
1414

15+
public bool AutoCheckForUpdates { get; set; }
16+
1517
public Config() {
1618
this.LocalFolder = "C:\\Users\\" + System.Environment.UserName + "\\Pictures\\Lightroom";
1719
this.NetworkFolder = "P:\\Lightroom";
20+
this.AutoCheckForUpdates = true;
1821
}
1922

2023
public string ToJson()

LightroomSync/Form1.Designer.cs

Lines changed: 56 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LightroomSync/Form1.cs

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace LightroomSync
1616
{
1717
public partial class Form1 : Form
1818
{
19+
public string currentVersion = "1.0.0"; // <----- Make sure you always update latestVersion.txt as well!
20+
// Yes, I'm too lazy to pipe this in.
21+
1922
private Config config = new Config();
2023
private Status status = new Status();
2124

@@ -342,6 +345,12 @@ private void Form1_Load(object sender, EventArgs e)
342345
{
343346
launchAtStartupToolStripMenuItem.Image = Resources.checkmark;
344347
}
348+
349+
if (config.AutoCheckForUpdates)
350+
{
351+
autoCheckForUpdatesToolStripMenuItem.Image = Resources.checkmark;
352+
CheckForUpdates(true);
353+
}
345354
}
346355

347356
private void button1_Click(object sender, EventArgs e)
@@ -585,26 +594,57 @@ await Task.Run(() =>
585594
}
586595
}
587596

588-
private void submitABugToolStripMenuItem_Click(object sender, EventArgs e)
597+
private async void CheckForUpdates(bool silently)
589598
{
590-
string url = "https://github.com/software-2/LightroomSync/issues";
591-
ProcessStartInfo startInfo = new ProcessStartInfo
599+
string version = "ERR NOT SET";
600+
601+
using (HttpClient client = new HttpClient())
592602
{
593-
FileName = url,
594-
UseShellExecute = true
595-
};
596-
Process.Start(startInfo);
603+
try
604+
{
605+
version = await client.GetStringAsync("https://github.com/software-2/LightroomSync/raw/master/latestversion.txt");
606+
}
607+
catch (Exception ex)
608+
{
609+
Log($"Error checking for new version: {ex.Message}");
610+
if (silently)
611+
{
612+
return;
613+
}
614+
var result = MessageBox.Show("Sorry, I couldn't find the version number. Do you want to go to the website to check?", "Error!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
615+
if (result == DialogResult.Yes)
616+
{
617+
Utils.OpenURL("https://github.com/software-2/LightroomSync/releases");
618+
}
619+
return;
620+
}
621+
}
622+
623+
var parsed = Version.Parse(version);
624+
625+
if (parsed.CompareTo(currentVersion) != 0)
626+
{
627+
var dialog = "There is a new version! Want to go get it?" + Environment.NewLine + Environment.NewLine + "New Version: " + parsed.ToString() + Environment.NewLine + "Your Version: " + currentVersion.ToString();
628+
var result = MessageBox.Show(dialog, "New Version!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
629+
if (result == DialogResult.Yes)
630+
{
631+
Utils.OpenURL("https://github.com/software-2/LightroomSync/releases");
632+
}
633+
}
634+
else if (!silently)
635+
{
636+
MessageBox.Show("You expected an update, but it was me! Dio!", "Up To Date!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
637+
}
638+
}
639+
640+
private void submitABugToolStripMenuItem_Click(object sender, EventArgs e)
641+
{
642+
Utils.OpenURL("https://github.com/software-2/LightroomSync/issues");
597643
}
598644

599645
private void gitHubPageToolStripMenuItem_Click(object sender, EventArgs e)
600646
{
601-
string url = "https://github.com/software-2/LightroomSync";
602-
ProcessStartInfo startInfo = new ProcessStartInfo
603-
{
604-
FileName = url,
605-
UseShellExecute = true
606-
};
607-
Process.Start(startInfo);
647+
Utils.OpenURL("https://github.com/software-2/LightroomSync");
608648
}
609649

610650
private void minimizeToTrayToolStripMenuItem_Click(object sender, EventArgs e)
@@ -635,5 +675,28 @@ private void launchAtStartupToolStripMenuItem_Click(object sender, EventArgs e)
635675
Utils.CreateShortcutInStartupFolder(appPath);
636676
}
637677
}
678+
679+
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
680+
{
681+
MessageBox.Show("LightroomSync" + Environment.NewLine + "Copyright 2023 Anthony Bryan" + Environment.NewLine + Environment.NewLine + "Version " + currentVersion);
682+
}
683+
684+
private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
685+
{
686+
CheckForUpdates(false);
687+
}
688+
689+
private void autoCheckForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
690+
{
691+
config.AutoCheckForUpdates = !config.AutoCheckForUpdates;
692+
if (config.AutoCheckForUpdates)
693+
{
694+
autoCheckForUpdatesToolStripMenuItem.Image = Resources.checkmark;
695+
}
696+
else
697+
{
698+
autoCheckForUpdatesToolStripMenuItem.Image = null;
699+
}
700+
}
638701
}
639702
}

LightroomSync/Utils.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.IO;
8+
using System.Diagnostics;
89

910
namespace LightroomSync
1011
{
@@ -44,5 +45,15 @@ public static string GetWorkingDir()
4445
{
4546
return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\LightroomSync";
4647
}
48+
49+
public static void OpenURL(string url)
50+
{
51+
ProcessStartInfo startInfo = new ProcessStartInfo
52+
{
53+
FileName = url,
54+
UseShellExecute = true
55+
};
56+
Process.Start(startInfo);
57+
}
4758
}
4859
}

latestVersion.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

0 commit comments

Comments
 (0)