- Engines/ 配下へエンジン別に再編 (Common/Rgss/Tkool/Tyrano/Wolf/Unity/Nwjs) - ゲーム個別処理を Engines/<Engine>/Games/<GameName>/ へ分離し、共通処理から明示呼び出し - 外部ツールを Engines/<Engine>/Tools/ へ移動し、AppPathHelper 経由で解決 - 旧 Tools/ 直下参照と不要な参照ファイル/バックアップを削除 - エージェント規則 AGENTS.md を追加し、README から参照 - publish.ps1 を Engines/<Engine>/Tools/ の再帰配置に対応
116 lines
4.1 KiB
C#
116 lines
4.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using GameLauncher.Engines.Tkool;
|
|
|
|
namespace GameLauncher.Engines.Rgss.Games.IiniTitleRepair
|
|
{
|
|
/// <summary>
|
|
/// Game-specific handling for RPG Maker RGSS titles whose cached title was
|
|
/// stored corrupted (mojibake). The title is re-read from Game.ini using an
|
|
/// encoding-safe reader.
|
|
///
|
|
/// This logic is isolated per engine/per concern so that it applies only to
|
|
/// the RGSS title-repair case and cannot affect any other engine's games.
|
|
/// Call sites invoke it explicitly (<see cref="Fix"/>).
|
|
/// </summary>
|
|
public static class GameIniTitleRepair
|
|
{
|
|
/// <summary>
|
|
/// Repairs a mojibake RGSS title stored in the cache by re-reading the
|
|
/// "Title=" entry from Game.ini (direct, or one level down).
|
|
/// </summary>
|
|
public static void Fix(TkoolGameItem tg)
|
|
{
|
|
try
|
|
{
|
|
string? iniPath = null;
|
|
var directIni = Path.Combine(tg.RootDirectory, "Game.ini");
|
|
if (File.Exists(directIni))
|
|
{
|
|
iniPath = directIni;
|
|
}
|
|
else if (Directory.Exists(tg.RootDirectory))
|
|
{
|
|
foreach (var sub in Directory.GetDirectories(tg.RootDirectory))
|
|
{
|
|
var subIni = Path.Combine(sub, "Game.ini");
|
|
if (File.Exists(subIni))
|
|
{
|
|
iniPath = subIni;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (iniPath == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var line in ReadIniLinesSafe(iniPath))
|
|
{
|
|
var trim = line.Trim();
|
|
if (trim.StartsWith("Title=", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
var val = trim.Substring(6).Trim();
|
|
if (!string.IsNullOrWhiteSpace(val) && !val.Contains('\uFFFD'))
|
|
{
|
|
tg.Title = val;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reads an INI file line-by-line, auto-detecting BOM (UTF-8/UTF-16 LE)
|
|
/// and falling back to Shift_JIS (CP932), which is the standard for
|
|
/// RPG Maker VX/VX Ace and Wolf RPG.
|
|
/// </summary>
|
|
public static string[] ReadIniLinesSafe(string filePath)
|
|
{
|
|
try
|
|
{
|
|
if (!File.Exists(filePath)) return Array.Empty<string>();
|
|
|
|
byte[] bytes = File.ReadAllBytes(filePath);
|
|
if (bytes.Length == 0) return Array.Empty<string>();
|
|
|
|
// 1. UTF-8 BOM (EF BB BF)
|
|
if (bytes.Length >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
|
|
{
|
|
var text = System.Text.Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3);
|
|
return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
|
}
|
|
|
|
// 2. UTF-16 LE BOM (FF FE)
|
|
if (bytes.Length >= 2 && bytes[0] == 0xFF && bytes[1] == 0xFE)
|
|
{
|
|
var text = System.Text.Encoding.Unicode.GetString(bytes, 2, bytes.Length - 2);
|
|
return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
|
}
|
|
|
|
// 3. Shift_JIS (CP932)
|
|
System.Text.Encoding encoding;
|
|
try
|
|
{
|
|
encoding = System.Text.Encoding.GetEncoding(932);
|
|
}
|
|
catch
|
|
{
|
|
encoding = System.Text.Encoding.GetEncoding("shift_jis");
|
|
}
|
|
|
|
var decoded = encoding.GetString(bytes);
|
|
return decoded.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
|
}
|
|
catch
|
|
{
|
|
return Array.Empty<string>();
|
|
}
|
|
}
|
|
}
|
|
}
|