Skip to content

Commit 76ad5c6

Browse files
committed
完善更新,修改更新格式
1 parent 752a622 commit 76ad5c6

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

Round.NET.AvaloniaApp.EncodeCalculator/Models/Update/Update.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public static string GetCurrentVersion()
2525
// 获取当前程序的版本号
2626
Assembly assembly = Assembly.GetExecutingAssembly();
2727
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
28-
return $"v{fvi.ProductVersion.Split('+')[0]}";
28+
return $"v{fvi.ProductVersion.Split('+')[0].Replace(".","")}";
2929
}
3030

3131
public static string GetNewVersion()
3232
{
33-
return releaseInfo["name"].ToString();
33+
return releaseInfo["name"].ToString().Replace(".","");
3434
}
3535
public static string GetNewVersionTime()
3636
{
@@ -51,11 +51,8 @@ public static bool GetUpdate()
5151
string jsonResponse = client.GetStringAsync(repoUrl).Result;
5252
releaseInfo = JObject.Parse(jsonResponse);
5353

54-
string latestVersion = releaseInfo["name"].ToString();
55-
Console.WriteLine($"最新版本: {latestVersion}");
56-
5754
// 检查是否为当前版本
58-
if (latestVersion == currentVersion)
55+
if (GetNewVersion().Replace(".","") == GetCurrentVersion().Replace(".",""))
5956
{
6057
return false;
6158
}
@@ -70,7 +67,7 @@ public static bool GetUpdate()
7067
}
7168
}
7269

73-
public static async Task UpdateCore(ProgressBar bar,ContentDialog shd)
70+
public static async Task UpdateCore(ProgressBar bar,ContentDialog shd,Label jd)
7471
{
7572
// 获取系统架构
7673
string architecture = RuntimeInformation.ProcessArchitecture.ToString().ToLower();
@@ -90,7 +87,7 @@ public static async Task UpdateCore(ProgressBar bar,ContentDialog shd)
9087
{
9188
string downloadUrl = installerAsset["browser_download_url"].ToString();
9289
Console.WriteLine($"正在下载: {installerName}");
93-
await DownloadFileAsync(downloadUrl, installerName,bar,shd);
90+
await DownloadFileAsync(downloadUrl, installerName,bar,shd,jd);
9491
}
9592
else
9693
{
@@ -113,31 +110,32 @@ private static string GetInstallerName(string architecture)
113110
}
114111
}
115112

116-
private static async Task DownloadFileAsync(string url, string fileName,ProgressBar bar,ContentDialog shd)
113+
private static async Task DownloadFileAsync(string url, string fileName,ProgressBar bar,ContentDialog shd,Label jd)
117114
{
118115
try
119116
{
120117
var downloadOpt = new DownloadConfiguration()
121118
{
122119
BufferBlockSize = 10240,
123-
ChunkCount = 256,
120+
ChunkCount = 64,
124121
MaxTryAgainOnFailover = 5,
125122
ParallelDownload = true,
126123
ParallelCount = 10,
127124
Timeout = 1000,
128125
ClearPackageOnCompletionWithFailure = true,
129-
MinimumSizeOfChunking = 64,
126+
MinimumSizeOfChunking = 1024,
130127
ReserveStorageSpaceBeforeStartingDownload = true
131128
};
132129

133130
var downloader = new DownloadService(downloadOpt);
134131
downloader.DownloadProgressChanged += (sender, args) =>
135132
{
136133
// 确保事件被触发
137-
Console.WriteLine($"下载进度: {args.ProgressPercentage}%");
134+
// Console.WriteLine($"下载进度: {args.ProgressPercentage}%");
138135
Dispatcher.UIThread.InvokeAsync(() =>
139136
{
140137
bar.Value = args.ProgressPercentage;
138+
jd.Content = $"进度:{args.ProgressPercentage}%";
141139
});
142140
};
143141

Round.NET.AvaloniaApp.EncodeCalculator/Views/Controls/Update.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<Label Name="ThisVersionBox">当前版本:{Version}</Label>
1212
<Label Name="VersionBox">更新版本:{UpdateVersion}</Label>
1313
<Label Name="TimeBox">更新时间:{UpdateTime}</Label>
14+
<Label Name="jd">进度:0%</Label>
1415
<ProgressBar Name="ProgressBarBox" Margin="5"></ProgressBar>
1516
</StackPanel>
1617
</Grid>

Round.NET.AvaloniaApp.EncodeCalculator/Views/Controls/Update.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public Update()
1414
VersionBox.Content = VersionBox.Content.ToString().Replace("{UpdateVersion}",Models.Update.Update.GetNewVersion());
1515
TimeBox.Content = TimeBox.Content.ToString().Replace("{UpdateTime}",Models.Update.Update.GetNewVersionTime());
1616
ThisVersionBox.Content = ThisVersionBox.Content.ToString().Replace("{Version}",Models.Update.Update.GetCurrentVersion());
17-
Models.Update.Update.UpdateCore(ProgressBarBox,(ContentDialog)this.Parent);
17+
Models.Update.Update.UpdateCore(ProgressBarBox,(ContentDialog)this.Parent,jd);
1818
}
1919
}

0 commit comments

Comments
 (0)