Skip to content

Commit 5e674e5

Browse files
committed
提交代码
1 parent 0e48200 commit 5e674e5

6 files changed

Lines changed: 268 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Remove="build.bat" />
12+
<None Remove="ClientSample.Desktop\**" />
13+
<None Remove="ClientSample\**" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="GeneralUpdate.ClientCore" Version="10.4.6" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Compile Remove="ClientSample.Desktop\**" />
22+
<Compile Remove="ClientSample\**" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<EmbeddedResource Remove="ClientSample.Desktop\**" />
27+
<EmbeddedResource Remove="ClientSample\**" />
28+
</ItemGroup>
29+
30+
</Project>

test_app/Client/ClientSample.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSample", "ClientSample.csproj", "{F90306BE-A032-4C38-BE1A-7E1CAFEFB633}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(SolutionProperties) = preSolution
14+
HideSolutionNode = FALSE
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{F90306BE-A032-4C38-BE1A-7E1CAFEFB633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{F90306BE-A032-4C38-BE1A-7E1CAFEFB633}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{F90306BE-A032-4C38-BE1A-7E1CAFEFB633}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{F90306BE-A032-4C38-BE1A-7E1CAFEFB633}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal

test_app/Client/Program.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System.Text;
2+
using GeneralUpdate.ClientCore;
3+
using GeneralUpdate.Common.Download;
4+
using GeneralUpdate.Common.Internal;
5+
using GeneralUpdate.Common.Internal.Bootstrap;
6+
using GeneralUpdate.Common.Shared.Object;
7+
8+
try
9+
{
10+
Console.WriteLine($"主程序初始化,{DateTime.Now}!");
11+
Console.WriteLine("当前运行目录:" + Thread.GetDomain().BaseDirectory);
12+
var configinfo = new Configinfo
13+
{
14+
//UpdateLogUrl = "https://www.baidu.com",
15+
ReportUrl = "http://127.0.0.1:5000/Upgrade/Report",
16+
UpdateUrl = "http://127.0.0.1:5000/Upgrade/Verification",
17+
AppName = "UpgradeSample.exe",
18+
MainAppName = "ClientSample.exe",
19+
InstallPath = Thread.GetDomain().BaseDirectory,
20+
//Bowl = "Generalupdate.CatBowl.exe",
21+
//当前客户端的版本号
22+
ClientVersion = "1.0.0.0",
23+
//当前升级端的版本号
24+
UpgradeClientVersion = "1.0.0.0",
25+
//产品id
26+
ProductId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a",
27+
//应用密钥
28+
AppSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6",
29+
//BlackFiles = new List<string> { "123.exe" },
30+
//BlackFormats = new List<string> { "123.dll" },
31+
//SkipDirectorys = new List<string> { "logs" },
32+
//Scheme = "Bearer",
33+
//Token = "..."
34+
};
35+
_ = await new GeneralClientBootstrap()
36+
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
37+
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
38+
//单个或多个更新包下载完成
39+
.AddListenerMultiDownloadCompleted(OnMultiDownloadCompleted)
40+
//完成所有的下载任务通知
41+
.AddListenerMultiAllDownloadCompleted(OnMultiAllDownloadCompleted)
42+
//下载过程出现的异常通知
43+
.AddListenerMultiDownloadError(OnMultiDownloadError)
44+
//整个更新过程出现的任何问题都会通过这个事件通知
45+
.AddListenerException(OnException)
46+
//服务端返回更新信息后的通知(可用于显示更新日志、版本信息等)
47+
.AddListenerUpdateInfo(OnUpdateInfo)
48+
//更新预检回调:返回 true 跳过本次更新,返回 false 继续自动更新
49+
//(强制更新版本会忽略此回调)
50+
.AddListenerUpdatePrecheck(OnUpdatePrecheck)
51+
.SetConfig(configinfo)
52+
.Option(UpdateOption.DownloadTimeOut, 60)
53+
.Option(UpdateOption.Encoding, Encoding.Default)
54+
.LaunchAsync();
55+
Console.WriteLine($"主程序已启动,{DateTime.Now}!");
56+
await Task.Delay(2000);
57+
}
58+
catch (Exception e)
59+
{
60+
Console.WriteLine(e.Message + "\n" + e.StackTrace);
61+
}
62+
63+
void OnMultiDownloadError(object arg1, MultiDownloadErrorEventArgs arg2)
64+
{
65+
var version = arg2.Version as VersionInfo;
66+
Console.WriteLine($"{version?.Version} {arg2.Exception}");
67+
}
68+
69+
void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs arg2)
70+
{
71+
Console.WriteLine(arg2.IsAllDownloadCompleted ? "所有的下载任务已完成!" : $"下载任务已失败!{arg2.FailedVersions.Count}");
72+
}
73+
74+
void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
75+
{
76+
var version = arg2.Version as VersionInfo;
77+
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version?.Version}, 下载完成!" : $"当前下载版本:{version?.Version}, 下载失败!");
78+
}
79+
80+
void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)
81+
{
82+
var version = arg2.Version as VersionInfo;
83+
Console.WriteLine(
84+
$"当前下载版本:{version?.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
85+
}
86+
87+
void OnException(object arg1, ExceptionEventArgs arg2)
88+
{
89+
Console.WriteLine($"{arg2.Exception}");
90+
}
91+
92+
void OnUpdateInfo(object arg1, UpdateInfoEventArgs arg2)
93+
{
94+
// arg2.Info 包含服务端返回的完整版本信息(VersionRespDTO)
95+
Console.WriteLine($"服务端返回更新信息:Code={arg2.Info.Code}, 版本数量={arg2.Info.Body?.Count ?? 0}");
96+
}
97+
98+
bool OnUpdatePrecheck(UpdateInfoEventArgs arg)
99+
{
100+
// 返回 true:跳过本次更新;返回 false:继续执行自动更新
101+
// 可在此处添加自定义判断逻辑,例如检查磁盘空间、询问用户是否立即更新等
102+
Console.WriteLine($"更新预检:发现 {arg.Info.Body?.Count ?? 0} 个可用版本,继续更新...");
103+
return false; // false = 继续更新
104+
}

test_app/Upgrade/Program.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using GeneralUpdate.Common.Download;
2+
using GeneralUpdate.Common.Internal;
3+
using GeneralUpdate.Common.Shared.Object;
4+
using GeneralUpdate.Core;
5+
6+
try
7+
{
8+
Console.WriteLine($"升级程序初始化,{DateTime.Now}!");
9+
Console.WriteLine("当前运行目录:" + Thread.GetDomain().BaseDirectory);
10+
_ = await new GeneralUpdateBootstrap()
11+
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
12+
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
13+
//单个或多个更新包下载完成
14+
.AddListenerMultiDownloadCompleted(OnMultiDownloadCompleted)
15+
//完成所有的下载任务通知
16+
.AddListenerMultiAllDownloadCompleted(OnMultiAllDownloadCompleted)
17+
//下载过程出现的异常通知
18+
.AddListenerMultiDownloadError(OnMultiDownloadError)
19+
//整个更新过程出现的任何问题都会通过这个事件通知
20+
.AddListenerException(OnException)
21+
//设置字段映射表,用于解析所有驱动包的信息的字符串
22+
//.SetFieldMappings(fieldMappingsCN)
23+
//是否开启驱动更新
24+
//.Option(UpdateOption.Drive, true)
25+
.LaunchAsync();
26+
Console.WriteLine($"升级程序已启动,{DateTime.Now}!");
27+
await Task.Delay(2000);
28+
}
29+
catch (Exception e)
30+
{
31+
Console.WriteLine(e.Message + "\n" + e.StackTrace);
32+
}
33+
34+
void OnMultiDownloadError(object arg1, MultiDownloadErrorEventArgs arg2)
35+
{
36+
var version = arg2.Version as VersionInfo;
37+
Console.WriteLine($"{version?.Version} {arg2.Exception}");
38+
}
39+
40+
void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs arg2)
41+
{
42+
Console.WriteLine(arg2.IsAllDownloadCompleted ? "所有的下载任务已完成!" : $"下载任务已失败!{arg2.FailedVersions.Count}");
43+
}
44+
45+
void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
46+
{
47+
var version = arg2.Version as VersionInfo;
48+
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version?.Version}, 下载完成!" : $"当前下载版本:{version?.Version}, 下载失败!");
49+
}
50+
51+
void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)
52+
{
53+
var version = arg2.Version as VersionInfo;
54+
Console.WriteLine($"当前下载版本:{version?.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
55+
}
56+
57+
void OnException(object arg1, ExceptionEventArgs arg2)
58+
{
59+
Console.WriteLine($"{arg2.Exception}");
60+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Remove="build.bat" />
12+
<None Remove="UpgradeSample.Desktop\**" />
13+
<None Remove="UpgradeSample\**" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="GeneralUpdate.Core" Version="10.4.6" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Compile Remove="UpgradeSample.Desktop\**" />
22+
<Compile Remove="UpgradeSample\**" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<EmbeddedResource Remove="UpgradeSample.Desktop\**" />
27+
<EmbeddedResource Remove="UpgradeSample\**" />
28+
</ItemGroup>
29+
30+
</Project>

test_app/Upgrade/UpgradeSample.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpgradeSample", "UpgradeSample.csproj", "{ECAB29C6-2EA8-458A-B822-DC0A4BDA93EE}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(SolutionProperties) = preSolution
14+
HideSolutionNode = FALSE
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{ECAB29C6-2EA8-458A-B822-DC0A4BDA93EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{ECAB29C6-2EA8-458A-B822-DC0A4BDA93EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{ECAB29C6-2EA8-458A-B822-DC0A4BDA93EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{ECAB29C6-2EA8-458A-B822-DC0A4BDA93EE}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal

0 commit comments

Comments
 (0)