Skip to content

Commit 26a3fce

Browse files
authored
Merge pull request #81 from yangxuilyx/master
Fix client update updater bugs
2 parents 413dff9 + 91d8c3f commit 26a3fce

File tree

9 files changed

+104
-55
lines changed

9 files changed

+104
-55
lines changed

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public GeneralClientBootstrap SetConfig(Configinfo configInfo)
7979
ProductId = configInfo.ProductId,
8080
UpgradeClientVersion = configInfo.UpgradeClientVersion,
8181
Bowl = configInfo.Bowl,
82+
SkipDirectorys = configInfo.SkipDirectorys
8283
Scheme = configInfo.Scheme,
8384
Token = configInfo.Token
8485
};
@@ -178,7 +179,7 @@ private async Task ExecuteWorkflowAsync()
178179

179180
if (_configInfo.IsMainUpdate)
180181
{
181-
_configInfo.UpdateVersions = mainResp.Body.OrderBy(x => x.ReleaseDate).ToList();
182+
_configInfo.UpdateVersions = upgradeResp.Body.OrderBy(x => x.ReleaseDate).ToList();
182183
_configInfo.LastVersion = _configInfo.UpdateVersions.Last().Version;
183184

184185
var failed = CheckFail(_configInfo.LastVersion);
@@ -205,9 +206,11 @@ private async Task ExecuteWorkflowAsync()
205206
JsonSerializer.Serialize(processInfo, ProcessInfoJsonContext.Default.ProcessInfo);
206207
}
207208

209+
var skipDirectorys = StorageManager.SkipDirectorys;
210+
skipDirectorys.AddRange(_configInfo.SkipDirectorys);
208211
StorageManager.Backup(_configInfo.InstallPath
209212
, _configInfo.BackupDirectory
210-
, StorageManager.SkipDirectorys);
213+
, skipDirectorys);
211214

212215
StrategyFactory();
213216
switch (_configInfo.IsUpgradeUpdate)
@@ -235,7 +238,7 @@ private async Task ExecuteWorkflowAsync()
235238
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
236239
}
237240
}
238-
241+
239242
private async Task Download()
240243
{
241244
try
@@ -270,7 +273,7 @@ private int GetPlatform()
270273
{
271274
return PlatformType.Linux;
272275
}
273-
276+
274277
return -1;
275278
}
276279

@@ -288,7 +291,7 @@ private bool CheckFail(string version)
288291
var fail = Environment.GetEnvironmentVariable("UpgradeFail", EnvironmentVariableTarget.User);
289292
if (string.IsNullOrEmpty(fail) || string.IsNullOrEmpty(version))
290293
return false;
291-
294+
292295
var failVersion = new Version(fail);
293296
var lastVersion = new Version(version);
294297
return failVersion >= lastVersion;
@@ -306,20 +309,20 @@ private bool CheckUpgrade(VersionRespDTO? response)
306309

307310
if (response.Code == 200)
308311
return response.Body.Count > 0;
309-
312+
310313
return false;
311314
}
312-
315+
313316
/// <summary>
314317
/// During the iteration process, if any version requires a mandatory update, all the update content from this request should be updated.
315318
/// </summary>
316319
/// <param name="versions"></param>
317320
/// <returns></returns>
318321
private bool CheckForcibly(List<VersionInfo>? versions)
319322
{
320-
if (versions == null)
323+
if (versions == null)
321324
return false;
322-
325+
323326
foreach (var item in versions)
324327
{
325328
if (item.IsForcibly == true)
@@ -330,7 +333,7 @@ private bool CheckForcibly(List<VersionInfo>? versions)
330333

331334
return false;
332335
}
333-
336+
334337
/// <summary>
335338
/// User decides if update is required.
336339
/// </summary>
@@ -343,9 +346,9 @@ private bool CanSkip(bool isForcibly)
343346

344347
private void CallSmallBowlHome(string processName)
345348
{
346-
if(string.IsNullOrWhiteSpace(processName))
349+
if (string.IsNullOrWhiteSpace(processName))
347350
return;
348-
351+
349352
try
350353
{
351354
var processes = Process.GetProcessesByName(processName);
@@ -383,14 +386,14 @@ private void ExecuteCustomOptions()
383386
{
384387
var exception = new Exception($"{nameof(option)}Execution failure!");
385388
var args = new ExceptionEventArgs(exception, exception.Message);
386-
EventManager.Instance.Dispatch(this,args);
389+
EventManager.Instance.Dispatch(this, args);
387390
}
388391
}
389392
catch (Exception exception)
390393
{
391394
Debug.WriteLine(exception.Message);
392395
var args = new ExceptionEventArgs(exception, $"{nameof(option)}Execution failure!");
393-
EventManager.Instance.Dispatch(this,args);
396+
EventManager.Instance.Dispatch(this, args);
394397
}
395398
}
396399
}
@@ -422,9 +425,9 @@ private void ClearEnvironmentVariable()
422425
}
423426
}
424427

425-
protected override void ExecuteStrategy()=> throw new NotImplementedException();
426-
427-
protected override Task ExecuteStrategyAsync()=> throw new NotImplementedException();
428+
protected override void ExecuteStrategy() => throw new NotImplementedException();
429+
430+
protected override Task ExecuteStrategyAsync() => throw new NotImplementedException();
428431

429432
protected override GeneralClientBootstrap StrategyFactory()
430433
{
@@ -438,7 +441,7 @@ protected override GeneralClientBootstrap StrategyFactory()
438441
_strategy?.Create(_configInfo!);
439442
return this;
440443
}
441-
444+
442445
private GeneralClientBootstrap AddListener<TArgs>(Action<object, TArgs> callbackAction) where TArgs : EventArgs
443446
{
444447
Debug.Assert(callbackAction != null);
@@ -457,6 +460,6 @@ private void OnMultiDownloadError(object sender, MultiDownloadErrorEventArgs e)
457460

458461
private void OnMultiAllDownloadCompleted(object sender, MultiAllDownloadCompletedEventArgs e)
459462
=> EventManager.Instance.Dispatch(sender, e);
460-
463+
461464
#endregion Private Methods
462465
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ public async Task InvokeAsync(PipelineContext context)
2020
var targetPath = context.Get<string>("PatchPath");
2121
var blackFiles = context.Get<List<string>>("BlackFiles");
2222
var blackFileFormats = context.Get<List<string>>("BlackFileFormats");
23+
var skipDirectorys = context.Get<List<string>>("SkipDirectorys");
2324

2425
BlackListManager.Instance.AddBlackFiles(blackFiles);
2526
BlackListManager.Instance.AddBlackFileFormats(blackFileFormats);
27+
BlackListManager.Instance.AddSkipDirectorys(skipDirectorys);
2628
await DifferentialCore.Instance.Dirty(sourcePath, targetPath);
2729
}
2830
catch (Exception exception)

src/c#/GeneralUpdate.ClientCore/Strategys/LinuxStrategy.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class LinuxStrategy : AbstractStrategy
2222
private GlobalConfigInfo _configinfo = new();
2323
private const string ProcessInfoFileName = "ProcessInfo.json";
2424

25-
public override void Create(GlobalConfigInfo parameter)=> _configinfo = parameter;
25+
public override void Create(GlobalConfigInfo parameter) => _configinfo = parameter;
2626

2727
public override async Task ExecuteAsync()
2828
{
@@ -47,8 +47,9 @@ public override async Task ExecuteAsync()
4747
//patch middleware
4848
context.Add("SourcePath", _configinfo.InstallPath);
4949
context.Add("PatchPath", patchPath);
50-
context.Add("BlackFiles", BlackListManager.Instance.BlackFiles);
51-
context.Add("BlackFileFormats", BlackListManager.Instance.BlackFileFormats);
50+
context.Add("BlackFiles", _configinfo.BlackFiles);
51+
context.Add("BlackFileFormats", _configinfo.BlackFormats);
52+
context.Add("SkipDirectorys", _configinfo.SkipDirectorys);
5253

5354
var pipelineBuilder = new PipelineBuilder(context)
5455
.UseMiddleware<PatchMiddleware>()
@@ -97,7 +98,7 @@ public override void StartApp()
9798
{
9899
if (File.Exists(ProcessInfoFileName))
99100
{
100-
File.SetAttributes(ProcessInfoFileName,FileAttributes.Normal);
101+
File.SetAttributes(ProcessInfoFileName, FileAttributes.Normal);
101102
File.Delete(ProcessInfoFileName);
102103
}
103104

src/c#/GeneralUpdate.ClientCore/Strategys/WindowsStrategy.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class WindowsStrategy : AbstractStrategy
2121
{
2222
private GlobalConfigInfo _configinfo = new();
2323

24-
public override void Create(GlobalConfigInfo parameter)=> _configinfo = parameter;
24+
public override void Create(GlobalConfigInfo parameter) => _configinfo = parameter;
2525

2626
public override async Task ExecuteAsync()
2727
{
@@ -46,8 +46,9 @@ public override async Task ExecuteAsync()
4646
//patch middleware
4747
context.Add("SourcePath", _configinfo.InstallPath);
4848
context.Add("PatchPath", patchPath);
49-
context.Add("BlackFiles", BlackListManager.Instance.BlackFiles);
50-
context.Add("BlackFileFormats", BlackListManager.Instance.BlackFileFormats);
49+
context.Add("BlackFiles", _configinfo.BlackFiles);
50+
context.Add("BlackFileFormats", _configinfo.BlackFormats);
51+
context.Add("SkipDirectorys", _configinfo.SkipDirectorys);
5152

5253
var pipelineBuilder = new PipelineBuilder(context)
5354
.UseMiddleware<PatchMiddleware>()

src/c#/GeneralUpdate.Common/FileBasic/BlackListManager.cs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.IO;
3+
using System.Linq;
34
using GeneralUpdate.Common.Shared.Object;
45

56
namespace GeneralUpdate.Common.FileBasic;
@@ -8,7 +9,7 @@ public class BlackListManager
89
{
910
private static readonly object LockObject = new object();
1011
private static BlackListManager? _instance;
11-
12+
1213
private static readonly List<string> _blackFileFormats =
1314
[
1415
".patch",
@@ -21,6 +22,8 @@ public class BlackListManager
2122

2223
private static readonly List<string> _blackFiles = ["Newtonsoft.Json.dll"];
2324

25+
private static readonly List<string> _skipDirectorys = [];
26+
2427
private BlackListManager() { }
2528

2629
public static BlackListManager? Instance
@@ -44,56 +47,83 @@ public static BlackListManager? Instance
4447

4548
public IReadOnlyList<string> BlackFileFormats => _blackFileFormats.AsReadOnly();
4649
public IReadOnlyList<string> BlackFiles => _blackFiles.AsReadOnly();
47-
50+
51+
public IReadOnlyList<string> SkipDirectorys = _skipDirectorys.AsReadOnly();
52+
4853
public void AddBlackFileFormats(List<string>? formats)
4954
{
50-
if(formats == null)
55+
if (formats == null)
5156
return;
52-
57+
5358
foreach (var format in formats)
5459
{
5560
AddBlackFileFormat(format);
5661
}
5762
}
58-
63+
5964
public void AddBlackFileFormat(string format)
6065
{
61-
if(string.IsNullOrWhiteSpace(format))
66+
if (string.IsNullOrWhiteSpace(format))
6267
return;
63-
68+
6469
if (!_blackFileFormats.Contains(format))
6570
{
6671
_blackFileFormats.Add(format);
6772
}
6873
}
69-
74+
7075
public void AddBlackFiles(List<string>? fileNames)
7176
{
72-
if(fileNames == null)
77+
if (fileNames == null)
7378
return;
74-
79+
7580
foreach (var fileName in fileNames)
7681
{
7782
AddBlackFile(fileName);
7883
}
7984
}
80-
85+
8186
public void AddBlackFile(string fileName)
8287
{
83-
if(string.IsNullOrWhiteSpace(fileName))
88+
if (string.IsNullOrWhiteSpace(fileName))
8489
return;
85-
90+
8691
if (!_blackFiles.Contains(fileName))
8792
{
8893
_blackFiles.Add(fileName);
8994
}
9095
}
9196

97+
public void AddSkipDirectorys(List<string>? directorys)
98+
{
99+
if (directorys == null)
100+
return;
101+
foreach (var directory in directorys)
102+
{
103+
AddSkipDirectory(directory);
104+
}
105+
}
106+
107+
public void AddSkipDirectory(string directory)
108+
{
109+
if (string.IsNullOrWhiteSpace(directory))
110+
return;
111+
if (!_skipDirectorys.Contains(directory))
112+
{
113+
_skipDirectorys.Add(directory);
114+
}
115+
}
116+
92117
public bool IsBlacklisted(string relativeFilePath)
93118
{
94119
var fileName = Path.GetFileName(relativeFilePath);
95120
var fileExtension = Path.GetExtension(relativeFilePath);
96121

97122
return _blackFiles.Contains(fileName) || _blackFileFormats.Contains(fileExtension);
98123
}
124+
125+
public bool IsSkipDirectory(string directory)
126+
{
127+
return _skipDirectorys.Any(directory.Contains);
128+
}
99129
}

0 commit comments

Comments
 (0)