Skip to content

Commit

Permalink
chore: merge code
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Jan 10, 2024
2 parents 59081fe + e360af3 commit df60351
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 77 deletions.
65 changes: 33 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,6 @@



**GeneralUpdate.SystemService发布/部署**

GeneralUpdate.SystemService是一个windows系统服务,并不是部署在服务端的web api。它的主要作用是监听更新过程,以及更新崩溃之后还原。

**发布:**

推荐发布Single file,如果想发布AOT版本需要移除源码中映射代码。

```shell
dotnet publish -r win-x64 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true --self-contained true
```

**创建/部署windows服务:**

```shell
sc create MyWorkerService binPath="C:\your_path\GeneralUpdate.SystemService.exe"
```

**启动已部署的windows服务:**

```shell
sc start GeneralUpdate.SystemService
```

**删除已部署的windows服务:**

```shell
sc delete GeneralUpdate.SystemService
```



## 2.帮助文档 ##

- 讲解视频: https://www.bilibili.com/video/BV1aX4y137dd
Expand Down Expand Up @@ -131,3 +99,36 @@ sc delete GeneralUpdate.SystemService
| 树莓派(IoT) | 待验证 |
| 麒麟V10(飞腾S2500) | 支持 |
| 麒麟V10(x64) | 支持 |



## 6.GeneralUpdate.SystemService发布/部署

GeneralUpdate.SystemService是一个windows系统服务,并不是部署在服务端的web api。它的主要作用是监听更新过程,以及更新崩溃之后还原。

**发布:**

推荐发布Single file,如果想发布AOT版本需要移除源码中映射代码。

```shell
dotnet publish -r win-x64 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true --self-contained true
```

**创建/部署windows服务:**

```shell
sc create MyWorkerService binPath="C:\your_path\GeneralUpdate.SystemService.exe"
```

**启动已部署的windows服务:**

```shell
sc start GeneralUpdate.SystemService
```

**删除已部署的windows服务:**

```shell
sc delete GeneralUpdate.SystemService
```

65 changes: 33 additions & 32 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,6 @@



**GeneralUpdate.SystemService Publish/Deploy**

GeneralUpdate.SystemService is a Windows system service, not a web API deployed on the server. Its main purpose is to listen for the update process and restore after an update crash.

**Publish:**

It is recommended to release a single file, if you want to release the AOT version, you need to remove the mapping code from the source code.

```shell
dotnet publish -r win-x64 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true --self-contained true
```

**Create/deploy Windows services:**

```shell
sc create MyWorkerService binPath="C:\your_path\GeneralUpdate.SystemService.exe"
```

**Start the deployed Windows service:**

```shell
sc start GeneralUpdate.SystemService
```

**Delete the deployed Windows service:**

```shell
sc delete GeneralUpdate.SystemService
```



### 2.Help documentation ###

- explainer video: https://www.bilibili.com/video/BV1aX4y137dd
Expand Down Expand Up @@ -126,3 +94,36 @@ sc delete GeneralUpdate.SystemService
| raspberry pie | Not currently supported |
| Kylin V10 (FT-S2500) | yes |
| Kylin V10 (x64) | yes |



## GeneralUpdate.SystemService Publish/Deploy

GeneralUpdate.SystemService is a Windows system service, not a web API deployed on the server. Its main purpose is to listen for the update process and restore after an update crash.

**Publish:**

It is recommended to release a single file, if you want to release the AOT version, you need to remove the mapping code from the source code.

```shell
dotnet publish -r win-x64 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true --self-contained true
```

**Create/deploy Windows services:**

```shell
sc create MyWorkerService binPath="C:\your_path\GeneralUpdate.SystemService.exe"
```

**Start the deployed Windows service:**

```shell
sc start GeneralUpdate.SystemService
```

**Delete the deployed Windows service:**

```shell
sc delete GeneralUpdate.SystemService
```

3 changes: 2 additions & 1 deletion src/c#/GeneralUpdate.Core/Domain/Entity/Configinfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;

namespace GeneralUpdate.Core.Domain.Entity
{
Expand All @@ -15,7 +16,7 @@ public Configinfo(int appType, string appName, string appSecretKey, string clien
ClientVersion = clientVersion ?? throw new ArgumentNullException(nameof(clientVersion));
UpdateUrl = updateUrl ?? throw new ArgumentNullException(nameof(updateUrl));
UpdateLogUrl = updateLogUrl ?? throw new ArgumentNullException(nameof(updateLogUrl));
InstallPath = installPath ?? throw new ArgumentNullException(nameof(installPath));
InstallPath = installPath ?? Directory.GetCurrentDirectory();
MainUpdateUrl = mainUpdateUrl ?? throw new ArgumentNullException(nameof(mainUpdateUrl));
MainAppName = mainAppName ?? throw new ArgumentNullException(nameof(mainAppName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class WindowsStrategy : AbstractStrategy

#region Public Methods

public override void Create<T>(T parameter)=> Packet = parameter as Packet;
public override void Create<T>(T parameter) => Packet = parameter as Packet;

public override void Execute()
{
Expand All @@ -44,7 +44,7 @@ public override void Execute()
{
var patchPath = FileUtil.GetTempDirectory(PATCHS);
var zipFilePath = Path.Combine(Packet.TempPath, $"{version.Name}{Packet.Format}");
var context = new BaseContext.Builder()
.SetVersion(version)
.SetZipfilePath(zipFilePath)
Expand All @@ -65,6 +65,7 @@ public override void Execute()
UseMiddleware<PatchMiddleware>();
await pipelineBuilder.Build();
}
if (!string.IsNullOrEmpty(Packet.UpdateLogUrl)) Process.Start("explorer.exe", Packet.UpdateLogUrl);
}
Clear();
StartApp(Packet.AppName, Packet.AppType);
Expand All @@ -81,13 +82,12 @@ public override bool StartApp(string appName, int appType)
{
try
{
if (!string.IsNullOrEmpty(Packet.UpdateLogUrl)) Process.Start("explorer.exe", Packet.UpdateLogUrl);
var path = Path.Combine(Packet.InstallPath, appName);
switch (appType)
{
case AppType.ClientApp:
Environment.SetEnvironmentVariable("ProcessBase64", Packet.ProcessBase64, EnvironmentVariableTarget.User);
WaitForProcessToStart(path, 20, ()=> WillMessageManager.Instance.Check());
WaitForProcessToStart(path, 20, () => WillMessageManager.Instance.Check());
break;

case AppType.UpgradeApp:
Expand All @@ -109,7 +109,7 @@ public override bool StartApp(string appName, int appType)

public override string GetPlatform() => PlatformType.Windows;

#endregion Public Methods
#endregion Public Methods

#region Private Methods

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace GeneralUpdate.Differential.ContentProvider
{
Expand All @@ -24,6 +24,8 @@ public class FileNode

public int RightType { get; set; }

public string RelativePath { get; set; }

#endregion Public Properties

#region Constructors
Expand Down
17 changes: 11 additions & 6 deletions src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GeneralUpdate.Core.HashAlgorithms;
using GeneralUpdate.Core.HashAlgorithms;
using GeneralUpdate.Differential.Common;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -48,8 +48,8 @@ public async Task<IEnumerable<FileNode>> Except(string leftPath, string rightPat
{
var leftFileNodes = Read(leftPath);
var rightFileNodes = Read(rightPath);
var rightNodeDic = rightFileNodes.ToDictionary(x => x.Name, x => x);
var filesOnlyInLeft = leftFileNodes.Where(f => !rightNodeDic.ContainsKey(f.Name)).ToList();
var rightNodeDic = rightFileNodes.ToDictionary(x => x.RelativePath, x => x);
var filesOnlyInLeft = leftFileNodes.Where(f => !rightNodeDic.ContainsKey(f.RelativePath)).ToList();
return filesOnlyInLeft;
});
}
Expand All @@ -62,22 +62,27 @@ public async Task<IEnumerable<FileNode>> Except(string leftPath, string rightPat
/// Recursively read all files in the folder path.
/// </summary>
/// <param name="path">folder path.</param>
/// <param name="rootPath">folder root path.</param>
/// <returns>different chalders.</returns>
private IEnumerable<FileNode> Read(string path)
private IEnumerable<FileNode> Read(string path, string rootPath = null)
{
var resultFiles = new List<FileNode>();
if (string.IsNullOrEmpty(rootPath)) rootPath = path;
if (!rootPath.EndsWith("/")) rootPath += "/";
Uri rootUri = new Uri(rootPath);
foreach (var subPath in Directory.GetFiles(path))
{
if (IsMatchBlacklist(subPath)) continue;

var hashAlgorithm = new Sha256HashAlgorithm();
var hash = hashAlgorithm.ComputeHash(subPath);
var subFileInfo = new FileInfo(subPath);
resultFiles.Add(new FileNode() { Id = GetId(), Path = path, Name = subFileInfo.Name, Hash = hash, FullName = subFileInfo.FullName });
Uri subUri = new Uri(subFileInfo.FullName);
resultFiles.Add(new FileNode() { Id = GetId(), Path = path, Name = subFileInfo.Name, Hash = hash, FullName = subFileInfo.FullName, RelativePath = rootUri.MakeRelativeUri(subUri).ToString() });
}
foreach (var subPath in Directory.GetDirectories(path))
{
resultFiles.AddRange(Read(subPath));
resultFiles.AddRange(Read(subPath, rootPath));
}
return resultFiles;
}
Expand Down

0 comments on commit df60351

Please sign in to comment.