feat: 准备增量更新包
This commit is contained in:
1 parent
02e8fbe045
commit
6bda6d7a89
2 files changed
+43
No files matched your search
@@ -0,0 +1,32 @@
|
||||
using MeloongCore.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MeloongCore {
|
||||
public static class DirectoryUtils {
|
||||
|
||||
/// <summary>
|
||||
/// 确保路径以 / 或 \ 结尾。
|
||||
/// </summary>
|
||||
public static string ToDirectoryFormat(string folder) => IsDirectoryFormat(folder) ? folder : folder + Path.DirectorySeparatorChar;
|
||||
|
||||
/// <summary>
|
||||
/// 检查路径是否以 / 或 \ 结尾。
|
||||
/// </summary>
|
||||
public static bool IsDirectoryFormat(string path) => path.EndsWithF("/") || path.EndsWithF("\\");
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件夹,或文件所在的文件夹。
|
||||
/// 支持长路径,文件夹已存在时不会抛出异常。
|
||||
/// </summary>
|
||||
public static void Create(string path) {
|
||||
if (!IsDirectoryFormat(path)) path = Path.GetDirectoryName(path);
|
||||
Directory.CreateDirectory(PathUtils.Shorten(path));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MeloongCore {
|
||||
@@ -12,7 +13,12 @@ namespace MeloongCore {
|
||||
/// <summary>
|
||||
/// 生成增量补丁文件:比较 <paramref name="oldFilePath"/> 和 <paramref name="newFilePath"/>,将补丁写入 <paramref name="deltaFilePath"/>。
|
||||
/// </summary>
|
||||
/// <exception cref="FileNotFoundException" />
|
||||
/// <exception cref="Win32Exception" />
|
||||
public static void Create(string oldFilePath, string newFilePath, string deltaFilePath) {
|
||||
if (!File.Exists(oldFilePath)) throw new FileNotFoundException($"旧文件不存在:{oldFilePath}", oldFilePath);
|
||||
if (!File.Exists(newFilePath)) throw new FileNotFoundException($"新文件不存在:{newFilePath}", newFilePath);
|
||||
DirectoryUtils.Create(deltaFilePath);
|
||||
// fileTypeSet:https://learn.microsoft.com/en-us/previous-versions/bb417345(v=msdn.10)?redirectedfrom=MSDN#file-type-sets (15L: DELTA_FILE_TYPE_SET_EXECUTABLES)
|
||||
// 131072L: IgnoreFileSizeLimit, 32u: Crc32
|
||||
if (!CreateDelta(15L, 131072L, 0L,
|
||||
@@ -23,7 +29,12 @@ namespace MeloongCore {
|
||||
/// <summary>
|
||||
/// 应用增量补丁文件:将 <paramref name="deltaFilePath"/> 补丁应用到 <paramref name="oldFilePath"/>,将结果写入 <paramref name="newFilePath"/>。
|
||||
/// </summary>
|
||||
/// <exception cref="FileNotFoundException" />
|
||||
/// <exception cref="Win32Exception" />
|
||||
public static void Apply(string oldFilePath, string deltaFilePath, string newFilePath) {
|
||||
if (!File.Exists(oldFilePath)) throw new FileNotFoundException($"旧文件不存在:{oldFilePath}", oldFilePath);
|
||||
if (!File.Exists(deltaFilePath)) throw new FileNotFoundException($"补丁文件不存在:{deltaFilePath}", deltaFilePath);
|
||||
DirectoryUtils.Create(newFilePath);
|
||||
// 1L: AllowLegacy
|
||||
if (!ApplyDelta(1L, PathUtils.Shorten(oldFilePath), PathUtils.Shorten(deltaFilePath), PathUtils.Shorten(newFilePath)))
|
||||
throw new Win32Exception();
|
||||
|
||||
Reference in new issue
Block a user