Skip to content

Commit

Permalink
Added version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
software-2 committed May 24, 2023
1 parent f780a1d commit ed5acb1
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 43 deletions.
3 changes: 3 additions & 0 deletions LightroomSync/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ internal class Config
public string LocalFolder { get; set; }
public string NetworkFolder { get; set; }

public bool AutoCheckForUpdates { get; set; }

public Config() {
this.LocalFolder = "C:\\Users\\" + System.Environment.UserName + "\\Pictures\\Lightroom";
this.NetworkFolder = "P:\\Lightroom";
this.AutoCheckForUpdates = true;
}

public string ToJson()
Expand Down
85 changes: 56 additions & 29 deletions LightroomSync/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 77 additions & 14 deletions LightroomSync/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace LightroomSync
{
public partial class Form1 : Form
{
public string currentVersion = "1.0.0"; // <----- Make sure you always update latestVersion.txt as well!
// Yes, I'm too lazy to pipe this in.

private Config config = new Config();
private Status status = new Status();

Expand Down Expand Up @@ -342,6 +345,12 @@ private void Form1_Load(object sender, EventArgs e)
{
launchAtStartupToolStripMenuItem.Image = Resources.checkmark;
}

if (config.AutoCheckForUpdates)
{
autoCheckForUpdatesToolStripMenuItem.Image = Resources.checkmark;
CheckForUpdates(true);
}
}

private void button1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -585,26 +594,57 @@ await Task.Run(() =>
}
}

private void submitABugToolStripMenuItem_Click(object sender, EventArgs e)
private async void CheckForUpdates(bool silently)
{
string url = "https://github.com/software-2/LightroomSync/issues";
ProcessStartInfo startInfo = new ProcessStartInfo
string version = "ERR NOT SET";

using (HttpClient client = new HttpClient())
{
FileName = url,
UseShellExecute = true
};
Process.Start(startInfo);
try
{
version = await client.GetStringAsync("https://github.com/software-2/LightroomSync/raw/master/latestversion.txt");
}
catch (Exception ex)
{
Log($"Error checking for new version: {ex.Message}");
if (silently)
{
return;
}
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);
if (result == DialogResult.Yes)
{
Utils.OpenURL("https://github.com/software-2/LightroomSync/releases");
}
return;
}
}

var parsed = Version.Parse(version);

if (parsed.CompareTo(currentVersion) != 0)
{
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();
var result = MessageBox.Show(dialog, "New Version!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (result == DialogResult.Yes)
{
Utils.OpenURL("https://github.com/software-2/LightroomSync/releases");
}
}
else if (!silently)
{
MessageBox.Show("You expected an update, but it was me! Dio!", "Up To Date!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

private void submitABugToolStripMenuItem_Click(object sender, EventArgs e)
{
Utils.OpenURL("https://github.com/software-2/LightroomSync/issues");
}

private void gitHubPageToolStripMenuItem_Click(object sender, EventArgs e)
{
string url = "https://github.com/software-2/LightroomSync";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
};
Process.Start(startInfo);
Utils.OpenURL("https://github.com/software-2/LightroomSync");
}

private void minimizeToTrayToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -635,5 +675,28 @@ private void launchAtStartupToolStripMenuItem_Click(object sender, EventArgs e)
Utils.CreateShortcutInStartupFolder(appPath);
}
}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("LightroomSync" + Environment.NewLine + "Copyright 2023 Anthony Bryan" + Environment.NewLine + Environment.NewLine + "Version " + currentVersion);
}

private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
CheckForUpdates(false);
}

private void autoCheckForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
config.AutoCheckForUpdates = !config.AutoCheckForUpdates;
if (config.AutoCheckForUpdates)
{
autoCheckForUpdatesToolStripMenuItem.Image = Resources.checkmark;
}
else
{
autoCheckForUpdatesToolStripMenuItem.Image = null;
}
}
}
}
11 changes: 11 additions & 0 deletions LightroomSync/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

namespace LightroomSync
{
Expand Down Expand Up @@ -44,5 +45,15 @@ public static string GetWorkingDir()
{
return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\LightroomSync";
}

public static void OpenURL(string url)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
};
Process.Start(startInfo);
}
}
}
1 change: 1 addition & 0 deletions latestVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0

0 comments on commit ed5acb1

Please sign in to comment.