Skip to content

Commit 4c6168d

Browse files
committed
更新暂时改用网页
1 parent 346907d commit 4c6168d

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Mikoto/Common.cs

+17-8
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ private static void ShowUpdateMessageBox(Version latestVersion)
3030

3131
if (dr == MessageBoxResult.OK)
3232
{
33-
// Process.Start(new ProcessStartInfo("https://github.com/liscs/Mikoto/releases/latest") { UseShellExecute = true });
33+
Process.Start(new ProcessStartInfo("https://github.com/liscs/Mikoto/releases/latest") { UseShellExecute = true });
3434
//点击确认,自动下载最新版并替换重启
35-
_ = DownloadBackgroundAsync(latestVersion);
35+
//DownloadBackground(latestVersion);
3636
}
3737
}
3838

39-
private static async Task DownloadBackgroundAsync(Version latestVersion)
39+
private static async void DownloadBackground(Version latestVersion)
4040
{
4141
string filename = GetDownloadZipFilename();
4242
string url = $"https://github.com/liscs/Mikoto/releases/download/v{latestVersion.ToString(3)}/{filename}";
4343
var temp = Directory.CreateTempSubdirectory();
4444
string filePath = Path.Combine(temp.FullName, filename); // 替换为你希望保存文件的路径
4545

46-
HttpClient client = CommonHttpClient.Instance;
46+
HttpClient client = new() { Timeout = Timeout.InfiniteTimeSpan };
4747
try
4848
{
49-
byte[] fileBytes = await client.GetByteArrayAsync(url);
50-
await File.WriteAllBytesAsync(filePath, fileBytes);
49+
using (HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
50+
using (Stream stream = await response.Content.ReadAsStreamAsync())
51+
using (FileStream fileStream = new(filePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true))
52+
{
53+
await stream.CopyToAsync(fileStream);
54+
}
55+
5156
ZipFile.ExtractToDirectory(filePath, temp.FullName);
5257

5358
string extractedFolder = Path.Combine(temp.FullName, Path.GetFileNameWithoutExtension(filename));
@@ -57,6 +62,10 @@ private static async Task DownloadBackgroundAsync(Version latestVersion)
5762
{
5863
Logger.Warn(ex);
5964
}
65+
finally
66+
{
67+
client.Dispose();
68+
}
6069
}
6170

6271
private static string GetDownloadZipFilename()
@@ -76,7 +85,7 @@ private static void AskUpdateNow(string extractedFolder)
7685
MessageBoxResult dr = MessageBox.Show("下载完成,是否立刻更新?", "", MessageBoxButton.OKCancel);
7786
if (dr == MessageBoxResult.OK)
7887
{
79-
ProcessStartInfo processStartInfo = new("Updater.exe");
88+
ProcessStartInfo processStartInfo = new("Mikoto.Updater.exe");
8089
processStartInfo.ArgumentList.Add(extractedFolder);
8190
processStartInfo.ArgumentList.Add(true.ToString());
8291
Process.Start(processStartInfo);
@@ -86,7 +95,7 @@ private static void AskUpdateNow(string extractedFolder)
8695
{
8796
Application.Current.MainWindow.Closing += (s, e) =>
8897
{
89-
ProcessStartInfo processStartInfo = new("Updater.exe");
98+
ProcessStartInfo processStartInfo = new("Mikoto.Updater.exe");
9099
processStartInfo.ArgumentList.Add(extractedFolder);
91100
processStartInfo.ArgumentList.Add(false.ToString());
92101
Process.Start(processStartInfo);

0 commit comments

Comments
 (0)