253 lines
8.9 KiB
C#
253 lines
8.9 KiB
C#
// Engines/Bakin/BakinDetector.cs — RPG Developer Bakin (Smile Game Builder 系 YUKRDATA) ゲーム検出ヘルパー
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Media;
|
|
using GameLauncher.Engines.Tkool;
|
|
using GameLauncher.Engines.Unity;
|
|
|
|
namespace GameLauncher.Engines.Bakin
|
|
{
|
|
/// <summary>
|
|
/// RPG Developer Bakin / Smile Game Builder 系ゲームの検出およびメタデータ解決を行うヘルパークラス。
|
|
/// </summary>
|
|
public static class BakinDetector
|
|
{
|
|
#region □変数(Private)
|
|
|
|
private static readonly HashSet<string> ExcludedExeNames = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
"bakinplayer.exe",
|
|
"notification_helper.exe",
|
|
"crashpad_handler.exe",
|
|
"elevate.exe",
|
|
"UnityCrashHandler32.exe",
|
|
"UnityCrashHandler64.exe"
|
|
};
|
|
|
|
#endregion
|
|
|
|
#region □メソッド(Public)
|
|
|
|
/// <summary>
|
|
/// 指定されたディレクトリが RPG Developer Bakin 製ゲームであるかを判定します。
|
|
/// </summary>
|
|
/// <param name="dirPath">対象ディレクトリパス</param>
|
|
/// <returns>Bakin ゲームであれば true</returns>
|
|
public static bool IsBakinGame(string dirPath)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dirPath) || !Directory.Exists(dirPath))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var dataSubDir = Path.Combine(dirPath, "data");
|
|
|
|
// data/ サブフォルダまたはルート直下に Bakin 固有ファイルが存在するか確認
|
|
if (File.Exists(Path.Combine(dataSubDir, "bakinplayer.exe")) ||
|
|
File.Exists(Path.Combine(dataSubDir, "bakinengine.dll")) ||
|
|
File.Exists(Path.Combine(dataSubDir, "data.rbpack")) ||
|
|
File.Exists(Path.Combine(dirPath, "bakinplayer.exe")) ||
|
|
File.Exists(Path.Combine(dirPath, "bakinengine.dll")) ||
|
|
File.Exists(Path.Combine(dirPath, "data.rbpack")))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 指定ディレクトリ内の RPG Developer Bakin ゲームを検出し、TkoolGameItem を生成します。
|
|
/// </summary>
|
|
/// <param name="dirPath">ゲームフォルダの絶対パス</param>
|
|
/// <param name="folderName">フォルダ名</param>
|
|
/// <param name="folderModified">フォルダ更新日時</param>
|
|
/// <param name="iconLoader">アイコン読み込み関数</param>
|
|
/// <returns>検出されたゲームアイテム。該当しない場合は null</returns>
|
|
public static TkoolGameItem? DetectBakinGame(
|
|
string dirPath,
|
|
string folderName,
|
|
DateTime? folderModified,
|
|
Func<string?, string?, ImageSource?>? iconLoader)
|
|
{
|
|
try
|
|
{
|
|
if (!BakinDetector.IsBakinGame(dirPath))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var exePath = BakinDetector.FindBakinExecutable(dirPath, folderName);
|
|
string title = folderName;
|
|
if (!string.IsNullOrEmpty(exePath))
|
|
{
|
|
var exeName = Path.GetFileNameWithoutExtension(exePath);
|
|
if (!string.IsNullOrWhiteSpace(exeName) &&
|
|
!string.Equals(exeName, "bakinplayer", StringComparison.OrdinalIgnoreCase) &&
|
|
!string.Equals(exeName, "Game", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
title = folderName;
|
|
}
|
|
}
|
|
|
|
ImageSource? icon = null;
|
|
if (iconLoader != null)
|
|
{
|
|
icon = iconLoader(exePath, dirPath);
|
|
}
|
|
|
|
bool hasSave = BakinSaveService.HasAnySaveData(dirPath);
|
|
|
|
return new TkoolGameItem
|
|
{
|
|
Title = title,
|
|
FolderName = folderName,
|
|
RootDirectory = dirPath,
|
|
ExecutablePath = exePath ?? string.Empty,
|
|
EngineType = TkoolEngineType.Bakin,
|
|
IsModded = false,
|
|
ApplyMod = false,
|
|
HasSaveData = hasSave,
|
|
IconImage = icon,
|
|
FolderLastModified = folderModified
|
|
};
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bakin ゲームの起動用実行ファイル(ランチャー .exe または bakinplayer.exe)を検索します。
|
|
/// </summary>
|
|
/// <param name="dirPath">ゲームルートディレクトリ</param>
|
|
/// <param name="folderName">フォルダ名(省略可)</param>
|
|
/// <returns>実行ファイルのフルパス。見つからない場合は null</returns>
|
|
public static string? FindBakinExecutable(string dirPath, string? folderName = null)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dirPath) || !Directory.Exists(dirPath))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var topExes = Directory.GetFiles(dirPath, "*.exe", SearchOption.TopDirectoryOnly)
|
|
.Where(p => !BakinDetector.IsExcludedLauncherCandidate(p))
|
|
.ToList();
|
|
|
|
if (topExes.Count == 1)
|
|
{
|
|
return topExes[0];
|
|
}
|
|
|
|
if (topExes.Count > 1)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(folderName))
|
|
{
|
|
var match = topExes.FirstOrDefault(p =>
|
|
folderName.Contains(Path.GetFileNameWithoutExtension(p), StringComparison.OrdinalIgnoreCase) ||
|
|
Path.GetFileNameWithoutExtension(p).Contains(folderName, StringComparison.OrdinalIgnoreCase));
|
|
if (match != null)
|
|
{
|
|
return match;
|
|
}
|
|
}
|
|
|
|
return topExes
|
|
.OrderByDescending(p =>
|
|
{
|
|
try { return new FileInfo(p).Length; } catch { return 0L; }
|
|
})
|
|
.First();
|
|
}
|
|
|
|
var dataPlayer = Path.Combine(dirPath, "data", "bakinplayer.exe");
|
|
if (File.Exists(dataPlayer))
|
|
{
|
|
return dataPlayer;
|
|
}
|
|
|
|
var rootPlayer = Path.Combine(dirPath, "bakinplayer.exe");
|
|
if (File.Exists(rootPlayer))
|
|
{
|
|
return rootPlayer;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// 無視
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bakin ゲームのセーブデータ格納ディレクトリ (`data/savedata` または `savedata`) を解決します。
|
|
/// </summary>
|
|
/// <param name="dirPath">ゲームルートディレクトリ</param>
|
|
/// <returns>セーブデータディレクトリのフルパス</returns>
|
|
public static string ResolveSaveDirectory(string dirPath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dirPath))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
var dataSaveDir = Path.Combine(dirPath, "data", "savedata");
|
|
if (Directory.Exists(dataSaveDir))
|
|
{
|
|
return dataSaveDir;
|
|
}
|
|
|
|
var rootSaveDir = Path.Combine(dirPath, "savedata");
|
|
if (Directory.Exists(rootSaveDir))
|
|
{
|
|
return rootSaveDir;
|
|
}
|
|
|
|
if (Directory.Exists(Path.Combine(dirPath, "data")))
|
|
{
|
|
return dataSaveDir;
|
|
}
|
|
|
|
return rootSaveDir;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region □メソッド(Private)
|
|
|
|
private static bool IsExcludedLauncherCandidate(string exePath)
|
|
{
|
|
var fileName = Path.GetFileName(exePath);
|
|
if (BakinDetector.ExcludedExeNames.Contains(fileName))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (fileName.StartsWith("unins", StringComparison.OrdinalIgnoreCase) ||
|
|
fileName.Contains("setup", StringComparison.OrdinalIgnoreCase) ||
|
|
fileName.Contains("config", StringComparison.OrdinalIgnoreCase) ||
|
|
fileName.Contains("軽量化", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|