Skip to content

Commit 2b8a7d1

Browse files
committed
添加测试代码
1 parent 5e9018c commit 2b8a7d1

File tree

7 files changed

+92
-39
lines changed

7 files changed

+92
-39
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ private static void Main(string[] args)
2222
await DifferentialCore.Instance?.Dirty(source, patch);
2323
});*/
2424

25-
Task.Run(() =>
25+
Task.Run(async () =>
2626
{
27+
Console.WriteLine("主程序启动辣!!!!");
28+
await Task.Delay(3000);
29+
2730
var configinfo = new Configinfo();
28-
configinfo.UpdateLogUrl = "https://www.baidu.com";
31+
//configinfo.UpdateLogUrl = "https://www.baidu.com";
2932
configinfo.ReportUrl = "http://127.0.0.1:5008/Upgrade/Report";
3033
configinfo.UpdateUrl = "http://127.0.0.1:5008/Upgrade/Verification";
3134

32-
configinfo.AppName = "GeneralUpdate.Upgrade.exe";
35+
configinfo.AppName = "GeneralUpdate.Upgrad.exe";
3336
configinfo.MainAppName = "GeneralUpdate.Client.exe";
3437
configinfo.InstallPath = Thread.GetDomain().BaseDirectory;
3538

@@ -59,9 +62,8 @@ private static void Main(string[] args)
5962
.AddListenerException(OnException)
6063
.SetConfig(configinfo)
6164
.Option(UpdateOption.DownloadTimeOut, 60)
62-
.Option(UpdateOption.Encoding, Encoding.Default)
65+
.Option(UpdateOption.Encoding, Encoding.UTF8)
6366
.Option(UpdateOption.Format, Format.ZIP)
64-
.Option(UpdateOption.Drive, false)
6567
.LaunchAsync();
6668
});
6769

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

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,17 @@ private async Task ExecuteWorkflowAsync()
159159
_configinfo.Encoding = GetOption(UpdateOption.Encoding) ?? Encoding.Default;
160160
_configinfo.Format = GetOption(UpdateOption.Format) ?? ".zip";
161161
_configinfo.DownloadTimeOut = GetOption(UpdateOption.DownloadTimeOut) == 0 ? 60 : GetOption(UpdateOption.DownloadTimeOut);
162-
_configinfo.DriveEnabled = GetOption(UpdateOption.Drive);
162+
_configinfo.DriveEnabled = GetOption(UpdateOption.Drive) ?? false;
163163
_configinfo.TempPath = GeneralFileManager.GetTempDirectory("main_temp");
164164

165165
if (_configinfo.IsMainUpdate)
166166
{
167167
_configinfo.UpdateVersions = mainResp.Body.OrderBy(x => x.ReleaseDate).ToList();
168168
_configinfo.LastVersion = _configinfo.UpdateVersions.Last().Version;
169169

170+
//var failed = CheckFail(_configinfo.LastVersion);
171+
//if (failed) return;
172+
170173
//Initialize the process transfer parameter object.
171174
var processInfo = new ProcessInfo(_configinfo.MainAppName
172175
, _configinfo.InstallPath
@@ -220,6 +223,31 @@ private async Task Download()
220223
await manager.LaunchTasksAsync();
221224
}
222225

226+
/// <summary>
227+
/// Check if there has been a recent update failure.
228+
/// </summary>
229+
/// <param name="version"></param>
230+
/// <returns></returns>
231+
private bool CheckFail(string version)
232+
{
233+
/*
234+
Read the version number of the last failed upgrade from the system environment variables, then compare it with the version number of the current request.
235+
If it is less than or equal to the failed version number, do not perform the update.
236+
*/
237+
var fail = Environment.GetEnvironmentVariable("UpgradeFail", EnvironmentVariableTarget.User);
238+
if (string.IsNullOrEmpty(fail) || string.IsNullOrEmpty(version))
239+
return false;
240+
241+
var failVersion = new Version(fail);
242+
var lastVersion = new Version(version);
243+
return failVersion >= lastVersion;
244+
}
245+
246+
/// <summary>
247+
/// Determine whether the current version verification result indicates that an update is needed.
248+
/// </summary>
249+
/// <param name="response"></param>
250+
/// <returns></returns>
223251
private bool CheckUpgrade(VersionRespDTO? response)
224252
{
225253
if (response == null)
@@ -235,6 +263,27 @@ private bool CheckUpgrade(VersionRespDTO? response)
235263
return false;
236264
}
237265

266+
/// <summary>
267+
/// During the iteration process, if any version requires a mandatory update, all the update content from this request should be updated.
268+
/// </summary>
269+
/// <param name="versions"></param>
270+
/// <returns></returns>
271+
private bool CheckForcibly(List<VersionBodyDTO>? versions)
272+
{
273+
if (versions == null)
274+
return false;
275+
276+
foreach (var item in versions)
277+
{
278+
if (item.IsForcibly == true)
279+
{
280+
return true;
281+
}
282+
}
283+
284+
return false;
285+
}
286+
238287
/// <summary>
239288
/// User decides if update is required.
240289
/// </summary>
@@ -274,28 +323,10 @@ private void ClearEnvironmentVariable()
274323
}
275324
catch (Exception ex)
276325
{
277-
EventManager.Instance.Dispatch(this,
278-
new ExceptionEventArgs(ex,
279-
"Error: An unknown error occurred while deleting the environment variable."));
326+
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(ex, "Error: An unknown error occurred while deleting the environment variable."));
280327
}
281328
}
282329

283-
private bool CheckForcibly(List<VersionBodyDTO>? versions)
284-
{
285-
if (versions == null)
286-
return false;
287-
288-
foreach (var item in versions)
289-
{
290-
if (item.IsForcibly == true)
291-
{
292-
return true;
293-
}
294-
}
295-
296-
return false;
297-
}
298-
299330
protected override void ExecuteStrategy()=> throw new NotImplementedException();
300331

301332
protected override Task ExecuteStrategyAsync()=> throw new NotImplementedException();

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Threading;
45
using System.Threading.Tasks;
56
using GeneralUpdate.ClientCore.Pipeline;
67
using GeneralUpdate.Common.FileBasic;
@@ -88,7 +89,11 @@ public override void StartApp()
8889
if (File.Exists(appPath))
8990
{
9091
Environment.SetEnvironmentVariable("ProcessInfo", _configinfo.ProcessInfo, EnvironmentVariableTarget.User);
91-
Process.Start(appPath);
92+
Process.Start(new ProcessStartInfo
93+
{
94+
UseShellExecute = true,
95+
FileName = appPath
96+
});
9297
}
9398
}
9499
catch (Exception e)

src/c#/GeneralUpdate.Common/Internal/Bootstrap/AbstractBootstrap.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Concurrent;
1+
using System;
2+
using System.Collections.Concurrent;
23
using System.Diagnostics;
34
using System.Threading.Tasks;
45
using GeneralUpdate.Common.Internal.Strategy;
@@ -48,10 +49,17 @@ public TBootstrap Option<T>(UpdateOption<T> option, T value)
4849

4950
protected T? GetOption<T>(UpdateOption<T>? option)
5051
{
51-
Debug.Assert(option != null && _options.Count != 0);
52-
var val = _options[option];
53-
if (val != null) return (T)val.GetValue();
54-
return default;
52+
try
53+
{
54+
Debug.Assert(option != null && _options.Count != 0);
55+
var val = _options[option];
56+
if (val != null) return (T)val.GetValue();
57+
return default;
58+
}
59+
catch
60+
{
61+
return default;
62+
}
5563
}
5664
}
5765
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ public override void StartApp()
9797
{
9898
var appPath = Path.Combine(_configinfo.InstallPath, _configinfo.MainAppName);
9999
if (File.Exists(appPath))
100-
Process.Start(appPath);
101-
100+
{
101+
Process.Start(new ProcessStartInfo
102+
{
103+
FileName = appPath,
104+
UseShellExecute = true
105+
});
106+
}
107+
102108
Environment.SetEnvironmentVariable("ProcessInfo", null, EnvironmentVariableTarget.User);
103109
}
104110
catch (Exception e)

src/c#/GeneralUpdate.Differential/DifferentialCore.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ private async Task DirtyPatch(string appPath, string patchPath)
141141
try
142142
{
143143
if (!File.Exists(appPath) || !File.Exists(patchPath))
144-
{
145144
return;
146-
}
147145

148146
var newPath = Path.Combine(Path.GetDirectoryName(appPath)!, $"{Path.GetRandomFileName()}_{Path.GetFileName(appPath)}");
149147
await new BinaryHandler().Dirty(appPath, newPath, patchPath);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ private static void Main(string[] args)
5252
processor.AddCommand(new InstallDriverCommand(information));
5353
processor.ProcessCommands();*/
5454

55-
Task.Run(() =>
55+
Task.Run(async () =>
5656
{
57-
var jsonPath = @"D:\packet\test.json";
58-
var json = File.ReadAllText(jsonPath);
59-
Environment.SetEnvironmentVariable("ProcessInfo", json, EnvironmentVariableTarget.User);
57+
Console.WriteLine("升级程序启动辣!!!!");
58+
await Task.Delay(3000);
59+
60+
//var jsonPath = @"D:\packet\test.json";
61+
//var json = File.ReadAllText(jsonPath);
62+
//Environment.SetEnvironmentVariable("ProcessInfo", json, EnvironmentVariableTarget.User);
6063

6164
_ = new GeneralUpdateBootstrap() //单个或多个更新包下载通知事件
6265
.AddListenerMultiDownloadProgress(OnMultiDownloadProgressChanged)

0 commit comments

Comments
 (0)