forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
295 additions
and
286 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1,116 @@ | ||
using System.Application.Models; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Security.Cryptography; | ||
using static System.Application.Utils; | ||
|
||
namespace System.Application.Steps | ||
{ | ||
internal static class Step8_tar_gz | ||
internal static class Step8_tar_gz // tgz | ||
{ | ||
public static void Add(RootCommand command) | ||
{ | ||
// tgz | ||
var tgz = new Command("tgz", "8. (本地)读取上一步操作后的 Publish.json 生成压缩包并计算哈希值写入 Publish.json"); | ||
tgz.Handler = CommandHandler.Create(() => | ||
{ | ||
var publish_json_path = PublishJsonFilePath; | ||
var publish_json_str = File.ReadAllText(publish_json_path); | ||
var dirNames = Serializable.DJSON<PublishDirInfo[]>(publish_json_str); | ||
|
||
if (!dirNames.Any_Nullable()) | ||
{ | ||
Console.WriteLine($"错误:发布配置文件读取失败!{publish_json_path}"); | ||
return; | ||
} | ||
|
||
dirNames = dirNames.ThrowIsNull(nameof(dirNames)); | ||
|
||
foreach (var item in dirNames) | ||
{ | ||
var packPath = GetPackPath(item, FileEx.TAR_GZ); | ||
Console.WriteLine($"正在生成压缩包:{packPath}"); | ||
IOPath.FileIfExistsItDelete(packPath); | ||
|
||
CreatePack(packPath, item.Files); | ||
|
||
using var fileStream = File.OpenRead(packPath); | ||
var sha256 = Hashs.String.SHA256(fileStream); | ||
|
||
if (item.BuildDownloads.ContainsKey(AppDownloadType.Compressed_GZip)) | ||
{ | ||
item.BuildDownloads[AppDownloadType.Compressed_GZip] = new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }; | ||
} | ||
else | ||
{ | ||
item.BuildDownloads.Add(AppDownloadType.Compressed_GZip, new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }); | ||
} | ||
} | ||
|
||
SavePublishJson(dirNames, removeFiles: true); | ||
|
||
Console.WriteLine("完成"); | ||
}); | ||
command.AddCommand(tgz); | ||
} | ||
=> Step8.Add(command, | ||
AppDownloadType.Compressed_GZip, | ||
"tgz", | ||
FileEx.TAR_GZ, | ||
CreatePack); | ||
} | ||
|
||
internal static class Step8_7z | ||
internal static class Step8_7z // 7z(Lzma2) 64,809,214 字节 | ||
{ | ||
public static void Add(RootCommand command) | ||
{ | ||
// 7z | ||
var _7z = new Command("7z", "8. (本地)读取上一步操作后的 Publish.json 生成压缩包并计算哈希值写入 Publish.json"); | ||
_7z.Handler = CommandHandler.Create(() => | ||
{ | ||
var publish_json_path = PublishJsonFilePath; | ||
var publish_json_str = File.ReadAllText(publish_json_path); | ||
var dirNames = Serializable.DJSON<PublishDirInfo[]>(publish_json_str); | ||
|
||
if (!dirNames.Any_Nullable()) | ||
{ | ||
Console.WriteLine($"错误:发布配置文件读取失败!{publish_json_path}"); | ||
return; | ||
} | ||
|
||
dirNames = dirNames.ThrowIsNull(nameof(dirNames)); | ||
|
||
foreach (var item in dirNames) | ||
{ | ||
var packPath = GetPackPath(item, FileEx._7Z); | ||
Console.WriteLine($"正在生成压缩包:{packPath}"); | ||
IOPath.FileIfExistsItDelete(packPath); | ||
|
||
CreateSevenZipPack(packPath, item.Files); | ||
|
||
using var fileStream = File.OpenRead(packPath); | ||
var sha256 = Hashs.String.SHA256(fileStream); | ||
|
||
if (item.BuildDownloads.ContainsKey(AppDownloadType.Compressed_7z)) | ||
{ | ||
item.BuildDownloads[AppDownloadType.Compressed_7z] = new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }; | ||
} | ||
else | ||
{ | ||
item.BuildDownloads.Add(AppDownloadType.Compressed_7z, new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }); | ||
} | ||
} | ||
=> Step8.Add(command, | ||
AppDownloadType.Compressed_7z, | ||
"7z", | ||
FileEx._7Z, | ||
CreateSevenZipPack); | ||
} | ||
|
||
SavePublishJson(dirNames, removeFiles: true); | ||
internal static class Step8_tar_br // tbr 70,278,650 字节 | ||
{ | ||
public static void Add(RootCommand command) | ||
=> Step8.Add(command, | ||
AppDownloadType.Compressed_Br, | ||
"tbr", | ||
FileEx.TAR_BR, | ||
CreateBrotliPack); | ||
} | ||
|
||
Console.WriteLine("完成"); | ||
}); | ||
command.AddCommand(_7z); | ||
} | ||
internal static class Step8_tar_xz // tar.xz XZOutputStream.Flush NotSupportedException | ||
{ | ||
public static void Add(RootCommand command) | ||
=> Step8.Add(command, | ||
AppDownloadType.Compressed_XZ, | ||
"xz", | ||
FileEx.TAR_XZ, | ||
CreateXZPack); | ||
} | ||
|
||
internal static class Step8_tar_br | ||
internal static class Step8_tar_zst // tar.zst 71,854,499 字节 | ||
{ | ||
public static void Add(RootCommand command) | ||
=> Step8.Add(command, | ||
AppDownloadType.Compressed_Zstd, | ||
"zst", | ||
FileEx.TAR_ZST, | ||
CreateZstdPack); | ||
} | ||
} | ||
|
||
namespace System.Application | ||
{ | ||
partial class Utils | ||
{ | ||
public static class Step8 | ||
{ | ||
// tbr | ||
var tar_br = new Command("tbr", "8. (本地)读取上一步操作后的 Publish.json 生成压缩包并计算哈希值写入 Publish.json"); | ||
tar_br.Handler = CommandHandler.Create(() => | ||
public static void Add(RootCommand command, AppDownloadType type, string name, string fileEx, Action<string, IEnumerable<PublishFileInfo>> createPack) | ||
{ | ||
var publish_json_path = PublishJsonFilePath; | ||
var publish_json_str = File.ReadAllText(publish_json_path); | ||
var dirNames = Serializable.DJSON<PublishDirInfo[]>(publish_json_str); | ||
|
||
if (!dirNames.Any_Nullable()) | ||
{ | ||
Console.WriteLine($"错误:发布配置文件读取失败!{publish_json_path}"); | ||
return; | ||
} | ||
|
||
dirNames = dirNames.ThrowIsNull(nameof(dirNames)); | ||
|
||
foreach (var item in dirNames) | ||
var comm = new Command(name, "8. (本地)读取上一步操作后的 Publish.json 生成压缩包并计算哈希值写入 Publish.json") | ||
{ | ||
var packPath = GetPackPath(item, FileEx.TAR_BR); | ||
Console.WriteLine($"正在生成压缩包:{packPath}"); | ||
IOPath.FileIfExistsItDelete(packPath); | ||
|
||
CreateBrotliPack(packPath, item.Files); | ||
|
||
using var fileStream = File.OpenRead(packPath); | ||
var sha256 = Hashs.String.SHA256(fileStream); | ||
|
||
if (item.BuildDownloads.ContainsKey(AppDownloadType.Compressed_Br)) | ||
Handler = CommandHandler.Create(() => | ||
{ | ||
item.BuildDownloads[AppDownloadType.Compressed_Br] = new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }; | ||
} | ||
else | ||
{ | ||
item.BuildDownloads.Add(AppDownloadType.Compressed_Br, new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }); | ||
} | ||
} | ||
|
||
SavePublishJson(dirNames, removeFiles: true); | ||
|
||
Console.WriteLine("完成"); | ||
}); | ||
command.AddCommand(tar_br); | ||
var publish_json_path = PublishJsonFilePath; | ||
var publish_json_str = File.ReadAllText(publish_json_path); | ||
var dirNames = Serializable.DJSON<PublishDirInfo[]>(publish_json_str); | ||
|
||
if (!dirNames.Any_Nullable()) | ||
{ | ||
Console.WriteLine($"错误:发布配置文件读取失败!{publish_json_path}"); | ||
return; | ||
} | ||
|
||
dirNames = dirNames.ThrowIsNull(nameof(dirNames)); | ||
|
||
foreach (var item in dirNames) | ||
{ | ||
var packPath = GetPackPath(item, fileEx); | ||
Console.WriteLine($"正在生成压缩包:{packPath}"); | ||
IOPath.FileIfExistsItDelete(packPath); | ||
|
||
createPack(packPath, item.Files); | ||
|
||
using var fileStream = File.OpenRead(packPath); | ||
var sha256 = Hashs.String.SHA256(fileStream); | ||
|
||
if (item.BuildDownloads.ContainsKey(type)) | ||
{ | ||
item.BuildDownloads[type] = new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }; | ||
} | ||
else | ||
{ | ||
item.BuildDownloads.Add(type, new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length }); | ||
} | ||
} | ||
|
||
SavePublishJson(dirNames, removeFiles: false); | ||
|
||
Console.WriteLine("完成"); | ||
}) | ||
}; | ||
command.AddCommand(comm); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters