*
This commit is contained in:
1 parent
680cc61869
commit
44d59806ee
3 files changed
+11
-6
No files matched your search
@@ -11,8 +11,8 @@ public static class MsDelta {
|
|||||||
/// <exception cref="FileNotFoundException" />
|
/// <exception cref="FileNotFoundException" />
|
||||||
/// <exception cref="Win32Exception" />
|
/// <exception cref="Win32Exception" />
|
||||||
public static void Create(string oldFilePath, string newFilePath, string deltaFilePath) {
|
public static void Create(string oldFilePath, string newFilePath, string deltaFilePath) {
|
||||||
if (!File.Exists(oldFilePath)) throw new FileNotFoundException($"旧文件不存在:{oldFilePath}", oldFilePath);
|
if (!FileUtils.Exists(oldFilePath)) throw new FileNotFoundException($"旧文件不存在:{oldFilePath}", oldFilePath);
|
||||||
if (!File.Exists(newFilePath)) throw new FileNotFoundException($"新文件不存在:{newFilePath}", newFilePath);
|
if (!FileUtils.Exists(newFilePath)) throw new FileNotFoundException($"新文件不存在:{newFilePath}", newFilePath);
|
||||||
DirectoryUtils.Create(deltaFilePath, isFilePath: true);
|
DirectoryUtils.Create(deltaFilePath, isFilePath: true);
|
||||||
// fileTypeSet:https://learn.microsoft.com/en-us/previous-versions/bb417345(v=msdn.10)?redirectedfrom=MSDN#file-type-sets (15L: DELTA_FILE_TYPE_SET_EXECUTABLES)
|
// 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
|
// 131072L: IgnoreFileSizeLimit, 32u: Crc32
|
||||||
@@ -27,8 +27,8 @@ public static class MsDelta {
|
|||||||
/// <exception cref="FileNotFoundException" />
|
/// <exception cref="FileNotFoundException" />
|
||||||
/// <exception cref="Win32Exception" />
|
/// <exception cref="Win32Exception" />
|
||||||
public static void Apply(string oldFilePath, string deltaFilePath, string newFilePath) {
|
public static void Apply(string oldFilePath, string deltaFilePath, string newFilePath) {
|
||||||
if (!File.Exists(oldFilePath)) throw new FileNotFoundException($"旧文件不存在:{oldFilePath}", oldFilePath);
|
if (!FileUtils.Exists(oldFilePath)) throw new FileNotFoundException($"旧文件不存在:{oldFilePath}", oldFilePath);
|
||||||
if (!File.Exists(deltaFilePath)) throw new FileNotFoundException($"补丁文件不存在:{deltaFilePath}", deltaFilePath);
|
if (!FileUtils.Exists(deltaFilePath)) throw new FileNotFoundException($"补丁文件不存在:{deltaFilePath}", deltaFilePath);
|
||||||
DirectoryUtils.Create(newFilePath, isFilePath: true);
|
DirectoryUtils.Create(newFilePath, isFilePath: true);
|
||||||
// 1L: AllowLegacy
|
// 1L: AllowLegacy
|
||||||
if (!ApplyDelta(1L, PathUtils.ToLongPath(oldFilePath), PathUtils.ToLongPath(deltaFilePath), PathUtils.ToLongPath(newFilePath)))
|
if (!ApplyDelta(1L, PathUtils.ToLongPath(oldFilePath), PathUtils.ToLongPath(deltaFilePath), PathUtils.ToLongPath(newFilePath)))
|
||||||
|
|||||||
@@ -40,4 +40,9 @@ public static class FileUtils {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Delete(string filePath) => File.Delete(PathUtils.ToLongPath(filePath));
|
public static void Delete(string filePath) => File.Delete(PathUtils.ToLongPath(filePath));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 确定指定的文件是否存在。
|
||||||
|
/// </summary>
|
||||||
|
public static bool Exists(string filePath) => File.Exists(PathUtils.ToLongPath(filePath));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -34,13 +34,13 @@ public static class PathUtils {
|
|||||||
string pathToKeep = "";
|
string pathToKeep = "";
|
||||||
string pathToShorten = fullName;
|
string pathToShorten = fullName;
|
||||||
if (fullName.EndsWithF(".jar", true)) keepFileName = true; // jar 文件的文件名需要保留原样,否则会导致 Forge 1.20.1 无法通过文件名识别模块名
|
if (fullName.EndsWithF(".jar", true)) keepFileName = true; // jar 文件的文件名需要保留原样,否则会导致 Forge 1.20.1 无法通过文件名识别模块名
|
||||||
if (keepFileName && File.Exists(fullName)) {
|
if (keepFileName && FileUtils.Exists(fullName)) {
|
||||||
pathToKeep = Path.GetFileName(fullName);
|
pathToKeep = Path.GetFileName(fullName);
|
||||||
pathToShorten = Path.GetDirectoryName(fullName);
|
pathToShorten = Path.GetDirectoryName(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 逐级向上寻找已存在的文件夹,将不存在的部分挪到 suffix,不再缩短
|
// 逐级向上寻找已存在的文件夹,将不存在的部分挪到 suffix,不再缩短
|
||||||
while (!Directory.Exists(pathToShorten) && !File.Exists(pathToShorten)) { // 如果路径不存在
|
while (!DirectoryUtils.Exists(pathToShorten) && !FileUtils.Exists(pathToShorten)) { // 如果路径不存在
|
||||||
string parentPath = Path.GetDirectoryName(pathToShorten);
|
string parentPath = Path.GetDirectoryName(pathToShorten);
|
||||||
if (string.IsNullOrEmpty(parentPath) || parentPath == pathToShorten) return fullName; // 已经到达根目录,全都不存在,直接返回
|
if (string.IsNullOrEmpty(parentPath) || parentPath == pathToShorten) return fullName; // 已经到达根目录,全都不存在,直接返回
|
||||||
pathToKeep = Path.Combine(Path.GetFileName(pathToShorten), pathToKeep);
|
pathToKeep = Path.Combine(Path.GetFileName(pathToShorten), pathToKeep);
|
||||||
|
|||||||
Reference in new issue
Block a user