diff --git a/Deceive/ConfigProxy.cs b/Deceive/ConfigProxy.cs index 47889e5..b2ac4c3 100644 --- a/Deceive/ConfigProxy.cs +++ b/Deceive/ConfigProxy.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Deceive.Properties; using EmbedIO; using EmbedIO.Actions; @@ -54,7 +53,6 @@ public static int StartConfigProxy(string configUrl, int chatPort) private async static Task ProxyAndRewriteResponse(string configUrl, int chatPort, IHttpContext ctx) { var url = configUrl + ctx.Request.RawUrl; - Console.WriteLine(url); using (var message = new HttpRequestMessage(HttpMethod.Get, url)) { @@ -119,7 +117,7 @@ private async static Task ProxyAndRewriteResponse(string configUrl, int chatPort MessageBox.Show( "Deceive was unable to rewrite a League of Legends configuration file. This normally happens because Riot changed something on their end. Please check if there's a new version of Deceive available, or contact the creator through GitHub (https://github.com/molenzwiebel/deceive) or Discord if there's not.\n\n" + ex, - Resources.DeceiveTitle, + MainClass.DeceiveTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 diff --git a/Deceive/MainController.cs b/Deceive/MainController.cs index 48b6103..f639bc3 100644 --- a/Deceive/MainController.cs +++ b/Deceive/MainController.cs @@ -28,7 +28,7 @@ public MainController() { Icon = Resources.deceive, Visible = true, - BalloonTipTitle = Resources.DeceiveTitle, + BalloonTipTitle = MainClass.DeceiveTitle, BalloonTipText = "Deceive is currently masking your status. Right-Click the tray icon for more options." }; trayIcon.ShowBalloonTip(5000); @@ -64,7 +64,7 @@ private async void InitLcuStatus() private void SetupMenuItems() { - var aboutMenuItem = new MenuItem(Resources.DeceiveTitle) + var aboutMenuItem = new MenuItem(MainClass.DeceiveTitle) { Enabled = false }; @@ -105,7 +105,7 @@ private void SetupMenuItems() { var result = MessageBox.Show( "Are you sure you want to stop Deceive? This will also stop League if it is running.", - Resources.DeceiveTitle, + MainClass.DeceiveTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 diff --git a/Deceive/Program.cs b/Deceive/Program.cs index 93b3bf3..aef72f9 100644 --- a/Deceive/Program.cs +++ b/Deceive/Program.cs @@ -15,6 +15,14 @@ namespace Deceive { class MainClass { + public static string DeceiveTitle + { + get + { + return "Deceive " + Resources.DeceiveVersion; + } + } + [STAThread] public static void Main(string[] args) { @@ -27,7 +35,7 @@ public static void Main(string[] args) // Show some kind of message so that Deceive doesn't just disappear. MessageBox.Show( "Deceive encountered an error and couldn't properly initialize itself. Please contact the creator through GitHub (https://github.com/molenzwiebel/deceive) or Discord.\n\n" + ex, - Resources.DeceiveTitle, + DeceiveTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 @@ -47,7 +55,7 @@ private static void StartDeceive() var result = MessageBox.Show( "League is currently running. In order to mask your online status, League needs to be started by Deceive. Do you want Deceive to stop League, so that it can restart it with the proper configuration?", - Resources.DeceiveTitle, + DeceiveTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 @@ -58,6 +66,10 @@ private static void StartDeceive() Thread.Sleep(2000); // Riot Client takes a while to die } + // Step 0: Check for updates in the background. + // Intentionally not awaited. + Utils.CheckForUpdates(); + // Step 1: Open a port for our proxy, so we can patch the port number into the system yaml. var listener = new TcpListener(IPAddress.Loopback, 0); listener.Start(); @@ -95,7 +107,7 @@ private static void StartDeceive() { MessageBox.Show( "Deceive was unable to find the path to the Riot Launcher. If you have League installed and it is working properly, please file a bug report through GitHub (https://github.com/molenzwiebel/deceive) or Discord.", - Resources.DeceiveTitle, + DeceiveTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 diff --git a/Deceive/Properties/Resources.Designer.cs b/Deceive/Properties/Resources.Designer.cs index 1e02c92..acc489f 100644 --- a/Deceive/Properties/Resources.Designer.cs +++ b/Deceive/Properties/Resources.Designer.cs @@ -81,11 +81,11 @@ internal static System.Drawing.Icon deceive { } /// - /// Looks up a localized string similar to Deceive v1.6.0. + /// Looks up a localized string similar to v1.6.0. /// - internal static string DeceiveTitle { + internal static string DeceiveVersion { get { - return ResourceManager.GetString("DeceiveTitle", resourceCulture); + return ResourceManager.GetString("DeceiveVersion", resourceCulture); } } } diff --git a/Deceive/Properties/Resources.resx b/Deceive/Properties/Resources.resx index 8abc6da..c70e1d1 100644 --- a/Deceive/Properties/Resources.resx +++ b/Deceive/Properties/Resources.resx @@ -124,7 +124,7 @@ ..\Resources\deceive.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - Deceive v1.6.0 + + v1.6.0 \ No newline at end of file diff --git a/Deceive/Utils.cs b/Deceive/Utils.cs index 679f63d..c907858 100644 --- a/Deceive/Utils.cs +++ b/Deceive/Utils.cs @@ -13,12 +13,16 @@ using System.Text.RegularExpressions; using System.Windows.Forms; using Deceive.Properties; +using System.Net.Http; using WebSocketSharp; +using System.Threading.Tasks; namespace Deceive { class Utils { + private static readonly HttpClient HTTP_CLIENT = new HttpClient(); + public static readonly string DATA_DIR = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Deceive"); private static readonly Regex AUTH_TOKEN_REGEX = new Regex("\"--remoting-auth-token=(.+?)\""); private static readonly Regex PORT_REGEX = new Regex("\"--app-port=(\\d+?)\""); @@ -89,7 +93,7 @@ public static string GetLCUPath() // Notify that the path is invalid. MessageBox.Show( "Could not find the League client at " + path + ". Please select the location of 'LeagueClient.exe' manually.", - Resources.DeceiveTitle, + MainClass.DeceiveTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); @@ -121,6 +125,54 @@ public static string GetLCUPath() return path; } + /** + * Asynchronously checks if the current version of Deceive is the latest version. If not, and the user has + * not dismissed the message before, an alert is shwon. + */ + public static async Task CheckForUpdates() + { + try + { + HTTP_CLIENT.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("Deceive", Resources.DeceiveVersion)); + + var response = await HTTP_CLIENT.GetAsync("https://api.github.com/repos/molenzwiebel/deceive/releases/latest"); + var content = await response.Content.ReadAsStringAsync(); + dynamic release = SimpleJson.DeserializeObject(content); + var latestVersion = release["tag_name"]; + + // If failed to fetch or already latest, return. + if (latestVersion == null) return; + if (latestVersion == Resources.DeceiveVersion) return; + + // Check if we have shown this before. + var persistencePath = Path.Combine(DATA_DIR, "updateVersionPrompted"); + var latestShownVersion = File.Exists(persistencePath) ? File.ReadAllText(persistencePath) : ""; + + // If we have, return. + if (latestShownVersion == latestVersion) return; + + // Show a message and record the latest shown. + File.WriteAllText(persistencePath, latestVersion); + + var result = MessageBox.Show( + $"There is a new version of Deceive available: {latestVersion}. You are currently using Deceive {Resources.DeceiveVersion}. Deceive updates usually fix critical bugs or adapt to changes by Riot, so it is recommended that you install the latest version.\n\nPress OK to visit the download page, or press Cancel to continue. Don't worry, we won't bother you with this message again if you press cancel.", + MainClass.DeceiveTitle, + MessageBoxButtons.OKCancel, + MessageBoxIcon.Information, + MessageBoxDefaultButton.Button1 + ); + + if (result == DialogResult.OK) + { + // Open the url in the browser. + Process.Start(release["html_url"]); + } + } + { + // Ignored. + } + } + /** * Checks if the provided path is most likely a path where the LCU is installed. */ @@ -162,7 +214,7 @@ public static void InitPathWithRunningLCU() { var result = MessageBox.Show( "League is currently running in admin mode. In order to proceed Deceive also needs to be elevated. Do you want Deceive to restart in admin mode?", - Resources.DeceiveTitle, + MainClass.DeceiveTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1