2024-03-07 21:04:59 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using Zerolauncher.Defender;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Zerolauncher.Manager
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
class UpDateManager
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task TakeQMessage()
|
|
|
|
|
|
{
|
|
|
|
|
|
var client = new HttpClient();
|
|
|
|
|
|
client.DefaultRequestVersion = HttpVersion.Version20;
|
|
|
|
|
|
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
|
|
|
|
|
|
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (iPad; U; CPU OS 6_0 like Mac OS X; zh-CN; iPad2)");
|
|
|
|
|
|
HttpResponseMessage response;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
client.Timeout = TimeSpan.FromMinutes(3);
|
2024-03-07 22:50:28 +08:00
|
|
|
|
response = await client.GetAsync("https://sharechain.qq.com/037846c482eddc948612b0d0f8ed98d5"); // 初夏
|
2024-03-07 21:04:59 +08:00
|
|
|
|
}catch (Exception _ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
EngineCacheSha.errorCode = 1;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var responseString = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
responseString = responseString.Split("<div class=\"note-content\">")[1].Split("</article>")[0].Replace("</div>", "").Replace("\n", "").Replace("\t", "").Replace("\r", "").Replace("'", "");
|
|
|
|
|
|
var arr = responseString.Split("<div>").Last();
|
|
|
|
|
|
|
|
|
|
|
|
if (arr.Length < 90)
|
|
|
|
|
|
{
|
|
|
|
|
|
EngineCacheSha.errorCode = 2;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
int count;
|
|
|
|
|
|
var sha = SpaceEncoder.Decode(arr[..86], out count);
|
|
|
|
|
|
if (sha == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Console.WriteLine($"faile: {count}");
|
|
|
|
|
|
EngineCacheSha.errorCode = 2;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
EngineCacheSha.Put(sha);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
var client = new HttpClient();
|
|
|
|
|
|
client.DefaultRequestVersion = HttpVersion.Version20;
|
|
|
|
|
|
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
|
|
|
|
|
|
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (iPad; U; CPU OS 6_0 like Mac OS X; zh-CN; iPad2)");
|
|
|
|
|
|
var response = await client.GetAsync("https://sharechain.qq.com/13111bbd6ffbffa3057878431bef103e");
|
|
|
|
|
|
var responseString = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
if (responseString.Contains("<div class=\"note-content\">"))
|
|
|
|
|
|
{
|
|
|
|
|
|
responseString = responseString.Split("<div class=\"note-content\">")[1].Split("</article>")[0].Replace("</div>", "").Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("'", "");
|
|
|
|
|
|
Console.WriteLine(responseString.Replace("<div>", "\n"));
|
|
|
|
|
|
var arr = responseString.Split("<div>");
|
|
|
|
|
|
int main_version, engine_version, sa_version;
|
|
|
|
|
|
if (int.TryParse(arr[0], out main_version) && int.TryParse(arr[1], out engine_version))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// todo open faile update dialog
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void DownLoad(string Url, string FileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool Value = false;
|
|
|
|
|
|
WebResponse response = null;
|
|
|
|
|
|
Stream stream = null;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
|
|
|
|
|
|
|
|
|
|
|
|
response = request.GetResponse();
|
|
|
|
|
|
stream = response.GetResponseStream();
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ContentType.ToLower().StartsWith("text/"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Value = SaveBinaryFile(response, FileName);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
|
{
|
|
|
|
|
|
string aa = err.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static bool SaveBinaryFile(WebResponse response, string FileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool Value = true;
|
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(FileName))
|
|
|
|
|
|
File.Delete(FileName);
|
|
|
|
|
|
Stream outStream = File.Create(FileName);
|
|
|
|
|
|
Stream inStream = response.GetResponseStream();
|
|
|
|
|
|
|
|
|
|
|
|
int l;
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
l = inStream.Read(buffer, 0, buffer.Length);
|
|
|
|
|
|
if (l > 0)
|
|
|
|
|
|
outStream.Write(buffer, 0, l);
|
|
|
|
|
|
}
|
|
|
|
|
|
while (l > 0);
|
|
|
|
|
|
|
|
|
|
|
|
outStream.Close();
|
|
|
|
|
|
inStream.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
Value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|