for Push.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
using KssSmaPlaLib.Encryption;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.Tools.ClaraHack.NamespaceAdjust
|
||||
{
|
||||
public static class NamespaceAdjusterUxer
|
||||
{
|
||||
public static bool TuckIntoMain(string[] args)
|
||||
{
|
||||
if (args.Length != 3) return false;
|
||||
|
||||
if (args[0].ToLower() != "/namespaceadjuster") return false;
|
||||
|
||||
var projectTopFolderPath = args[1];
|
||||
var projectName = args[2];
|
||||
|
||||
if (NamespaceAdjusterUxer.Try(
|
||||
projectTopFolderPath,
|
||||
projectName,
|
||||
out var updatedCount,
|
||||
out var resultMessage) == false)
|
||||
{
|
||||
Console.WriteLine(resultMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"namespace調整完了。[更新ファイル数:{updatedCount}]");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Try(
|
||||
string projectRootPath,
|
||||
string projectName,
|
||||
out int updatedCount,
|
||||
out string resultMessage)
|
||||
{
|
||||
updatedCount = 0;
|
||||
resultMessage = string.Empty;
|
||||
|
||||
// フォルダバリデ
|
||||
if (!Directory.Exists(projectRootPath))
|
||||
{
|
||||
resultMessage = $"プロジェクトルートフォルダが存在しません。[プロジェクトルートフォルダ:{projectRootPath}]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 配下全どり
|
||||
var csFiles = Directory.GetFiles(
|
||||
projectRootPath,
|
||||
"*.cs",
|
||||
SearchOption.AllDirectories);
|
||||
|
||||
foreach (var filePath in csFiles)
|
||||
{
|
||||
// トップ下相対フォルダパス
|
||||
var relativeDir = Path.GetDirectoryName(filePath)?.Substring(projectRootPath.Length).TrimStart(Path.DirectorySeparatorChar);
|
||||
|
||||
// セパレータ変換('\'→'.')
|
||||
var namespaceSuffix = relativeDir?.Replace(Path.DirectorySeparatorChar, '.');
|
||||
|
||||
// トップノード(PJ名)つけてフル化
|
||||
var fullNamespace = string.IsNullOrEmpty(namespaceSuffix)
|
||||
// PJ名のみ(カレントはトップ下)
|
||||
? projectName
|
||||
// PJ名+配下
|
||||
: $"{projectName}.{namespaceSuffix}";
|
||||
|
||||
// フル読み
|
||||
var content = File.ReadAllText(filePath);
|
||||
|
||||
// namespace行の置換
|
||||
var newContent = Regex.Replace(
|
||||
content,
|
||||
@"namespace\s+[\w\.]+",
|
||||
$"namespace {fullNamespace}");
|
||||
|
||||
if (newContent != content)
|
||||
{
|
||||
// 内容変わった時だけ書き込み
|
||||
File.WriteAllText(filePath, newContent);
|
||||
updatedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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