コード例 #1
0
        public static void GetSomeData()
        {
            switch (Type)
            {
            case UpdateType.GitHubReleases:
                using (var client = new System.Net.WebClient())
                {
                    client.Headers.Add("User-Agent", "https://github.com/ScriptedEngineer/AutoUpdater");
                    client.Encoding = Encoding.UTF8;
                    try {
                        SomeData    = client.DownloadString($"https://api.github.com/repos/{LinkOrToken}/releases");
                        DownloadURL = MyExtentions.RegexMatch(SomeData, @"""browser_download_url"":""([^""]*)""");
                    }
                    catch
                    {
                        RunApp();
                    }
                }
                break;

            case UpdateType.XMLServer:
                break;

            case UpdateType.WSXZApi:
                break;
            }
        }
コード例 #2
0
        public static bool CheckVersion(string ver, out string lastVersion)
        {
            if (string.IsNullOrEmpty(SomeData))
            {
                GetSomeData();
            }
            lastVersion = "";
            switch (Type)
            {
            case UpdateType.None: return(false);

            case UpdateType.GitHubReleases:
                lastVersion = MyExtentions.RegexMatch(SomeData, @"""tag_name"":""([^""]*)""");
                string[] VFc    = ver.Split('.');
                string[] VFl    = lastVersion.Split('.');
                bool     oldVer = false;
                for (int i = 0; i < VFc.Length; i++)
                {
                    if (VFc[i] != VFl[i])
                    {
                        int.TryParse(VFc[i], out int VFci);
                        int.TryParse(VFl[i], out int VFli);
                        if (VFli > VFci)
                        {
                            oldVer = true;
                        }
                    }
                }
                return(oldVer);

            case UpdateType.XMLServer:
                break;

            case UpdateType.WSXZApi:
                break;
            }
            return(false);
        }
コード例 #3
0
        public static string GetUpdateLog(string version)
        {
            if (string.IsNullOrEmpty(SomeData))
            {
                GetSomeData();
            }
            switch (Type)
            {
            case UpdateType.GitHubReleases:
                string   updLog    = "";
                string[] gVersions = SomeData.Split(new string[] { @"},{""url"":" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string gVer in gVersions)
                {
                    string vsi = MyExtentions.RegexMatch(gVer, @"""tag_name"":""([^""]*)""");
                    if (vsi == version)
                    {
                        break;
                    }
                    string[] Lines  = MyExtentions.RegexMatch(gVer, @"""body"":""([^""]*)""").Split(new string[] { "\\r\\n" }, StringSplitOptions.RemoveEmptyEntries);
                    bool     writes = true;
                    foreach (var Line in Lines)
                    {
                        if (Line.StartsWith("# "))
                        {
                            if (!string.IsNullOrEmpty(LogLanguage))
                            {
                                string[] lang = Line.Split(']');
                                if (lang[0] == "# [" + LogLanguage)
                                {
                                    writes = true;
                                }
                                else
                                {
                                    writes = false;
                                }
                                if (lang.Length == 1)
                                {
                                    writes = true;
                                }
                            }
                            if (writes)
                            {
                                updLog += "\r\n" + Line + "\r\n";
                            }
                        }
                        else
                        if (Line.StartsWith("### "))
                        {
                            //Ingore
                        }
                        else
                        {
                            if (writes)
                            {
                                updLog += Line + "\r\n";
                            }
                        }
                    }
                }
                return(updLog.Trim());

            case UpdateType.XMLServer:
                break;

            case UpdateType.WSXZApi:
                break;
            }
            return("");
        }