Skip to content

Commit d266c75

Browse files
committed
添加异常处理、修改命名错别字
1 parent d3a6533 commit d266c75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+345
-235
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
using System.IO;
33
using System.Runtime.InteropServices;
44
using System.Text.Json;
5-
using GeneralUpdate.Bowl.Internal;
65
using GeneralUpdate.Bowl.Strategys;
7-
using GeneralUpdate.Common.AOT.JsonContext;
6+
using GeneralUpdate.Common.Internal.JsonContext;
87
using GeneralUpdate.Common.Shared.Object;
98

109
namespace GeneralUpdate.Bowl;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Diagnostics;
33
using System.IO;
4+
using GeneralUpdate.Common.FileBasic;
45

56
namespace GeneralUpdate.Bowl.Strategys;
67

@@ -20,7 +21,7 @@ private void Startup(string appName, string arguments)
2021
{
2122
if (Directory.Exists(_parameter.FailDirectory))
2223
{
23-
Directory.Delete(_parameter.FailDirectory, true);
24+
StorageManager.DeleteDirectory(_parameter.FailDirectory);
2425
}
2526
Directory.CreateDirectory(_parameter.FailDirectory);
2627

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void CreateCrash()
6363
ProcdumpOutPutLines = OutputList
6464
};
6565
var failJsonPath = Path.Combine(_parameter.FailDirectory, _parameter.FailFileName);
66-
GeneralFileManager.CreateJson(failJsonPath, crash, CrashJsonContext.Default.Crash);
66+
StorageManager.CreateJson(failJsonPath, crash, CrashJsonContext.Default.Crash);
6767
}
6868

6969
/// <summary>
@@ -84,7 +84,7 @@ private void Export()
8484
private void Restore()
8585
{
8686
if (string.Equals(_parameter.WorkModel, WorkModel))
87-
GeneralFileManager.Restore(_parameter.BackupDirectory, _parameter.TargetPath);
87+
StorageManager.Restore(_parameter.BackupDirectory, _parameter.TargetPath);
8888
}
8989

9090
/// <summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static async Task Main(string[] args)
2424
UpdateUrl = "http://127.0.0.1:5000/Upgrade/Verification",
2525
AppName = "GeneralUpdate.Upgrad.exe",
2626
MainAppName = "GeneralUpdate.Client.exe",
27-
InstallPath = Thread.GetDomain().BaseDirectory, //@"D:\packet\installtest",
27+
InstallPath = Thread.GetDomain().BaseDirectory,
2828
//configinfo.Bowl = "Generalupdate.CatBowl.exe";
2929
//当前客户端的版本号
3030
ClientVersion = "1.0.0.0",

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
using System.Text.Json;
99
using System.Threading.Tasks;
1010
using GeneralUpdate.ClientCore.Strategys;
11-
using GeneralUpdate.Common.AOT.JsonContext;
1211
using GeneralUpdate.Common.FileBasic;
1312
using GeneralUpdate.Common.Download;
1413
using GeneralUpdate.Common.Internal;
1514
using GeneralUpdate.Common.Internal.Bootstrap;
1615
using GeneralUpdate.Common.Internal.Event;
16+
using GeneralUpdate.Common.Internal.JsonContext;
1717
using GeneralUpdate.Common.Internal.Strategy;
1818
using GeneralUpdate.Common.Shared.Object;
1919
using GeneralUpdate.Common.Shared.Object.Enum;
@@ -166,9 +166,9 @@ private async Task ExecuteWorkflowAsync()
166166
? 60
167167
: GetOption(UpdateOption.DownloadTimeOut);
168168
_configInfo.DriveEnabled = GetOption(UpdateOption.Drive) ?? false;
169-
_configInfo.TempPath = GeneralFileManager.GetTempDirectory("main_temp");
169+
_configInfo.TempPath = StorageManager.GetTempDirectory("main_temp");
170170
_configInfo.BackupDirectory = Path.Combine(_configInfo.InstallPath,
171-
$"{GeneralFileManager.DirectoryName}{_configInfo.ClientVersion}");
171+
$"{StorageManager.DirectoryName}{_configInfo.ClientVersion}");
172172

173173
if (_configInfo.IsMainUpdate)
174174
{
@@ -197,9 +197,9 @@ private async Task ExecuteWorkflowAsync()
197197
JsonSerializer.Serialize(processInfo, ProcessInfoJsonContext.Default.ProcessInfo);
198198
}
199199

200-
GeneralFileManager.Backup(_configInfo.InstallPath
200+
StorageManager.Backup(_configInfo.InstallPath
201201
, _configInfo.BackupDirectory
202-
, GeneralFileManager.SkipDirectorys);
202+
, StorageManager.SkipDirectorys);
203203

204204
StrategyFactory();
205205
switch (_configInfo.IsUpgradeUpdate)
@@ -246,6 +246,7 @@ private async Task Download()
246246
}
247247
catch (Exception exception)
248248
{
249+
Debug.WriteLine(exception.Message);
249250
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
250251
}
251252
}
@@ -400,11 +401,15 @@ private void ClearEnvironmentVariable()
400401
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
401402
{
402403
if (File.Exists("ProcessInfo.json"))
404+
{
405+
File.SetAttributes("ProcessInfo.json", FileAttributes.Normal);
403406
File.Delete("ProcessInfo.json");
407+
}
404408
}
405409
}
406410
catch (Exception ex)
407411
{
412+
Debug.WriteLine(ex);
408413
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(ex, "Error: An unknown error occurred while deleting the environment variable."));
409414
}
410415
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4-
using System.Diagnostics.Contracts;
54
using System.IO;
65
using System.Linq;
76
using System.Net;
8-
using System.Runtime.CompilerServices;
97
using System.Text.Json;
108
using System.Threading;
119
using System.Threading.Tasks;
12-
using GeneralUpdate.Common.AOT.JsonContext;
1310
using GeneralUpdate.Common.FileBasic;
14-
using GeneralUpdate.Common.Internal;
15-
using GeneralUpdate.Common.Internal.Event;
11+
using GeneralUpdate.Common.Internal.JsonContext;
1612
using GeneralUpdate.Common.Shared.Object;
1713

1814
namespace GeneralUpdate.ClientCore;
@@ -35,7 +31,7 @@ await Task.Run(() =>
3531
var versionsFilePath = Path.Combine(basePath, configGlobalConfigInfo.VersionFileName);
3632
DownloadFile(configGlobalConfigInfo.Url, versionsFilePath);
3733
if (!File.Exists(versionsFilePath)) return;
38-
var versions = GeneralFileManager.GetJson<List<VersionOSS>>(versionsFilePath, VersionOSSJsonContext.Default.ListVersionOSS);
34+
var versions = StorageManager.GetJson<List<VersionOSS>>(versionsFilePath, VersionOSSJsonContext.Default.ListVersionOSS);
3935
if (versions == null || versions.Count == 0) return;
4036
versions = versions.OrderByDescending(x => x.PubTime).ToList();
4137
var newVersion = versions.First();
@@ -54,6 +50,7 @@ await Task.Run(() =>
5450
}
5551
catch (Exception ex)
5652
{
53+
Debug.WriteLine(ex.Message);
5754
throw new Exception(ex.Message + "\n" + ex.StackTrace);
5855
}
5956
finally

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

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Threading.Tasks;
34
using Microsoft.AspNetCore.SignalR.Client;
45

@@ -38,13 +39,40 @@ public void AddListenerReconnected(Func<string?, Task>? reconnectedCallback)
3839

3940
public void AddListenerClosed(Func<Exception?, Task> closeCallback)
4041
=> _connection!.Closed += closeCallback;
41-
42+
4243
public async Task StartAsync()
43-
=> await _connection!.StartAsync();
44-
44+
{
45+
try
46+
{
47+
await _connection!.StartAsync();
48+
}
49+
catch (Exception e)
50+
{
51+
Debug.WriteLine(e);
52+
}
53+
}
54+
4555
public async Task StopAsync()
46-
=> await _connection!.StopAsync();
56+
{
57+
try
58+
{
59+
await _connection!.StopAsync();
60+
}
61+
catch (Exception e)
62+
{
63+
Debug.WriteLine(e);
64+
}
65+
}
4766

4867
public async Task DisposeAsync()
49-
=> await _connection!.DisposeAsync();
68+
{
69+
try
70+
{
71+
await _connection!.DisposeAsync();
72+
}
73+
catch (Exception e)
74+
{
75+
Debug.WriteLine(e);
76+
}
77+
}
5078
}

src/c#/GeneralUpdate.ClientCore/Pipeline/CompressMiddleware.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.Text;
45
using System.Threading.Tasks;
@@ -25,6 +26,7 @@ public Task InvokeAsync(PipelineContext? context)
2526
}
2627
catch (Exception e)
2728
{
29+
Debug.WriteLine(e);
2830
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
2931
}
3032
});
Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Security.Cryptography;
34
using System.Threading.Tasks;
45
using GeneralUpdate.Common.HashAlgorithms;
6+
using GeneralUpdate.Common.Internal;
7+
using GeneralUpdate.Common.Internal.Event;
58
using GeneralUpdate.Common.Internal.Pipeline;
69

710
namespace GeneralUpdate.ClientCore.Pipeline;
@@ -10,19 +13,36 @@ public class HashMiddleware : IMiddleware
1013
{
1114
public async Task InvokeAsync(PipelineContext context)
1215
{
13-
var path = context.Get<string>("ZipFilePath");
14-
var hash = context.Get<string>("Hash");
15-
var isVerify = await VerifyFileHash(path, hash);
16-
if (!isVerify) throw new CryptographicException("Hash verification failed .");
16+
try
17+
{
18+
var path = context.Get<string>("ZipFilePath");
19+
var hash = context.Get<string>("Hash");
20+
var isVerify = await VerifyFileHash(path, hash);
21+
if (!isVerify) throw new CryptographicException("Hash verification failed .");
22+
}
23+
catch (Exception exception)
24+
{
25+
Debug.WriteLine(exception.Message);
26+
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
27+
}
1728
}
1829

1930
private Task<bool> VerifyFileHash(string path, string hash)
2031
{
2132
return Task.Run(() =>
2233
{
23-
var hashAlgorithm = new Sha256HashAlgorithm();
24-
var hashSha256 = hashAlgorithm.ComputeHash(path);
25-
return string.Equals(hash, hashSha256, StringComparison.OrdinalIgnoreCase);
34+
try
35+
{
36+
var hashAlgorithm = new Sha256HashAlgorithm();
37+
var hashSha256 = hashAlgorithm.ComputeHash(path);
38+
return string.Equals(hash, hashSha256, StringComparison.OrdinalIgnoreCase);
39+
}
40+
catch (Exception exception)
41+
{
42+
Debug.WriteLine(exception.Message);
43+
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
44+
}
45+
return false;
2646
});
2747
}
2848
}
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.Threading.Tasks;
35
using GeneralUpdate.Common.FileBasic;
6+
using GeneralUpdate.Common.Internal;
7+
using GeneralUpdate.Common.Internal.Event;
48
using GeneralUpdate.Common.Internal.Pipeline;
59
using GeneralUpdate.Differential;
610

@@ -10,13 +14,21 @@ public class PatchMiddleware : IMiddleware
1014
{
1115
public async Task InvokeAsync(PipelineContext context)
1216
{
13-
var sourcePath = context.Get<string>("SourcePath");
14-
var targetPath = context.Get<string>("PatchPath");
15-
var blackFiles = context.Get<List<string>>("BlackFiles");
16-
var blackFileFormats = context.Get<List<string>>("BlackFileFormats");
17+
try
18+
{
19+
var sourcePath = context.Get<string>("SourcePath");
20+
var targetPath = context.Get<string>("PatchPath");
21+
var blackFiles = context.Get<List<string>>("BlackFiles");
22+
var blackFileFormats = context.Get<List<string>>("BlackFileFormats");
1723

18-
BlackListManager.Instance.AddBlackFiles(blackFiles);
19-
BlackListManager.Instance.AddBlackFileFormats(blackFileFormats);
20-
await DifferentialCore.Instance.Dirty(sourcePath, targetPath);
24+
BlackListManager.Instance.AddBlackFiles(blackFiles);
25+
BlackListManager.Instance.AddBlackFileFormats(blackFileFormats);
26+
await DifferentialCore.Instance.Dirty(sourcePath, targetPath);
27+
}
28+
catch (Exception exception)
29+
{
30+
Debug.WriteLine(exception.Message);
31+
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
32+
}
2133
}
2234
}

0 commit comments

Comments
 (0)