Files
HLib/Tools/FileHack/MergeSplitFilesUxer.cs
2026-06-01 13:23:34 +09:00

64 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KssSmaPlaLib.Tools.FileHack
{
public static class MergeSplitFilesUxer
{
public static bool TuckIntoMain(string[] args)
{
if (args.Length != 2) return false;
if (args[0].ToLower() != "/filemerge") return false;
var path = args[1];
if (!Try(path, out var messageForMe))
{
Console.WriteLine($"ファイル結合に失敗しました。[エラー内容:{messageForMe}]");
return false;
}
Console.WriteLine($"ファイル結合が成功しました。");
return true;
}
public static bool Try(string baseFilePath, out string resultMessage)
{
try
{
string folder = Path.GetDirectoryName(baseFilePath);
string fileName = Path.GetFileName(baseFilePath);
string outputPath = Path.Combine(folder, fileName);
int partNum = 1;
using (var output = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
{
while (true)
{
string partPath = Path.Combine(folder, $"{fileName}.{partNum:D3}");
if (!File.Exists(partPath)) break;
using (var input = new FileStream(partPath, FileMode.Open, FileAccess.Read))
{
input.CopyTo(output);
}
partNum++;
}
}
resultMessage = $"結合成功:{partNum - 1}個のパートを結合しました。";
return true;
}
catch (Exception ex)
{
resultMessage = $"結合失敗: {ex.Message}";
return false;
}
}
}
}