Skip to content

Commit

Permalink
added update checks
Browse files Browse the repository at this point in the history
  • Loading branch information
FerrisSandCanyon committed Jan 24, 2020
1 parent 40ea12f commit 933a989
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 56 deletions.
74 changes: 57 additions & 17 deletions owl/Class/AppUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;

namespace owl.Class
{
public class AppUpdate
{
public AppUpdate(string _updateInfoLink = "", bool checkNow = false)
{
this.updateInfoLink = _updateInfoLink;

if (checkNow)
this.Check(this.updateInfoLink);

}

public int vMajor = 0,
vMinor = 0,
vPatch = 0;
public string dlLink = null,
desc = null;

[JsonIgnore]
private string updateInfoLink = "";

public void Check(string _updateInfoLink = "")
{

}

public bool IsNewer()
{
if (this.vMajor > Globals.Info.vMajor || this.vMinor > Globals.Info.vMinor || this.vPatch > Globals.Info.vPatch)
Expand All @@ -41,3 +28,56 @@ public bool IsNewer()
}
}
}

namespace owl.Utils
{
public static class AppUpdate
{
public static void Check(ref Class.AppUpdate _au, string updateInfoLink = null)
{
using (WebClient _wc = new WebClient())
{
_au = JsonConvert.DeserializeObject<Class.AppUpdate>(_wc.DownloadString(updateInfoLink));
}
}

public static void CheckUpdateWrapper(bool silentUpdate = false)
{
/*
Thread _thread = new Thread(new ThreadStart(() =>
{
Utils.AppUpdate.Check(ref Globals.AppUpdateInfo, Globals.Info.updateInfoLink);
if (Globals.AppUpdateInfo.IsCurrent())
{
MessageBox.Show("You're currently running the newest released version!", "Update Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (Globals.AppUpdateInfo.IsNewer()
&& MessageBox.Show($"A newer version of OWL is available! version {Globals.AppUpdateInfo.vMajor}.{Globals.AppUpdateInfo.vMinor}.{Globals.AppUpdateInfo.vMinor}\n\n{Globals.AppUpdateInfo.desc}\n\nWould you like to open the download link: {Globals.AppUpdateInfo.dlLink}?", "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Process.Start(Globals.AppUpdateInfo.dlLink);
}
}));
if (!_thread.IsAlive)
_thread.Start();
*/

Utils.AppUpdate.Check(ref Globals.AppUpdateInfo, Globals.Info.updateInfoLink);

if (Globals.AppUpdateInfo.IsNewer())
{
if (MessageBox.Show($"A newer version of OWL is available! version {Globals.AppUpdateInfo.vMajor}.{Globals.AppUpdateInfo.vMinor}.{Globals.AppUpdateInfo.vMinor}\n\n{Globals.AppUpdateInfo.desc}\n\nWould you like to open the download link: {Globals.AppUpdateInfo.dlLink}?", "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
Process.Start(Globals.AppUpdateInfo.dlLink);
}
else
{
if (!silentUpdate)
MessageBox.Show("You're currently running the newest released version!", "Update Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}
}
3 changes: 2 additions & 1 deletion owl/Class/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class Config

public bool forceStatus = false, // Forces status check on accounts with Bans
maskPassword = true, // Display the password in plain text or mask it with • on the accounts form
clipboardDetail = false; // Dictates clipboard mode whether to use a single line (false) or detailed (true) format
clipboardDetail = false, // Dictates clipboard mode whether to use a single line (false) or detailed (true) format
startupUpdateChk = true; // Checks for updates at startup
}
}

Expand Down
1 change: 1 addition & 0 deletions owl/Forms/Main.Designer.cs

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

40 changes: 24 additions & 16 deletions owl/Forms/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private void FormMain_Load(object sender, EventArgs e)

ddUtils.Visible = false;
ddSteamUserData.Visible = false;
btnUpdate.Visible = false;
#endif

this.title_fallback = this.Text;
Expand Down Expand Up @@ -75,6 +74,10 @@ private void FormMain_Load(object sender, EventArgs e)

FormMain_UpdateTitle();

#if !DEBUG
if (Globals.Config.startupUpdateChk)
Utils.AppUpdate.CheckUpdateWrapper(true);
#endif
}

// Legacy
Expand Down Expand Up @@ -170,7 +173,12 @@ private void importConvertToolStripMenuItem_Click(object sender, EventArgs e)
(new Forms.ProfileJSONImport()).ShowDialog();
}

#region Profile
private void btnUpdate_Click(object sender, EventArgs e)
{
Utils.AppUpdate.CheckUpdateWrapper();
}

#region Profile

// Loads the selected profile.
private void CbProfile_SelectedIndexChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -219,17 +227,17 @@ private void CbProfile_LoadProfileDirectory()
{
cbProfile.Items.Clear();

#if DEBUG
#if DEBUG
foreach(string _profile in Directory.GetFiles(Globals.Info.profilesPath, "*.json"))
{
string _profilename = Path.GetFileNameWithoutExtension(_profile);
cbProfile.Items.Add(_profilename);
Debug.WriteLine(String.Format("Profile: {0}\nProfile Name:[{1}]", _profile, _profilename));
}
#else
#else
foreach(string _profile in Directory.GetFiles(Globals.Info.profilesPath, "*.json"))
cbProfile.Items.Add(Path.GetFileNameWithoutExtension(_profile));
#endif
#endif

if (cbProfile.Items.Count != 0)
{
Expand Down Expand Up @@ -339,9 +347,9 @@ private void SetAsDefaultProfileToolStripMenuItem_Click(object sender, EventArgs
MessageBox.Show("Current profile has been set as the default profile!", "Profile", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

#endregion
#endregion

#region Account
#region Account

// Add an account
private void DdAccountAdd_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -400,9 +408,9 @@ private void DdAccountRemove_Click(object sender, EventArgs e)

foreach (ListViewItem _lvi in lvData.SelectedItems)
{
#if DEBUG
#if DEBUG
Debug.WriteLine("Deleting account id: " + _lvi.SubItems[0].Text);
#endif
#endif

Class.Account _account;
if (!Globals.CurrentProfile.Profiles.TryGetValue(_lvi.SubItems[0].Text, out _account))
Expand Down Expand Up @@ -518,9 +526,9 @@ private void DdManageObtainQueueAbort_Click(object sender, EventArgs e)
Globals.ParserQueue.Abort();
}

#endregion
#endregion

#region Info Pop-Up
#region Info Pop-Up

private void DdManageObtainInfo_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -548,9 +556,9 @@ private void BtnAbout_Click(object sender, EventArgs e)
}
}

#endregion
#endregion

#region Account Login
#region Account Login

private void DdManageLoginNormal_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -580,9 +588,9 @@ private void AccountLogin(bool force = false)
_account.Login(force);
}

#endregion
#endregion

#region Events
#region Events

protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
Expand Down Expand Up @@ -751,6 +759,6 @@ private void Event_LSImport(object sender, EventArgs e)
}
}

#endregion
#endregion
}
}
17 changes: 15 additions & 2 deletions owl/Forms/Settings.Designer.cs

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

30 changes: 16 additions & 14 deletions owl/Forms/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public Settings()

private void FormSettings_Load(object sender, EventArgs e)
{
tbPath.Text = Globals.Config.steamPath ?? "";
tbParam.Text = Globals.Config.steamParam ?? "";
tbCD.Text = Globals.Config.cooldownRefresh.ToString() ?? "800";
tbThread.Text = Globals.Config.maxThreads.ToString() ?? "4";
cbForce.Checked = Globals.Config.forceStatus;
cbMask.Checked = Globals.Config.maskPassword;
clipmode = Globals.Config.clipboardDetail;
tbPath.Text = Globals.Config.steamPath ?? "";
tbParam.Text = Globals.Config.steamParam ?? "";
tbCD.Text = Globals.Config.cooldownRefresh.ToString() ?? "800";
tbThread.Text = Globals.Config.maxThreads.ToString() ?? "4";
cbForce.Checked = Globals.Config.forceStatus;
cbMask.Checked = Globals.Config.maskPassword;
clipmode = Globals.Config.clipboardDetail;
cbUpdate.Checked = Globals.Config.startupUpdateChk;

BtnClip_SetTxt();
}
Expand All @@ -47,13 +48,14 @@ private void BtnSave_Click(object sender, EventArgs e)
return;
}

Globals.Config.steamPath = tbPath.Text;
Globals.Config.steamParam = tbParam.Text;
Globals.Config.cooldownRefresh = newcd;
Globals.Config.maxThreads = newmax;
Globals.Config.forceStatus = cbForce.Checked;
Globals.Config.maskPassword = cbMask.Checked;
Globals.Config.clipboardDetail = clipmode;
Globals.Config.steamPath = tbPath.Text;
Globals.Config.steamParam = tbParam.Text;
Globals.Config.cooldownRefresh = newcd;
Globals.Config.maxThreads = newmax;
Globals.Config.forceStatus = cbForce.Checked;
Globals.Config.maskPassword = cbMask.Checked;
Globals.Config.clipboardDetail = clipmode;
Globals.Config.startupUpdateChk = cbUpdate.Checked;

if (!Utils.Config.Save(ref Globals.Config, Globals.Info.cfgPath))
{
Expand Down
8 changes: 5 additions & 3 deletions owl/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class Globals
public static Class.ProfileInfo CurrentProfile = null; // Global ProfileInfo of all the account instances and extra information about the profile
public static Class.Config Config = null; // Global Config class
public static Class.Account LastAccountLogin = null; // Stores the account class of the last account logged in to
public static Class.AppUpdate AppUpdateInfo = new Class.AppUpdate();

public static FormMain hFormMain = null; // Handle to our main form for access and invoking

Expand Down Expand Up @@ -42,9 +43,10 @@ public static class Info
vPatch = 0,
vProfileFormat = 1;

public const string verStr = "0.4.0",
cfgPath = "./config.json",
profilesPath = "./profiles";
public const string verStr = "0.4.0",
cfgPath = "./config.json",
profilesPath = "./profiles",
updateInfoLink = "https://raw.githubusercontent.com/FerrisSandCanyon/OWL/master/update_info.json";
}
}
}
6 changes: 3 additions & 3 deletions update_info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"vMajor":0,
"vMinor":0,
"vMinor":3,
"vPatch":0,
"dlLink":"https://example.com",
"desc":"Test JSON"
"dlLink":"https://github.com/FerrisSandCanyon/OWL/releases/tag/0.3.0",
"desc":"Changed JSON format and added Profile JSON format converter"
}

0 comments on commit 933a989

Please sign in to comment.