コード例 #1
0
        private async Task <bool> CheckForUpdates()
        {
            bool   success = true;
            string xmlUrl  = "";

            string[] encodedXML = Assembly.GetExecutingAssembly().ManifestModule.Name.Split('_');
            if (Program.Arguments.Length == 1)
            {
                Logger.Log("XML passed via CLI.");
                xmlUrl = Program.Arguments[0];
            }
            else if (encodedXML.Length == 2)
            {
                Logger.Log("XML passed via module name.");
                xmlUrl = Encoding.UTF8.GetString(Convert.FromBase64String(encodedXML[1].Replace(".exe", "")));
            }
            else
            {
                Logger.Log("XML path has not been passed to Super Update!", LogLevels.Exception);
                return(false);
            }
            success = await XmlEngine.ReadXML(xmlUrl);

            if (!success)
            {
                return(success);
            }
            success = await UpdateEngine.DetectUpdates();

            if (!success)
            {
                return(success);
            }
            if (UpdateEngine.CurrentVersion != UpdateEngine.LatestVersion)
            {
                if (UpdateEngine.LatestVersion.Attributes["UpdateMessage"] != null)
                {
                    Logger.Log(UpdateEngine.LatestVersion.Attributes["UpdateMessage"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("Found new version, press \"Install\" to begin.", LogLevels.Information);
                }
            }
            else
            {
                XmlNode noUpdateMessage = XmlEngine.UpdateXML.SelectSingleNode("/SuperUpdate/Settings/MessageNoUpdate");
                if (noUpdateMessage != null)
                {
                    Logger.Log(noUpdateMessage.Attributes["Text"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("No updates are available.", LogLevels.Information);
                }
            }
            return(success);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: belowaverage-org/SuperUpdate
        /// <summary>
        /// This method will check for updates in the main form and display them to the user.
        /// </summary>
        /// <returns>bool: True on success.</returns>
        private async Task <bool> CheckForUpdates()
        {
            bool         success;
            string       xmlUrl = "";
            FileStream   fs     = File.OpenRead(Process.GetCurrentProcess().MainModule.FileName);
            StreamReader sr     = new StreamReader(fs);

            fs.Seek(-2048, SeekOrigin.End);
            List <string> srLines = new List <string>();

            while (!sr.EndOfStream)
            {
                srLines.Add(await sr.ReadLineAsync());
            }
            if (
                srLines.Count >= 2 &&
                srLines[srLines.Count - 2] == "" &&
                srLines[srLines.Count - 1] != "" &&
                Uri.TryCreate(srLines[srLines.Count - 1], UriKind.RelativeOrAbsolute, out Uri uri)
                )
            {
                xmlUrl = uri.ToString();
            }
            if (Program.Arguments.Length == 1)
            {
                Logger.Log("XML passed via CLI.");
                xmlUrl = Program.Arguments[0];
            }
            else if (xmlUrl != "")
            {
                Logger.Log("XML passed via binary.");
            }
            else
            {
                Logger.Log("XML path has not been passed to Super Update!", LogLevels.Exception);
                return(false);
            }
            success = await XmlEngine.ReadXML(xmlUrl);

            if (!success)
            {
                return(success);
            }
            success = await UpdateEngine.DetectUpdates();

            if (!success)
            {
                return(success);
            }
            if (UpdateEngine.CurrentVersion != UpdateEngine.LatestVersion)
            {
                if (UpdateEngine.LatestVersion.Attributes["UpdateMessage"] != null)
                {
                    Logger.Log(UpdateEngine.LatestVersion.Attributes["UpdateMessage"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("Found new version, press \"Install\" to begin.", LogLevels.Information);
                }
            }
            else
            {
                XmlNode noUpdateMessage = XmlEngine.UpdateXML.SelectSingleNode("/SU:SuperUpdate/SU:Settings/SU:MessageNoUpdate", XmlEngine.XNS);
                if (noUpdateMessage != null)
                {
                    Logger.Log(noUpdateMessage.Attributes["Text"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("No updates are available.", LogLevels.Information);
                }
            }
            return(success);
        }