@@ -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}
0 commit comments