Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bowl/BowlSample/BowlSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Bowl" Version="9.1.4" />
<PackageReference Include="GeneralUpdate.Bowl" Version="10.4.6" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Client/ClientSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.ClientCore" Version="9.1.4" />
<PackageReference Include="GeneralUpdate.ClientCore" Version="10.4.6" />
</ItemGroup>

<ItemGroup>
Expand Down
35 changes: 27 additions & 8 deletions src/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
Console.WriteLine("当前运行目录:" + Thread.GetDomain().BaseDirectory);
var configinfo = new Configinfo
{
//configinfo.UpdateLogUrl = "https://www.baidu.com";
//UpdateLogUrl = "https://www.baidu.com",
ReportUrl = "http://127.0.0.1:5000/Upgrade/Report",
UpdateUrl = "http://127.0.0.1:5000/Upgrade/Verification",
AppName = "UpgradeSample.exe",
MainAppName = "ClientSample.exe",
InstallPath = Thread.GetDomain().BaseDirectory,
//configinfo.Bowl = "Generalupdate.CatBowl.exe";
//Bowl = "Generalupdate.CatBowl.exe",
//当前客户端的版本号
ClientVersion = "1.0.0.0",
//当前升级端的版本号
Expand All @@ -28,11 +28,11 @@
AppSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6",
//BlackFiles = new List<string> { "123.exe" },
//BlackFormats = new List<string> { "123.dll" },
//BlackDirectories = new List<string> { "123" },
//SkipDirectorys = new List<string> { "logs" },
//Scheme = "Bearer",
//Token = "..."
};
_ = await new GeneralClientBootstrap() //单个或多个更新包下载通知事件
_ = await new GeneralClientBootstrap()
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
//单个或多个更新包下载完成
Expand All @@ -43,6 +43,11 @@
.AddListenerMultiDownloadError(OnMultiDownloadError)
//整个更新过程出现的任何问题都会通过这个事件通知
.AddListenerException(OnException)
//服务端返回更新信息后的通知(可用于显示更新日志、版本信息等)
.AddListenerUpdateInfo(OnUpdateInfo)
//更新预检回调:返回 true 跳过本次更新,返回 false 继续自动更新
//(强制更新版本会忽略此回调)
.AddListenerUpdatePrecheck(OnUpdatePrecheck)
.SetConfig(configinfo)
.Option(UpdateOption.DownloadTimeOut, 60)
.Option(UpdateOption.Encoding, Encoding.Default)
Expand All @@ -58,7 +63,7 @@
void OnMultiDownloadError(object arg1, MultiDownloadErrorEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine($"{version.Version} {arg2.Exception}");
Console.WriteLine($"{version?.Version} {arg2.Exception}");
}

void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs arg2)
Expand All @@ -69,17 +74,31 @@ void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs
void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version.Version}, 下载完成!" : $"当前下载版本:{version.Version}, 下载失败!");
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version?.Version}, 下载完成!" : $"当前下载版本:{version?.Version}, 下载失败!");
}

void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine(
$"当前下载版本:{version.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
$"当前下载版本:{version?.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
}

void OnException(object arg1, ExceptionEventArgs arg2)
{
Console.WriteLine($"{arg2.Exception}");
}
}

void OnUpdateInfo(object arg1, UpdateInfoEventArgs arg2)
{
// arg2.Info 包含服务端返回的完整版本信息(VersionRespDTO)
Console.WriteLine($"服务端返回更新信息:Code={arg2.Info.Code}, 版本数量={arg2.Info.Body?.Count ?? 0}");
}

bool OnUpdatePrecheck(UpdateInfoEventArgs arg)
{
// 返回 true:跳过本次更新;返回 false:继续执行自动更新
// 可在此处添加自定义判断逻辑,例如检查磁盘空间、询问用户是否立即更新等
Console.WriteLine($"更新预检:发现 {arg.Info.Body?.Count ?? 0} 个可用版本,继续更新...");
return false; // false = 继续更新
}
2 changes: 1 addition & 1 deletion src/Compress/CompressSample/CompressSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Core" Version="9.1.5" />
<PackageReference Include="GeneralUpdate.Core" Version="10.4.6" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Diff/DiffSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Core" Version="9.1.4" />
<PackageReference Include="GeneralUpdate.Core" Version="10.4.6" />
</ItemGroup>

</Project>
14 changes: 11 additions & 3 deletions src/Diff/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
using GeneralUpdate.Differential;
using GeneralUpdate.Differential.Matchers;

// Binary differential update sample:
// - Clean: generate a patch from source (old) vs target (new)
// - Dirty: apply the patch to the app directory

var source = @"D:\packet\app";
var target = @"D:\packet\release";
var patch = @"D:\packet\patch";
var patch = @"D:\packet\patch";

// Generate binary differential patch (old → new)
await DifferentialCore.Clean(source, target, patch, new DefaultCleanStrategy(new DefaultCleanMatcher()));

await DifferentialCore.Instance?.Clean(source, target, patch);
await DifferentialCore.Instance?.Dirty(source, patch);
// Apply the patch to the running app directory
await DifferentialCore.Dirty(source, patch, new DefaultDirtyStrategy(new DefaultDirtyMatcher()));
2 changes: 1 addition & 1 deletion src/Drivelution/DrivelutionSample/DrivelutionSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Drivelution" Version="10.2.1" />
<PackageReference Include="GeneralUpdate.Drivelution" Version="10.4.6" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Extension/ExtensionSample/ExtensionSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Extension" Version="10.2.1" />
<PackageReference Include="GeneralUpdate.Extension" Version="10.4.6" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/OSS/OSSClientSample/OSSClientSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.ClientCore" Version="9.1.4" />
<PackageReference Include="GeneralUpdate.ClientCore" Version="10.4.6" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/OSS/OSSUpgradeSample/OSSUpgradeSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Core" Version="9.1.4" />
<PackageReference Include="GeneralUpdate.Core" Version="10.4.6" />
</ItemGroup>

</Project>
87 changes: 81 additions & 6 deletions src/Push/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,85 @@
using System.Diagnostics;
using GeneralUpdate.ClientCore.Hubs;
using GeneralUpdate.ClientCore.Hubs;

var hub = new UpgradeHubService("http://localhost:5000/UpgradeHub"
, null,"dfeb5833-975e-4afb-88f1-6278ee9aeff6");
/*
* PushSample — 演示 UpgradeHubService (SignalR 推送) 的完整用法
* PushSample — Demonstrates full usage of UpgradeHubService (SignalR push notifications)
*
* 使用前提 / Prerequisites:
* 1. 服务端已运行并注册了 UpgradeHub (MapHub<UpgradeHub>("/UpgradeHub"))
* The server is running and has registered UpgradeHub
* 2. 客户端 appkey 与服务端约定一致
* The client appkey matches the server-side agreement
*/

const string HubUrl = "http://localhost:5000/UpgradeHub";
const string AppKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6";

Console.WriteLine($"=== UpgradeHubService 推送示例 / Push Sample ===");
Console.WriteLine($"连接地址 / Hub URL: {HubUrl}");
Console.WriteLine($"应用密钥 / App Key: {AppKey}");
Console.WriteLine();

// UpgradeHubService 参数说明:
// url — SignalR Hub 订阅地址
// token — ID4 认证令牌(可选),例如 Bearer Token
// appkey — 客户端唯一标识,推荐使用 GUID,用于服务端识别推送目标
var hub = new UpgradeHubService(HubUrl, token: null, appkey: AppKey);

// 1. 订阅服务端推送的版本更新消息
// Subscribe to version update messages pushed by the server
// message: 服务端推送的内容,建议使用 JSON 格式的 Packet 对象字符串
hub.AddListenerReceive((message) =>
{
Debug.WriteLine(message);
Console.WriteLine($"[ReceiveMessage] 收到更新推送 / Received update push:");
Console.WriteLine($" {message}");
});
await hub.StartAsync();

// 2. 订阅在线 / 离线状态通知
// Subscribe to online/offline status notifications
hub.AddListenerOnline((info) =>
{
Console.WriteLine($"[Online] 在线状态变化 / Online status change: {info}");
});

// 3. 订阅重连成功通知
// Subscribe to reconnection notifications
hub.AddListenerReconnected((connectionId) =>
{
Console.WriteLine($"[Reconnected] 已重连 / Reconnected, connectionId={connectionId}");
return Task.CompletedTask;
});

// 4. 订阅连接关闭通知
// Subscribe to connection closed notifications
hub.AddListenerClosed((exception) =>
{
if (exception is not null)
Console.WriteLine($"[Closed] 连接因异常关闭 / Connection closed due to exception: {exception.Message}");
else
Console.WriteLine("[Closed] 连接已正常关闭 / Connection closed normally");
return Task.CompletedTask;
});

try
{
// 5. 建立 SignalR 连接,启动推送监听
// Establish SignalR connection and start listening for push notifications
Console.WriteLine("正在连接 Hub... / Connecting to Hub...");
await hub.StartAsync();
Console.WriteLine("已成功连接 Hub,等待服务端推送... / Connected. Waiting for server push...");
Console.WriteLine("按 Enter 键断开连接并退出 / Press Enter to disconnect and exit");
Console.ReadLine();
}
finally
{
// 6. 先暂停连接(可在应用进入后台时调用)
// First stop the connection gracefully (call when the app enters background)
Console.WriteLine("正在停止连接... / Stopping connection...");
await hub.StopAsync();

// 7. 彻底释放 Hub 实例(停止后不可再复用)
// Fully dispose the Hub instance (cannot be reused after disposal)
Console.WriteLine("正在释放资源... / Disposing resources...");
await hub.DisposeAsync();
Console.WriteLine("资源已释放 / Resources disposed.");
}
2 changes: 1 addition & 1 deletion src/Push/PushSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.ClientCore" Version="9.1.4" />
<PackageReference Include="GeneralUpdate.ClientCore" Version="10.4.6" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Server/DTOs/HttpResponseDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class HttpResponseDTO
/// <summary>
/// 响应消息内容
/// </summary>
public string Message { get; set; }
public string Message { get; set; } = string.Empty;

public static HttpResponseDTO Success(string message = "Success")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Server/DTOs/VerificationResultDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public record VerificationResultDTO
/// <summary>
/// 文件格式
/// </summary>
public string Format { get; set; }
public string Format { get; set; } = string.Empty;

/// <summary>
/// 文件大小
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
count++;
if (count > 2)
{
return HttpResponseDTO<IEnumerable<VerificationResultDTO>>.Success(null,"Upgrade completed.");
return HttpResponseDTO<IEnumerable<VerificationResultDTO>>.Success(Enumerable.Empty<VerificationResultDTO>(), "Upgrade completed.");
}

var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "packages", $"{packageName}.zip");
Expand Down
6 changes: 3 additions & 3 deletions src/Upgrade/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
void OnMultiDownloadError(object arg1, MultiDownloadErrorEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine($"{version.Version} {arg2.Exception}");
Console.WriteLine($"{version?.Version} {arg2.Exception}");
}

void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs arg2)
Expand All @@ -45,13 +45,13 @@ void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs
void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version.Version}, 下载完成!" : $"当前下载版本:{version.Version}, 下载失败!");
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version?.Version}, 下载完成!" : $"当前下载版本:{version?.Version}, 下载失败!");
}

void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine($"当前下载版本:{version.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
Console.WriteLine($"当前下载版本:{version?.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
}

void OnException(object arg1, ExceptionEventArgs arg2)
Expand Down
2 changes: 1 addition & 1 deletion src/Upgrade/UpgradeSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Core" Version="9.1.4" />
<PackageReference Include="GeneralUpdate.Core" Version="10.4.6" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/dotnet10_scripts/upgrade.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#:package GeneralUpdate.Core @9.5.10
#:package GeneralUpdate.Core @10.4.6

using GeneralUpdate.Common.Download;
using GeneralUpdate.Common.Internal;
Expand Down Expand Up @@ -36,7 +36,7 @@
void OnMultiDownloadError(object arg1, MultiDownloadErrorEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine($"{version.Version} {arg2.Exception}");
Console.WriteLine($"{version?.Version} {arg2.Exception}");
}

void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs arg2)
Expand All @@ -47,13 +47,13 @@ void OnMultiAllDownloadCompleted(object arg1, MultiAllDownloadCompletedEventArgs
void OnMultiDownloadCompleted(object arg1, MultiDownloadCompletedEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version.Version}, 下载完成!" : $"当前下载版本:{version.Version}, 下载失败!");
Console.WriteLine(arg2.IsComplated ? $"当前下载版本:{version?.Version}, 下载完成!" : $"当前下载版本:{version?.Version}, 下载失败!");
}

void OnMultiDownloadStatistics(object arg1, MultiDownloadStatisticsEventArgs arg2)
{
var version = arg2.Version as VersionInfo;
Console.WriteLine($"当前下载版本:{version.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
Console.WriteLine($"当前下载版本:{version?.Version},下载速度:{arg2.Speed},剩余下载时间:{arg2.Remaining},已下载大小:{arg2.BytesReceived},总大小:{arg2.TotalBytesToReceive}, 进度百分比:{arg2.ProgressPercentage}%");
}

void OnException(object arg1, ExceptionEventArgs arg2)
Expand Down
Loading
Loading