diff --git a/WikiFunctions/Session.cs b/WikiFunctions/Session.cs index 4e1204fce..38a9fb5f4 100644 --- a/WikiFunctions/Session.cs +++ b/WikiFunctions/Session.cs @@ -23,6 +23,7 @@ using System.Security.Authentication; using System.Text.RegularExpressions; using System.Windows.Forms; +using Newtonsoft.Json.Linq; using WikiFunctions.API; namespace WikiFunctions @@ -237,8 +238,6 @@ public WikiStatusResult Update() public static string AWBVersion { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } } - private static readonly Regex BadName = new Regex(@"badname:\s*(.*)\s*(:?|#.*)$", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex DirectionMarks = new Regex(@"^(\u200E|\u200F)+", RegexOptions.Multiline); /// @@ -295,12 +294,13 @@ private WikiStatusResult UpdateWikiStatus() // TODO: assess the impact on servers later Editor.Maxlag = /*User.IsBot ? 5 : 20*/ -1; + var versionJson = JObject.Parse(Updater.GlobalVersionPage); // check if username is globally blacklisted - foreach (Match badName in BadName.Matches(Updater.GlobalVersionPage)) + foreach (string badName in versionJson["badnames"]) { - if (!string.IsNullOrEmpty(badName.Groups[1].Value.Trim()) && + if (!string.IsNullOrEmpty(badName.Trim()) && !string.IsNullOrEmpty(User.Name) && - Regex.IsMatch(User.Name, badName.Groups[1].Value.Trim(), + Regex.IsMatch(User.Name, badName.Trim(), RegexOptions.IgnoreCase | RegexOptions.Multiline)) return WikiStatusResult.NotRegistered; } @@ -363,11 +363,14 @@ private WikiStatusResult UpdateWikiStatus() if (Variables.Project != ProjectEnum.custom) { - string globalUsers = Tools.StringBetween(VersionCheckPage, "", - ""); - - if (UserNameInText(User.Name, globalUsers)) - return WikiStatusResult.Registered; + var globalUsers = versionJson["globalusers"]; + foreach (string s in globalUsers) + { + if (User.Name == s) + { + return WikiStatusResult.Registered; + } + } } return WikiStatusResult.NotRegistered; } diff --git a/WikiFunctions/Updater.cs b/WikiFunctions/Updater.cs index 08ebd671e..ab6866763 100644 --- a/WikiFunctions/Updater.cs +++ b/WikiFunctions/Updater.cs @@ -21,6 +21,9 @@ using System.Text.RegularExpressions; using System.Windows.Forms; using WikiFunctions.Background; +using System.Linq; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; namespace WikiFunctions { @@ -57,12 +60,10 @@ public enum AWBEnabledStatus public static AWBEnabledStatus Result { get; private set; } /// - /// Text of the Current AWB Global Checkpage (en.wp) + /// Text (JSON) of the Current AWB Global Checkpage (en.wp) /// public static string GlobalVersionPage { get; private set; } - private static readonly Regex EnabledVersions = new Regex(@"\*(.*?) enabled", RegexOptions.IgnoreCase | RegexOptions.Compiled); - /// /// Do the actual checking for enabledness etc /// @@ -72,56 +73,45 @@ private static void UpdateFunc() { string text = Tools.GetHTML( - "https://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw"); + "https://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/VersionJSON&action=raw"); GlobalVersionPage = text; - int awbCurrentVersion = - StringToVersion(Regex.Match(text, @"").Groups[1].Value); + var json = JObject.Parse(text); + + Result = AWBEnabledStatus.Disabled; // Disabled till proven enabled + + var definition = new { version = "", dotnetversion = "", svn = false }; + var enabledVersions = from v in json["enabledversions"] select JsonConvert.DeserializeAnonymousType(v.ToString(), definition); + + string updaterVersion = json["updaterversion"].ToString(); + + FileVersionInfo awbVersionInfo = + FileVersionInfo.GetVersionInfo(AWBDirectory + "AutoWikiBrowser.exe"); + + if (enabledVersions.Any(v => v.version == awbVersionInfo.ToString())) + { + Result = AWBEnabledStatus.Enabled; + } + + string updaterFileVersion = FileVersionInfo.GetVersionInfo(AWBDirectory + "AWBUpdater.exe").FileVersion; - int awbNewestVersion = - StringToVersion(Regex.Match(text, @"").Groups[1].Value); + if (Version.Parse(updaterFileVersion) < Version.Parse(updaterVersion)) + { + Result |= AWBEnabledStatus.UpdaterUpdate; + } - if ((awbCurrentVersion > 4000) || (awbNewestVersion > 4000)) + if ((Result & AWBEnabledStatus.Disabled) == AWBEnabledStatus.Disabled) { - int updaterVersion = - StringToVersion(Regex.Match(text, @"").Groups[1].Value); - - FileVersionInfo awbVersionInfo = - FileVersionInfo.GetVersionInfo(AWBDirectory + "AutoWikiBrowser.exe"); - int awbFileVersion = StringToVersion(awbVersionInfo.FileVersion); - - Result = AWBEnabledStatus.Disabled; // Disabled till proven enabled - - //if (awbFileVersion < awbCurrentVersion) - //{ - // return; - //} - - foreach (Match m in EnabledVersions.Matches(text)) - { - if (StringToVersion(m.Groups[1].Value) == awbFileVersion) - { - Result = AWBEnabledStatus.Enabled; - break; - } - } - - if (Result == AWBEnabledStatus.Disabled) - { - return; - } - - if ((updaterVersion > 1400) && - (updaterVersion > - StringToVersion(FileVersionInfo.GetVersionInfo(AWBDirectory + "AWBUpdater.exe").FileVersion))) - { - Result |= AWBEnabledStatus.UpdaterUpdate; - } - - if ((awbFileVersion >= awbCurrentVersion) && (awbFileVersion < awbNewestVersion)) - { - Result |= AWBEnabledStatus.OptionalUpdate; - } + // If it's disabled, updates aren't optional! + return; + } + + var awbVersionParsed = Version.Parse(awbVersionInfo.FileVersion); + + // SVN versions aren't optional updates + if (enabledVersions.Any(v => (Version.Parse(v.version) > awbVersionParsed && !v.svn))) + { + Result |= AWBEnabledStatus.OptionalUpdate; } } catch @@ -130,22 +120,6 @@ private static void UpdateFunc() } } - /// - /// Change a string version (x.x.x.x) to a version number (xxxx) - /// - /// Version String - /// Version Number - private static int StringToVersion(string version) - { - int res; - if (!int.TryParse(version.Replace(".", ""), out res)) - { - res = 0; - } - - return res; - } - private static BackgroundRequest _request; ///