@@ -30,24 +30,29 @@ private static void ShowUpdateMessageBox(Version latestVersion)
30
30
31
31
if ( dr == MessageBoxResult . OK )
32
32
{
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 } ) ;
34
34
//点击确认,自动下载最新版并替换重启
35
- _ = DownloadBackgroundAsync ( latestVersion ) ;
35
+ //DownloadBackground (latestVersion);
36
36
}
37
37
}
38
38
39
- private static async Task DownloadBackgroundAsync ( Version latestVersion )
39
+ private static async void DownloadBackground ( Version latestVersion )
40
40
{
41
41
string filename = GetDownloadZipFilename ( ) ;
42
42
string url = $ "https://github.com/liscs/Mikoto/releases/download/v{ latestVersion . ToString ( 3 ) } /{ filename } ";
43
43
var temp = Directory . CreateTempSubdirectory ( ) ;
44
44
string filePath = Path . Combine ( temp . FullName , filename ) ; // 替换为你希望保存文件的路径
45
45
46
- HttpClient client = CommonHttpClient . Instance ;
46
+ HttpClient client = new ( ) { Timeout = Timeout . InfiniteTimeSpan } ;
47
47
try
48
48
{
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
+
51
56
ZipFile . ExtractToDirectory ( filePath , temp . FullName ) ;
52
57
53
58
string extractedFolder = Path . Combine ( temp . FullName , Path . GetFileNameWithoutExtension ( filename ) ) ;
@@ -57,6 +62,10 @@ private static async Task DownloadBackgroundAsync(Version latestVersion)
57
62
{
58
63
Logger . Warn ( ex ) ;
59
64
}
65
+ finally
66
+ {
67
+ client . Dispose ( ) ;
68
+ }
60
69
}
61
70
62
71
private static string GetDownloadZipFilename ( )
@@ -76,7 +85,7 @@ private static void AskUpdateNow(string extractedFolder)
76
85
MessageBoxResult dr = MessageBox . Show ( "下载完成,是否立刻更新?" , "" , MessageBoxButton . OKCancel ) ;
77
86
if ( dr == MessageBoxResult . OK )
78
87
{
79
- ProcessStartInfo processStartInfo = new ( "Updater.exe" ) ;
88
+ ProcessStartInfo processStartInfo = new ( "Mikoto. Updater.exe" ) ;
80
89
processStartInfo . ArgumentList . Add ( extractedFolder ) ;
81
90
processStartInfo . ArgumentList . Add ( true . ToString ( ) ) ;
82
91
Process . Start ( processStartInfo ) ;
@@ -86,7 +95,7 @@ private static void AskUpdateNow(string extractedFolder)
86
95
{
87
96
Application . Current . MainWindow . Closing += ( s , e ) =>
88
97
{
89
- ProcessStartInfo processStartInfo = new ( "Updater.exe" ) ;
98
+ ProcessStartInfo processStartInfo = new ( "Mikoto. Updater.exe" ) ;
90
99
processStartInfo . ArgumentList . Add ( extractedFolder ) ;
91
100
processStartInfo . ArgumentList . Add ( false . ToString ( ) ) ;
92
101
Process . Start ( processStartInfo ) ;
0 commit comments