- 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/ の再帰配置に対応
194 lines
6.9 KiB
C#
194 lines
6.9 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace GameLauncher.Engines.Common
|
|
{
|
|
/// <summary>
|
|
/// Shared helpers for engine detection and misdetection repair logic,
|
|
/// consolidated from the duplicated branches previously spread across
|
|
/// GameScannerService. This is the single source of truth for engine names
|
|
/// and for re-validating a detected engine against the game directory content.
|
|
/// </summary>
|
|
public static class EngineDetectionHelper
|
|
{
|
|
/// <summary>Canonical engine name for RPG Maker (RGSS based) games.</summary>
|
|
public const string EngineRgss = "Rgss";
|
|
|
|
/// <summary>Canonical engine name for RPG Maker MV/MZ (NW.js based) games.</summary>
|
|
public const string EngineTkool = "Tkool";
|
|
|
|
/// <summary>Canonical engine name for tyrano scripts games.</summary>
|
|
public const string EngineTyrano = "Tyrano";
|
|
|
|
/// <summary>Canonical engine name for Wolf RPG games.</summary>
|
|
public const string EngineWolf = "Wolf";
|
|
|
|
/// <summary>Canonical engine name for Unity games.</summary>
|
|
public const string EngineUnity = "Unity";
|
|
|
|
/// <summary>Canonical engine name for generic NW.js packaged games.</summary>
|
|
public const string EngineNwjs = "Nwjs";
|
|
|
|
/// <summary>Canonical engine name used when detection fails.</summary>
|
|
public const string EngineUnknown = "Unknown";
|
|
|
|
/// <summary>Resolves the canonical engine name from a raw detection string.</summary>
|
|
/// <remarks>
|
|
/// Handles case differences and common aliases (e.g. "RPGMaker", "RGSS3",
|
|
/// "MV", "MZ", "WolfRPG", "NW.js") so callers always compare canonical names.
|
|
/// </remarks>
|
|
public static string NormalizeEngineName(string raw)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(raw))
|
|
{
|
|
return EngineUnknown;
|
|
}
|
|
|
|
var value = raw.Trim();
|
|
|
|
// Case-insensitive comparison without allocating a lowercase copy each time.
|
|
if (Matches(value, "Rgss", "RGSS", "RPGMaker", "RPGMakerVX", "VX", "VXAce", "XP"))
|
|
{
|
|
return EngineRgss;
|
|
}
|
|
|
|
if (Matches(value, "Tkool", "RPGMakerMV", "RPGMakerMZ", "MV", "MZ"))
|
|
{
|
|
return EngineTkool;
|
|
}
|
|
|
|
if (Matches(value, "Tyrano", "Tyranoscript", "KAG", "TJS"))
|
|
{
|
|
return EngineTyrano;
|
|
}
|
|
|
|
if (Matches(value, "Wolf", "WolfRPG"))
|
|
{
|
|
return EngineWolf;
|
|
}
|
|
|
|
if (Matches(value, "Unity"))
|
|
{
|
|
return EngineUnity;
|
|
}
|
|
|
|
if (Matches(value, "Nwjs", "NWjs", "NW.js", "NWJS"))
|
|
{
|
|
return EngineNwjs;
|
|
}
|
|
|
|
return EngineUnknown;
|
|
}
|
|
|
|
/// <summary>Re-validates and repairs engine misdetection for a scanned game.</summary>
|
|
/// <remarks>
|
|
/// A single detection signal (extension or file layout) can be wrong, so the
|
|
/// canonical engine is re-checked against the game directory content. When the
|
|
/// detected engine contradicts the on-disk evidence, the evidence-based engine
|
|
/// is returned; otherwise the normalized detection is kept.
|
|
/// </remarks>
|
|
public static string RepairMisdetection(string gameDirectory, string detectedEngine)
|
|
{
|
|
var normalized = NormalizeEngineName(detectedEngine);
|
|
|
|
if (string.IsNullOrWhiteSpace(gameDirectory) || !Directory.Exists(gameDirectory))
|
|
{
|
|
return normalized;
|
|
}
|
|
|
|
var evidence = DetectFromDirectory(gameDirectory);
|
|
|
|
// Directory evidence has priority when it clearly identifies an engine.
|
|
if (evidence != EngineUnknown && evidence != normalized)
|
|
{
|
|
return evidence;
|
|
}
|
|
|
|
return normalized;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Infers the engine purely from the game directory layout.
|
|
/// Returns <see cref="EngineUnknown"/> when no decisive evidence is found.
|
|
/// </summary>
|
|
private static string DetectFromDirectory(string gameDirectory)
|
|
{
|
|
// RPG Maker MV/MZ: www/ folder or a Game.exe next to nw.js package files.
|
|
var wwwDir = Path.Combine(gameDirectory, "www");
|
|
if (Directory.Exists(wwwDir))
|
|
{
|
|
return EngineTkool;
|
|
}
|
|
|
|
var packageJson = Path.Combine(gameDirectory, "package.json");
|
|
if (File.Exists(packageJson) && Directory.Exists(Path.Combine(gameDirectory, "nwjs")))
|
|
{
|
|
return EngineNwjs;
|
|
}
|
|
|
|
// Wolf RPG: Data folder with a .wolf project file in the root.
|
|
if (Directory.Exists(Path.Combine(gameDirectory, "Data")))
|
|
{
|
|
var wolfProjects = Directory.GetFiles(gameDirectory, "*.wolf", SearchOption.TopDirectoryOnly);
|
|
if (wolfProjects.Length > 0)
|
|
{
|
|
return EngineWolf;
|
|
}
|
|
}
|
|
|
|
// RPG Maker RGSS: Game.ini or a Data folder containing .rvdata2/.rvdata files.
|
|
var gameIni = Path.Combine(gameDirectory, "Game.ini");
|
|
if (File.Exists(gameIni))
|
|
{
|
|
return EngineRgss;
|
|
}
|
|
|
|
var dataDir = Path.Combine(gameDirectory, "Data");
|
|
if (Directory.Exists(dataDir) &&
|
|
(Directory.GetFiles(dataDir, "*.rvdata2").Length > 0 ||
|
|
Directory.GetFiles(dataDir, "*.rvdata").Length > 0))
|
|
{
|
|
return EngineRgss;
|
|
}
|
|
|
|
// tyrano: a tyrano/ subfolder or a .tjs config in the root.
|
|
if (Directory.Exists(Path.Combine(gameDirectory, "tyrano")))
|
|
{
|
|
return EngineTyrano;
|
|
}
|
|
|
|
if (Directory.GetFiles(gameDirectory, "*.tjs", SearchOption.TopDirectoryOnly).Length > 0)
|
|
{
|
|
return EngineTyrano;
|
|
}
|
|
|
|
// Unity: an *_Data folder next to the executable (typical Unity layout).
|
|
foreach (var dir in Directory.GetDirectories(gameDirectory))
|
|
{
|
|
var name = Path.GetFileName(dir);
|
|
if (name.EndsWith("_Data", StringComparison.OrdinalIgnoreCase) &&
|
|
File.Exists(Path.Combine(dir, "globalgamemanagers")))
|
|
{
|
|
return EngineUnity;
|
|
}
|
|
}
|
|
|
|
return EngineUnknown;
|
|
}
|
|
|
|
/// <summary>Case-insensitive equality against any of the provided aliases.</summary>
|
|
private static bool Matches(string value, params string[] aliases)
|
|
{
|
|
foreach (var alias in aliases)
|
|
{
|
|
if (string.Equals(value, alias, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|