AwbUpdater.Updater.AWBVersion C# (CSharp) Method

AWBVersion() private method

Checks and compares the current AWB version with the version listed on the checkpage
private AWBVersion ( ) : void
return void
        private void AWBVersion()
        {
            string text;

            UpdateUI("   Retrieving current version...", true);
            try
            {
                HttpWebRequest rq =
                    (HttpWebRequest)
                        WebRequest.Create(
                            "https://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw");

                rq.Proxy = _proxy;

                rq.UserAgent = string.Format("AWBUpdater/{0} ({1}; .NET CLR {2})",
                    Assembly.GetExecutingAssembly().GetName().Version,
                    Environment.OSVersion.VersionString, Environment.Version);

                HttpWebResponse response = (HttpWebResponse) rq.GetResponse();

                Stream stream = response.GetResponseStream();
                StreamReader sr = new StreamReader(stream, Encoding.UTF8);

                text = sr.ReadToEnd();

                sr.Close();
                stream.Close();
                response.Close();
            }
            catch
            {
                AppendLine("FAILED");
                throw new AbortException();
            }

            int awbCurrentVersion =
                StringToVersion(Regex.Match(text, @"<!-- Current version: (.*?) -->").Groups[1].Value);
            int awbNewestVersion =
                StringToVersion(Regex.Match(text, @"<!-- Newest version: (.*?) -->").Groups[1].Value);
            int updaterVersion = StringToVersion(Regex.Match(text, @"<!-- Updater version: (.*?) -->").Groups[1].Value);

            try
            {
                _awbUpdate = _updaterUpdate = false;
                FileVersionInfo awbVersionInfo =
                    FileVersionInfo.GetVersionInfo(Path.Combine(_awbDirectory, "AutoWikiBrowser.exe"));
                int awbFileVersion = StringToVersion(awbVersionInfo.FileVersion);

                if (awbFileVersion < awbCurrentVersion)
                    _awbUpdate = true;
                else if ((awbFileVersion >= awbCurrentVersion) &&
                         (awbFileVersion < awbNewestVersion) &&
                         MessageBox.Show("There is an optional update to AutoWikiBrowser. Would you like to upgrade?",
                             "Optional update", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    _awbUpdate = true;

                if (_awbUpdate)
                {
                    AWBZipName = "AutoWikiBrowser" + awbNewestVersion + ".zip";
                    _awbWebAddress = string.Format("http://downloads.sourceforge.net/project/autowikibrowser/autowikibrowser/{0}/{1}", AWBZipName.Replace(".zip", ""), AWBZipName);
                }
                else if ((updaterVersion > 1400) &&
                         (updaterVersion > AssemblyVersion))
                {
                    _updaterZipName = "AWBUpdater" + updaterVersion + ".zip";
                    _updaterWebAddress = string.Format("http://downloads.sourceforge.net/project/autowikibrowser/autowikibrowser/{0}/{1}", _updaterZipName.Replace(".zip", ""), _updaterZipName);
                    _updaterUpdate = true;
                }
            }
            catch
            {
                UpdateUI("   Unable to find AutoWikiBrowser.exe to query its version", true);
            }

            progressUpdate.Value = 35;
        }