for Push.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using KssSmaPlaLib.Tools.ClaraHack.NamespaceAdjust;
|
||||
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 SplitFileBySizeUxer
|
||||
{
|
||||
public static bool TuckIntoMain(string[] args)
|
||||
{
|
||||
if (args.Length != 3) return false;
|
||||
|
||||
if (args[0].ToLower() != "/filesplit") return false;
|
||||
|
||||
var path = args[1];
|
||||
if (!int.TryParse(args[2], out var kb))
|
||||
{
|
||||
Console.WriteLine($"分割サイズ(KB)が数値でありません。[分割サイズ:{args[2]}]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Try(path, kb, out var messageForMe))
|
||||
{
|
||||
Console.WriteLine($"ファイル分割に失敗しました。[エラー内容:{messageForMe}]");
|
||||
return false;
|
||||
}
|
||||
Console.WriteLine($"ファイル分割が成功しました。");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Try(string filePath, int sizeKB, out string resultMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
int partSize = sizeKB * 1024;
|
||||
string folder = Path.GetDirectoryName(filePath);
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
|
||||
int partNum = 1;
|
||||
using (var input = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] buffer = new byte[partSize];
|
||||
int bytesRead;
|
||||
|
||||
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
string partPath = Path.Combine(folder, $"{fileName}.{partNum:D3}");
|
||||
using (var output = new FileStream(partPath, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
output.Write(buffer, 0, bytesRead);
|
||||
partNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
resultMessage = $"分割成功:{partNum - 1}個のパートに分割されました。";
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultMessage = $"分割失敗: {ex.Message}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user