Skip to content

Commit

Permalink
[#] 修改补丁请求方式,使用新的地址和补丁发布机制
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyadanli committed Dec 7, 2019
1 parent 82d9b5e commit aed49e4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
25 changes: 1 addition & 24 deletions RevokeMsgPatcher/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
private async void FormMain_Load(object sender, EventArgs e)
{
// 异步获取最新的补丁信息
string json = await GetPathJsonAsync();
string json = await HttpUtil.GetPatchJsonAsync();
if (string.IsNullOrEmpty(json))
{
lblUpdatePachJson.Text = "[ 获取最新补丁信息失败 ]";

}
else
{
Expand Down Expand Up @@ -247,28 +246,6 @@ private async void FormMain_Load(object sender, EventArgs e)
}
}

private async Task<string> GetPathJsonAsync()
{
string downStr = null;
try
{
downStr = await HttpUtil.Client.GetStringAsync("https://huiyadanli.coding.me/i/revokemsg/05.json");
}
catch (Exception ex1)
{
Console.WriteLine(ex1.Message);
try
{
downStr = await HttpUtil.Client.GetStringAsync("https://www.huiyadan.com/i/revokemsg/05.json");
}
catch (Exception ex2)
{
Console.WriteLine(ex2.Message);
}
}
return downStr;
}

private void lblUpdatePachJson_Click(object sender, EventArgs e)
{
string tips = "";
Expand Down
47 changes: 44 additions & 3 deletions RevokeMsgPatcher/Utils/HttpUtil.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RevokeMsgPatcher.Utils
{
public class HttpUtil
{
public static HttpClient Client { get; } = new HttpClient();

static HttpUtil()
{
Client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
}

/// <summary>
/// 补丁路径
/// 已经弃用的路径
/// https://swordmaker-hauls-51508.netlify.com/i/revokemsg/05.json
/// https://huiyadanli.github.io/i/revokemsg/05.json
/// </summary>
private static readonly string[] urls = new string[]
{
"https://coding.net/u/huiyadanli/p/RevokeMsgPatcher/git/raw/master/RevokeMsgPatcher.Assistant/Data/0.6/patch.json",
"https://gitee.com/huiyadanli/RevokeMsgPatcher/raw/master/RevokeMsgPatcher.Assistant/Data/0.6/patch.json",
"https://raw.githubusercontent.com/huiyadanli/RevokeMsgPatcher/master/RevokeMsgPatcher.Assistant/Data/0.6/patch.json"
};

private static int i = 0;

public static async Task<string> GetPatchJsonAsync()
{
try
{
return await Client.GetStringAsync(urls[i]);
}
catch (Exception ex)
{
Console.WriteLine("第" + (i + 1) + "次请求异常:[" + ex.Message + "]\nURL:" + urls[i]);
i++;
if (i > urls.Length)
{
i = 0;
return null;
}
else
{
return await GetPatchJsonAsync();
}
}
}
}
}

0 comments on commit aed49e4

Please sign in to comment.