Skip to content

Commit 30f9114

Browse files
committed
移除压缩组件
1 parent d7846bd commit 30f9114

33 files changed

+501
-279
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0" />
12+
</ItemGroup>
13+
14+
</Project>

src/c#/ConsoleApp1/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Microsoft.AspNetCore.SignalR.Client;
4+
5+
HubConnection _connection = new HubConnectionBuilder()
6+
.WithUrl("http://localhost:5000/UpgradeHub")
7+
.Build();
8+
9+
_connection.On<string, string>("11", (user, message) =>
10+
{
11+
Console.WriteLine($"{user}: {message}");
12+
});
13+
await _connection.StartAsync();
14+
15+
while (true)
16+
{
17+
var content = Console.ReadLine();
18+
if (content == "exit") break;
19+
}

src/c#/GeneralUpdate.Bowl/Bowl.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ private Bowl() { }
2121
private static void CreateStrategy()
2222
{
2323
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
24-
{
2524
_strategy = new WindowStrategy();
26-
}
27-
/*else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
28-
{
29-
_strategy = new LinuxStrategy();
30-
}*/
3125

3226
if (_strategy == null)
3327
throw new PlatformNotSupportedException("Unsupported operating system");

src/c#/GeneralUpdate.Client/GeneralUpdate.Client.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<LangVersion>13</LangVersion>
89
<PublishAot>true</PublishAot>
910
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
10-
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="SharpCompress" Version="0.38.0" />
15-
<PackageReference Include="System.Net.Http" Version="4.3.4" />
16-
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
14+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0" />
1715
</ItemGroup>
1816

1917
<ItemGroup>

src/c#/GeneralUpdate.Client/Program.cs

Lines changed: 64 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System.Diagnostics;
2-
using System.Text;
1+
using System.Text;
32
using GeneralUpdate.ClientCore;
4-
using GeneralUpdate.ClientCore.Hubs;
53
using GeneralUpdate.Common.Download;
64
using GeneralUpdate.Common.Internal;
75
using GeneralUpdate.Common.Internal.Bootstrap;
@@ -12,90 +10,84 @@ namespace GeneralUpdate.Client
1210
{
1311
internal class Program
1412
{
15-
private static void Main(string[] args)
13+
static async Task Main(string[] args)
1614
{
17-
/*Task.Run(async () =>
18-
{
19-
var source = @"D:\packet\app";
20-
var target = @"D:\packet\release";
21-
var patch = @"D:\packet\patch";
22-
23-
await DifferentialCore.Instance?.Clean(source, target, patch);
24-
await DifferentialCore.Instance?.Dirty(source, patch);
25-
});*/
26-
27-
Task.Run(async () =>
15+
try
2816
{
29-
try
17+
Console.WriteLine($"主程序初始化,{DateTime.Now}!");
18+
await Task.Delay(3000);
19+
var configinfo = new Configinfo
3020
{
31-
Console.WriteLine("主程序启动辣!!!!");
32-
await Task.Delay(3000);
33-
34-
var configinfo = new Configinfo
35-
{
36-
//configinfo.UpdateLogUrl = "https://www.baidu.com";
37-
ReportUrl = "http://127.0.0.1:5000/Upgrade/Report",
38-
UpdateUrl = "http://127.0.0.1:5000/Upgrade/Verification",
39-
AppName = "GeneralUpdate.Upgrad.exe",
40-
MainAppName = "GeneralUpdate.Client.exe",
41-
InstallPath = @"D:\迅雷下载\Client", //Thread.GetDomain().BaseDirectory,
42-
//configinfo.Bowl = "Generalupdate.CatBowl.exe";
43-
//当前客户端的版本号
44-
ClientVersion = "1.0.0.0",
45-
//当前升级端的版本号
46-
UpgradeClientVersion = "1.0.0.0",
47-
//平台
48-
Platform = PlatformType.Windwos,
49-
//产品id
50-
ProductId = "a77c9df5-45f8-4ee9-b3ad-b9431ce0b51c",
51-
//应用密钥
52-
AppSecretKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
53-
};
21+
//configinfo.UpdateLogUrl = "https://www.baidu.com";
22+
ReportUrl = "http://127.0.0.1:5000/Upgrade/Report",
23+
UpdateUrl = "http://127.0.0.1:5000/Upgrade/Verification",
24+
AppName = "GeneralUpdate.Upgrad.exe",
25+
MainAppName = "GeneralUpdate.Client.exe",
26+
InstallPath = @"D:\packet\installtest",
27+
//configinfo.Bowl = "Generalupdate.CatBowl.exe";
28+
//当前客户端的版本号
29+
ClientVersion = "1.0.0.0",
30+
//当前升级端的版本号
31+
UpgradeClientVersion = "1.0.0.0",
32+
//产品id
33+
ProductId = "a77c9df5-45f8-4ee9-b3ad-b9431ce0b51c",
34+
//应用密钥
35+
AppSecretKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
36+
};
37+
_ = new GeneralClientBootstrap() //单个或多个更新包下载通知事件
38+
.AddListenerMultiDownloadProgress(OnMultiDownloadProgressChanged)
39+
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
40+
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
41+
//单个或多个更新包下载完成
42+
.AddListenerMultiDownloadCompleted(OnMultiDownloadCompleted)
43+
//完成所有的下载任务通知
44+
.AddListenerMultiAllDownloadCompleted(OnMultiAllDownloadCompleted)
45+
//下载过程出现的异常通知
46+
.AddListenerMultiDownloadError(OnMultiDownloadError)
47+
//整个更新过程出现的任何问题都会通过这个事件通知
48+
.AddListenerException(OnException)
49+
.SetConfig(configinfo)
50+
.Option(UpdateOption.DownloadTimeOut, 60)
51+
.Option(UpdateOption.Encoding, Encoding.UTF8)
52+
.Option(UpdateOption.Format, Format.ZIP)
53+
.LaunchAsync();
54+
Console.WriteLine($"主程序已启动,{DateTime.Now}!");
55+
}
56+
catch (Exception e)
57+
{
58+
Console.WriteLine(e.Message + "\n" + e.StackTrace);
59+
}
5460

55-
_ = new GeneralClientBootstrap() //单个或多个更新包下载通知事件
56-
.AddListenerMultiDownloadProgress(OnMultiDownloadProgressChanged)
57-
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
58-
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
59-
//单个或多个更新包下载完成
60-
.AddListenerMultiDownloadCompleted(OnMultiDownloadCompleted)
61-
//完成所有的下载任务通知
62-
.AddListenerMultiAllDownloadCompleted(OnMultiAllDownloadCompleted)
63-
//下载过程出现的异常通知
64-
.AddListenerMultiDownloadError(OnMultiDownloadError)
65-
//整个更新过程出现的任何问题都会通过这个事件通知
66-
.AddListenerException(OnException)
67-
.SetConfig(configinfo)
68-
.Option(UpdateOption.DownloadTimeOut, 60)
69-
.Option(UpdateOption.Encoding, Encoding.UTF8)
70-
.Option(UpdateOption.Format, Format.ZIP)
71-
.LaunchAsync();
72-
}
73-
catch (Exception e)
74-
{
75-
Console.WriteLine(e.Message + "\n" + e.StackTrace);
76-
}
77-
});
78-
7961
/*var paramsOSS = new GlobalConfigInfoOSS();
8062
paramsOSS.Url = "http://192.168.50.203/versions.json";
8163
paramsOSS.CurrentVersion = "1.0.0.0";
8264
paramsOSS.VersionFileName = "versions.json";
8365
paramsOSS.AppName = "GeneralUpdate.Client.exe";
8466
paramsOSS.Encoding = Encoding.UTF8.WebName;
8567
GeneralClientOSS.Start(paramsOSS);*/
86-
8768

88-
/*IUpgradeHubService hub = new UpgradeHubService("http://localhost:5008/UpgradeHub", null, "GeneralUpdate");
89-
hub.AddListenerReceive(Receive);
90-
hub.StartAsync().Wait();*/
69+
/*var hub = new UpgradeHubService("http://localhost:5000/UpgradeHub"
70+
, null,"a84d21d4-3448-48d4-b418-12c5a7a039cd");
71+
hub.AddListenerReceive((message) =>
72+
{
73+
Debug.WriteLine(message);
74+
});
75+
await hub.StartAsync();*/
76+
77+
/*Task.Run(async () =>
78+
{
79+
var source = @"D:\packet\app";
80+
var target = @"D:\packet\release";
81+
var patch = @"D:\packet\patch";
82+
83+
await DifferentialCore.Instance?.Clean(source, target, patch);
84+
await DifferentialCore.Instance?.Dirty(source, patch);
85+
});*/
9186

9287
while (true)
9388
{
94-
var input = Console.ReadLine();
95-
if (input == "exit")
96-
{
97-
break;
98-
}
89+
var content = Console.ReadLine();
90+
if (content == "exit") break;
9991
}
10092
}
10193

src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using GeneralUpdate.Common.Internal.Event;
1717
using GeneralUpdate.Common.Internal.Strategy;
1818
using GeneralUpdate.Common.Shared.Object;
19+
using GeneralUpdate.Common.Shared.Object.Enum;
1920
using GeneralUpdate.Common.Shared.Service;
2021

2122
namespace GeneralUpdate.ClientCore;
@@ -71,7 +72,6 @@ public GeneralClientBootstrap SetConfig(Configinfo configInfo)
7172
AppSecretKey = configInfo.AppSecretKey,
7273
BlackFormats = configInfo.BlackFormats,
7374
BlackFiles = configInfo.BlackFiles,
74-
Platform = configInfo.Platform,
7575
ProductId = configInfo.ProductId,
7676
UpgradeClientVersion = configInfo.UpgradeClientVersion,
7777
Bowl = configInfo.Bowl
@@ -138,20 +138,22 @@ public GeneralClientBootstrap AddListenerException(Action<object, ExceptionEvent
138138

139139
private async Task ExecuteWorkflowAsync()
140140
{
141+
Debug.Assert(_configinfo != null);
142+
141143
//Request the upgrade information needed by the client and upgrade end, and determine if an upgrade is necessary.
142144
var mainResp = await VersionService.Validate(_configinfo.UpdateUrl
143145
, _configinfo.ClientVersion
144146
, AppType.ClientApp
145-
,_configinfo.AppSecretKey
146-
,_configinfo.Platform
147-
,_configinfo.ProductId);
147+
, _configinfo.AppSecretKey
148+
, GetPlatform()
149+
, _configinfo.ProductId);
148150

149151
var upgradeResp = await VersionService.Validate(_configinfo.UpdateUrl
150152
, _configinfo.UpgradeClientVersion
151153
, AppType.UpgradeApp
152-
,_configinfo.AppSecretKey
153-
,_configinfo.Platform
154-
,_configinfo.ProductId);
154+
, _configinfo.AppSecretKey
155+
, GetPlatform()
156+
, _configinfo.ProductId);
155157

156158
_configinfo.IsUpgradeUpdate = CheckUpgrade(upgradeResp);
157159
_configinfo.IsMainUpdate = CheckUpgrade(mainResp);
@@ -230,7 +232,27 @@ private async Task Download()
230232
}
231233
await manager.LaunchTasksAsync();
232234
}
233-
235+
236+
private int GetPlatform()
237+
{
238+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
239+
{
240+
return PlatformType.Windows;
241+
}
242+
243+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
244+
{
245+
return PlatformType.Linux;
246+
}
247+
248+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
249+
{
250+
return PlatformType.Mac;
251+
}
252+
253+
return -1;
254+
}
255+
234256
/// <summary>
235257
/// Check if there has been a recent update failure.(only windows)
236258
/// </summary>

src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<ItemGroup>
2828
<ProjectReference Include="..\GeneralUpdate.Common\GeneralUpdate.Common.csproj" />
2929
<ProjectReference Include="..\GeneralUpdate.Differential\GeneralUpdate.Differential.csproj" />
30-
<ProjectReference Include="..\GeneralUpdate.Zip\GeneralUpdate.Zip.csproj" />
3130
</ItemGroup>
3231

3332
<ItemGroup>

src/c#/GeneralUpdate.ClientCore/Hubs/IUpgradeHubService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IUpgradeHubService
99
/// Add a listener to receive upgrade information pushed from the server.
1010
/// </summary>
1111
/// <param name="receiveMessageCallback">string : group name , string : received message content.</param>
12-
public void AddListenerReceive(Action<string, string> receiveMessageCallback);
12+
public void AddListenerReceive(Action<string> receiveMessageCallback);
1313

1414
/// <summary>
1515
/// Add a listener to receive online and offline notifications.

src/c#/GeneralUpdate.ClientCore/Hubs/UpgradeHubService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace GeneralUpdate.ClientCore.Hubs;
1010
/// <param name="url">Subscription address, for example: http://127.0.0.1/UpgradeHub</param>
1111
/// <param name="token">ID4 authentication token string.</param>
1212
/// <param name="args">Parameters to be sent to the server upon connection (recommended as a JSON string).</param>
13-
public class UpgradeHubService(string url, string? token = null, string? args = null) : IUpgradeHubService
13+
public class UpgradeHubService(string url, string? token = null, string? appkey = null) : IUpgradeHubService
1414
{
1515
private const string Onlineflag = "Online";
1616
private const string ReceiveMessageflag = "ReceiveMessage";
@@ -21,13 +21,13 @@ public class UpgradeHubService(string url, string? token = null, string? args =
2121
if (!string.IsNullOrWhiteSpace(token))
2222
config.AccessTokenProvider = () => Task.FromResult(token);
2323

24-
if (!string.IsNullOrWhiteSpace(args))
25-
config.Headers.Add("client", args);
24+
if (!string.IsNullOrWhiteSpace(appkey))
25+
config.Headers.Add("appkey", appkey);
2626
})
2727
.WithAutomaticReconnect(new RandomRetryPolicy())
2828
.Build();
2929

30-
public void AddListenerReceive(Action<string, string> receiveMessageCallback)
30+
public void AddListenerReceive(Action<string> receiveMessageCallback)
3131
=> _connection?.On(ReceiveMessageflag, receiveMessageCallback);
3232

3333
public void AddListenerOnline(Action<string> onlineMessageCallback)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using GeneralUpdate.Common.Compress;
6+
using GeneralUpdate.Common.Internal;
7+
using GeneralUpdate.Common.Internal.Event;
8+
using GeneralUpdate.Common.Internal.Pipeline;
9+
10+
namespace GeneralUpdate.ClientCore.Pipeline;
11+
12+
public class CompressMiddleware : IMiddleware
13+
{
14+
public Task InvokeAsync(PipelineContext? context)
15+
{
16+
return Task.Run(() =>
17+
{
18+
try
19+
{
20+
var format = context.Get<string>("Format");
21+
var name = context.Get<string>("Name");
22+
var sourcePath = context.Get<string>("ZipFilePath");
23+
var patchPath = context.Get<string>("PatchPath");
24+
var encoding = context.Get<Encoding>("Encoding");
25+
var destinationPath = Path.Combine(patchPath, name);
26+
CompressProvider.Decompress(format,sourcePath,destinationPath, encoding);
27+
}
28+
catch (Exception e)
29+
{
30+
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
31+
}
32+
});
33+
}
34+
}

0 commit comments

Comments
 (0)