Skip to content

Commit

Permalink
Check for newer versions on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
molenzwiebel committed Dec 7, 2019
1 parent aa2d42b commit 91bbe08
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Deceive/ConfigProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Deceive.Properties;
using EmbedIO;
using EmbedIO.Actions;

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Deceive/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions Deceive/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ namespace Deceive
{
class MainClass
{
public static string DeceiveTitle
{
get
{
return "Deceive " + Resources.DeceiveVersion;
}
}

[STAThread]
public static void Main(string[] args)
{
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Deceive/Properties/Resources.Designer.cs

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

4 changes: 2 additions & 2 deletions Deceive/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<data name="deceive" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\deceive.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="DeceiveTitle" xml:space="preserve">
<value>Deceive v1.6.0</value>
<data name="DeceiveVersion" xml:space="preserve">
<value>v1.6.0</value>
</data>
</root>
56 changes: 54 additions & 2 deletions Deceive/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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+?)\"");
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 91bbe08

Please sign in to comment.