6124d6060c
Co-authored-by: Cursor <cursoragent@cursor.com>
110 lines
4.2 KiB
C#
110 lines
4.2 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace R0PatchGenerator
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("========================================");
|
|
Console.WriteLine(" R0对战平台 增量包生成器");
|
|
Console.WriteLine("========================================");
|
|
Console.WriteLine();
|
|
|
|
if (args.Length < 3)
|
|
{
|
|
PrintUsage();
|
|
return;
|
|
}
|
|
|
|
string oldVersionPath = args[0];
|
|
string newVersionPath = args[1];
|
|
string outputPath = args[2];
|
|
|
|
// 可选参数:版本号
|
|
string fromVersion = args.Length > 3 ? args[3] : "unknown";
|
|
string toVersion = args.Length > 4 ? args[4] : "unknown";
|
|
|
|
Console.WriteLine("源版本目录: " + oldVersionPath);
|
|
Console.WriteLine("目标版本目录: " + newVersionPath);
|
|
Console.WriteLine("输出路径: " + outputPath);
|
|
Console.WriteLine("从版本: " + fromVersion);
|
|
Console.WriteLine("到版本: " + toVersion);
|
|
Console.WriteLine();
|
|
|
|
if (!Directory.Exists(oldVersionPath))
|
|
{
|
|
Console.WriteLine("错误: 源版本目录不存在!");
|
|
return;
|
|
}
|
|
|
|
if (!Directory.Exists(newVersionPath))
|
|
{
|
|
Console.WriteLine("错误: 目标版本目录不存在!");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
PatchGenerator generator = new PatchGenerator();
|
|
bool success = generator.GeneratePatch(oldVersionPath, newVersionPath, outputPath, fromVersion, toVersion);
|
|
|
|
if (success)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("增量包生成成功!");
|
|
Console.WriteLine("输出文件: " + outputPath);
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
|
Console.WriteLine("文件大小: " + FormatFileSize(fi.Length));
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("增量包生成失败!");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("错误: " + ex.Message);
|
|
Console.WriteLine(ex.StackTrace);
|
|
}
|
|
}
|
|
|
|
static void PrintUsage()
|
|
{
|
|
Console.WriteLine("用法:");
|
|
Console.WriteLine(" R0PatchGenerator.exe <旧版本目录> <新版本目录> <输出文件.zip> [从版本] [到版本]");
|
|
Console.WriteLine();
|
|
Console.WriteLine("示例:");
|
|
Console.WriteLine(" R0PatchGenerator.exe \"C:\\versions\\1.0.0\" \"C:\\versions\\1.0.1\" \"patch_1.0.0_to_1.0.1.zip\" 1.0.0 1.0.1");
|
|
Console.WriteLine();
|
|
Console.WriteLine("说明:");
|
|
Console.WriteLine(" - 旧版本目录: 包含旧版本完整文件的目录");
|
|
Console.WriteLine(" - 新版本目录: 包含新版本完整文件的目录");
|
|
Console.WriteLine(" - 输出文件: 生成的增量包文件路径(.zip格式)");
|
|
Console.WriteLine(" - 从版本/到版本: 可选,用于生成版本信息");
|
|
Console.WriteLine();
|
|
Console.WriteLine("增量包内容:");
|
|
Console.WriteLine(" - patch.json: 更新清单文件");
|
|
Console.WriteLine(" - patches/: 差异文件目录(使用HDiffPatch格式)");
|
|
Console.WriteLine(" - new/: 新增文件目录");
|
|
Console.WriteLine();
|
|
Console.WriteLine("注意: 需要将 hdiffz.exe 放在同一目录下");
|
|
}
|
|
|
|
static string FormatFileSize(long bytes)
|
|
{
|
|
if (bytes >= 1073741824)
|
|
return String.Format("{0:F2} GB", bytes / 1073741824.0);
|
|
if (bytes >= 1048576)
|
|
return String.Format("{0:F2} MB", bytes / 1048576.0);
|
|
if (bytes >= 1024)
|
|
return String.Format("{0:F2} KB", bytes / 1024.0);
|
|
return String.Format("{0} B", bytes);
|
|
}
|
|
}
|
|
}
|
|
|