chore: bundle evbunpack tool and add EVB control/launch fixes
- Add Enigma Virtual Box (EVB) engine support: detection, badge, unpack/restore UI - Bundle evbunpack.exe under Engines/Evb/Tools/evbunpack (Apache-2.0, with LICENSE/README) - Copy Engines\\**\\Tools\\** to build output via csproj (publish already covered by publish.ps1) - Throttle evbunpack progress reporting and shorten timeout to stop UI freeze - Rename original packed exe to .glbak and write a completion marker; make Restore reverse it - Launch the unpacked exe from _evb_extracted so script mods apply - Replace EVB MessageBox dialogs with readable log summaries - Remove obsolete boxed/7zip extraction code (NwjsPackageUnpacker, TkoolPackagedExtractionService)
This commit is contained in:
1 parent
8cea2a147d
commit
05e7bdb3c0
23 files changed
+1542
-1288
No files matched your search
+104
-44
@@ -116,13 +116,112 @@ namespace GameLauncher.Engines.Tkool
|
||||
|
||||
// ================= 単体exe梱包(FOSSIL / boxed)関連プロパティ =================
|
||||
// js/plugins.js がディスク上に無く、exeへ埋め込まれている形態を識別します。
|
||||
// 注: boxed の埋め込みコンテナ展開(旧 _extracted 展開)は廃止しました。
|
||||
// 単体exeは「起動のみ対応」として扱い、展開・注入は行いません。
|
||||
private bool _isFossilSingleExe;
|
||||
private bool _isBoxedExe;
|
||||
private bool _isStandaloneExeExtracted;
|
||||
private string? _standaloneExtractedDirPath;
|
||||
private string? _standaloneBackupPath;
|
||||
private string? _boxedPayloadEntryPath;
|
||||
private bool _canExtractViaExternalTool;
|
||||
|
||||
// ================= Enigma Virtual Box (EVB) 梱包関連プロパティ =================
|
||||
// EVB でパックされた exe を evbunpack で解凍した状態を識別します。
|
||||
// 他エンジンのゲームへは一切影響しません(このゲームフォルダ内でのみ扱う)。
|
||||
private bool _isEvbPacked;
|
||||
private bool _isEvbExtracted;
|
||||
private string? _evbExtractedDirPath;
|
||||
private string? _evbBackupPath;
|
||||
private string _evbUnderlyingEngine = string.Empty;
|
||||
|
||||
/// <summary>Enigma Virtual Box でパックされた exe を持つゲームかどうか</summary>
|
||||
public bool IsEvbPacked
|
||||
{
|
||||
get => _isEvbPacked;
|
||||
set { if (_isEvbPacked != value) { _isEvbPacked = value; OnPropertyChanged(); OnPropertyChanged(nameof(EvbBadgeVisibility)); OnPropertyChanged(nameof(IsEvb)); } }
|
||||
}
|
||||
|
||||
/// <summary>EVB 解凍済み(_evb_extracted に出力済み)かどうか</summary>
|
||||
public bool IsEvbExtracted
|
||||
{
|
||||
get => _isEvbExtracted;
|
||||
set { if (_isEvbExtracted != value) { _isEvbExtracted = value; OnPropertyChanged(); OnPropertyChanged(nameof(EvbDetailStatusText)); } }
|
||||
}
|
||||
|
||||
/// <summary>EVB 解凍先ディレクトリ(ゲームフォルダ内 _evb_extracted)</summary>
|
||||
public string? EvbExtractedDirPath
|
||||
{
|
||||
get => _evbExtractedDirPath;
|
||||
set { if (_evbExtractedDirPath != value) { _evbExtractedDirPath = value; OnPropertyChanged(); } }
|
||||
}
|
||||
|
||||
/// <summary>EVB 解凍時に作成した元 exe のバックアップパス(*.glbak)</summary>
|
||||
public string? EvbBackupPath
|
||||
{
|
||||
get => _evbBackupPath;
|
||||
set { if (_evbBackupPath != value) { _evbBackupPath = value; OnPropertyChanged(); } }
|
||||
}
|
||||
|
||||
/// <summary>EVB 解凍後に再判定された本来のエンジン名</summary>
|
||||
public string EvbUnderlyingEngine
|
||||
{
|
||||
get => _evbUnderlyingEngine;
|
||||
set { if (_evbUnderlyingEngine != value) { _evbUnderlyingEngine = value; OnPropertyChanged(); OnPropertyChanged(nameof(EvbDetailStatusText)); } }
|
||||
}
|
||||
|
||||
/// <summary>EVB として扱うか(UI バッジ判定用)</summary>
|
||||
public override bool IsEvb => IsEvbPacked;
|
||||
|
||||
/// <summary>EVB バッジの可視性</summary>
|
||||
public Visibility EvbBadgeVisibility => IsEvbPacked ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
/// <summary>EVB バッジのテキスト</summary>
|
||||
public string EvbBadgeText => "EVB";
|
||||
|
||||
/// <summary>EVB 未解凍のときだけ「要解凍」を強調表示するための可視性(一目で分かる導線)</summary>
|
||||
public Visibility EvbNeedsUnpackVisibility => (IsEvbPacked && !IsEvbExtracted) ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
/// <summary>
|
||||
/// Evb 解凍ツール(evbunpack.exe)が未配置かどうか。
|
||||
/// 選択時のガイドで「README.md を参照してください」と案内するために使用します。
|
||||
/// </summary>
|
||||
public bool IsEvbToolMissing => IsEvbPacked && !Engines.Evb.EvbUnpackerToolProvider.IsAvailable();
|
||||
|
||||
/// <summary>EVB 詳細状態テキスト</summary>
|
||||
public string EvbDetailStatusText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsEvbPacked)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var engine = string.IsNullOrWhiteSpace(EvbUnderlyingEngine) ? "未判定" : EvbUnderlyingEngine;
|
||||
if (IsEvbToolMissing)
|
||||
{
|
||||
return "evbunpack.exe が未配置です。Engines/Evb/Tools/evbunpack/README.md を参照してください。";
|
||||
}
|
||||
return IsEvbExtracted
|
||||
? $"Enigma Virtual Box パック済み(解凍済み / 本来: {engine})"
|
||||
: $"Enigma Virtual Box パック済み(未解凍 / 本来: {engine})";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EVB 解凍後の起動に使う実行ファイルを解決します。
|
||||
/// 解凍済み(_evb_extracted に完了マーカーがある)なら、その配下の exe を起動対象とし、
|
||||
/// 未解凍なら元の exe を返します。他ゲームには影響しません。
|
||||
/// </summary>
|
||||
public string ResolveLaunchExecutable()
|
||||
{
|
||||
if (!IsEvbPacked || !IsEvbExtracted)
|
||||
{
|
||||
return ExecutablePath;
|
||||
}
|
||||
|
||||
var outputDir = !string.IsNullOrEmpty(EvbExtractedDirPath)
|
||||
? EvbExtractedDirPath!
|
||||
: GameLauncher.Engines.Evb.EvbUnpackService.GetExtractedDir(RootDirectory);
|
||||
|
||||
var exe = GameLauncher.Engines.Evb.EvbUnpackService.FindLaunchExecutable(outputDir);
|
||||
return string.IsNullOrEmpty(exe) ? ExecutablePath : exe!;
|
||||
}
|
||||
|
||||
/// <summary>FOSSIL形態(FOSSILindex.html + 単体Game.exe、data/System.json はディスク上)かどうか</summary>
|
||||
public bool IsFossilSingleExe
|
||||
@@ -141,45 +240,6 @@ namespace GameLauncher.Engines.Tkool
|
||||
/// <summary>いずれかの単体exe梱包形態(FOSSIL / boxed)かどうか</summary>
|
||||
public bool IsStandaloneExePackage => IsFossilSingleExe || IsBoxedExe;
|
||||
|
||||
/// <summary>単体exe梱包ゲームを _extracted へ展開済みかどうか</summary>
|
||||
public bool IsStandaloneExeExtracted
|
||||
{
|
||||
get => _isStandaloneExeExtracted;
|
||||
set { if (_isStandaloneExeExtracted != value) { _isStandaloneExeExtracted = value; OnPropertyChanged(); } }
|
||||
}
|
||||
|
||||
/// <summary>展開先ディレクトリ(ゲームフォルダ内 _extracted)</summary>
|
||||
public string? StandaloneExtractedDirPath
|
||||
{
|
||||
get => _standaloneExtractedDirPath;
|
||||
set { if (_standaloneExtractedDirPath != value) { _standaloneExtractedDirPath = value; OnPropertyChanged(); } }
|
||||
}
|
||||
|
||||
/// <summary>exe内コンテナ改変時のバックアップパス(*.glbak)</summary>
|
||||
public string? StandaloneBackupPath
|
||||
{
|
||||
get => _standaloneBackupPath;
|
||||
set { if (_standaloneBackupPath != value) { _standaloneBackupPath = value; OnPropertyChanged(); } }
|
||||
}
|
||||
|
||||
/// <summary>boxed exe内で注入対象とするコンテナ内エントリ(例: js/plugins.js)</summary>
|
||||
public string? BoxedPayloadEntryPath
|
||||
{
|
||||
get => _boxedPayloadEntryPath;
|
||||
set { if (_boxedPayloadEntryPath != value) { _boxedPayloadEntryPath = value; OnPropertyChanged(); } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 外部アンパッカー(Tools\7zr.exe 等)による展開を試行できる可能性があるか。
|
||||
/// 標準ZIP署名が未確定でも、boxed命名exeが存在する場合に true となり「展開試行可」を示す。
|
||||
/// 実際に展開可能かは実行時(ExtractPackageNw)に確定する。
|
||||
/// </summary>
|
||||
public bool CanExtractViaExternalTool
|
||||
{
|
||||
get => _canExtractViaExternalTool;
|
||||
set { if (_canExtractViaExternalTool != value) { _canExtractViaExternalTool = value; OnPropertyChanged(); } }
|
||||
}
|
||||
|
||||
public override GameEngineKind EngineKind => EngineType switch
|
||||
{
|
||||
TkoolEngineType.Tyrano => GameEngineKind.Tyrano,
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using GameLauncher.Engines.Nwjs;
|
||||
|
||||
namespace GameLauncher.Engines.Tkool
|
||||
{
|
||||
/// <summary>
|
||||
/// nw.js boxed(exe埋め込み package.nw)等の単体exe梱包ツクールゲームの解析と
|
||||
/// ゲームフォルダ内 `_extracted` への冪等展開を行うオーケストレーター。
|
||||
///
|
||||
/// 役割分担(恒久・再利用可能を目的とした汎用設計):
|
||||
/// - 本サービス = 抽出の「進行役(オーケストレーター)」。
|
||||
/// - <see cref="NwjsPackageUnpacker"/> = 組み込みの埋め込みZIPコンテナ検出・展開。
|
||||
/// - <see cref="NwjsUnpackerToolProvider"/> = 外部アンパッカーの取得・呼び出し。
|
||||
///
|
||||
/// 展開戦略(順に試行):
|
||||
/// 1. 組み込みZIP展開: exe内の標準ZIPコンテナ(package.nw)を検出して展開。
|
||||
/// 2. 外部ツール委譲: Tools\ 配下の外部アンパッカー(未配置なら自動取得)へ委譲。
|
||||
///
|
||||
/// 設計方針:
|
||||
/// - 1.14GB級exeを対象に含むため、組み込み検出は限定/逐次走査で行う。
|
||||
/// - 展開はゲームフォルダ内 `_extracted` のみ。他ゲームへは一切影響しない。
|
||||
/// - 冪等: 展開済み(plugins.js 存在)なら再展開しない。
|
||||
/// - 既存公開API(GetExtractedDir / ContainsPackageNwMarker / IsExtractionComplete /
|
||||
/// ExeBackupSuffix / ExtractPackageNw)のシグネチャは維持し、後方互換を壊さない。
|
||||
/// </summary>
|
||||
public sealed class TkoolPackagedExtractionService
|
||||
{
|
||||
/// <summary>ゲームフォルダ内の展開先フォルダ名(Asar/SRPG の慣習に合わせる)</summary>
|
||||
public const string ExtractedDirName = NwjsPackageUnpacker.ExtractedDirName;
|
||||
|
||||
/// <summary>exe内コンテナ改変時のバックアップ拡張子</summary>
|
||||
public const string ExeBackupSuffix = ".glbak";
|
||||
|
||||
/// <summary>展開戦略の種別。将来の新形式追加を見据え、列挙型で差し替え可能にする。</summary>
|
||||
public enum UnpackStrategy
|
||||
{
|
||||
/// <summary>組み込みの埋め込みZIPコンテナ検出・展開</summary>
|
||||
BuiltInZip = 0,
|
||||
|
||||
/// <summary>外部アンパッカーへの委譲</summary>
|
||||
ExternalTool = 1,
|
||||
}
|
||||
|
||||
/// <summary>ゲームフォルダ内の展開先ディレクトリ(物理パス)</summary>
|
||||
public static string GetExtractedDir(string gameRootDir)
|
||||
=> NwjsPackageUnpacker.GetExtractedDir(gameRootDir);
|
||||
|
||||
/// <summary>
|
||||
/// exeに package.nw マーカーが含まれるかを限定部分読み(4MB窓×数点)で判定します。
|
||||
/// 全走査は行いません(1.14GB級exe対策)。
|
||||
/// </summary>
|
||||
public static bool ContainsPackageNwMarker(string exePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
const int windowSize = 4 * 1024 * 1024;
|
||||
using var fs = new FileStream(exePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
long size = fs.Length;
|
||||
if (size < 1024)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
double[] fractions = { 0.25, 0.5, 0.75, 0.9 };
|
||||
foreach (var frac in fractions)
|
||||
{
|
||||
long start = (long)(size * frac);
|
||||
int readLen = (int)Math.Min(windowSize, size - start);
|
||||
if (readLen <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var buf = new byte[readLen];
|
||||
fs.Seek(start, SeekOrigin.Begin);
|
||||
int read = fs.Read(buf, 0, buf.Length);
|
||||
var text = System.Text.Encoding.ASCII.GetString(buf, 0, read);
|
||||
|
||||
if (text.IndexOf("package.nw", StringComparison.Ordinal) >= 0 ||
|
||||
text.IndexOf("package.json", StringComparison.Ordinal) >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// exe内ZIPのローカルヘッダ(PK\x03\x04)offsetを限定ウィンドウで検出します。
|
||||
/// exe先頭の自己展開部を除いた中盤以降のみを対象にし、全走査を避けます。
|
||||
/// </summary>
|
||||
public static long? FindEmbeddedZipOffset(string exePath, long searchStart = 0, int windowBytes = 8 * 1024 * 1024)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var fs = new FileStream(exePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
long size = fs.Length;
|
||||
|
||||
// searchStart が 0 の場合は中盤〜後半(package.nw は後半に置かれる傾向)のみを走査
|
||||
double[] fractions = searchStart > 0 ? new[] { (double)searchStart / Math.Max(1, size) } : new[] { 0.5, 0.65, 0.8, 0.9 };
|
||||
foreach (var frac in fractions)
|
||||
{
|
||||
long start = (long)(size * frac);
|
||||
int readLen = (int)Math.Min(windowBytes, size - start);
|
||||
if (readLen <= 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var buf = new byte[readLen];
|
||||
fs.Seek(start, SeekOrigin.Begin);
|
||||
int read = fs.Read(buf, 0, buf.Length);
|
||||
|
||||
for (int i = 0; i < read - 3; i++)
|
||||
{
|
||||
if (buf[i] == 0x50 && buf[i + 1] == 0x4B && buf[i + 2] == 0x03 && buf[i + 3] == 0x04)
|
||||
{
|
||||
return start + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 既存 `_extracted` が完全か(plugins.js が存在するか)を判定します。
|
||||
/// </summary>
|
||||
public static bool IsExtractionComplete(string extractedDir, out string? pluginsJsPath)
|
||||
=> NwjsPackageUnpacker.IsExtractionComplete(extractedDir, out pluginsJsPath, out _);
|
||||
|
||||
/// <summary>
|
||||
/// exe内ZIP(package.nw 等)をゲームフォルダ内 `_extracted` へ冪等に全展開し、
|
||||
/// 展開後の js/plugins.js(相対パス)を返します。展開できなければ null。
|
||||
///
|
||||
/// 展開戦略を順に試行します: 組み込みZIP展開 → 外部ツール委譲。
|
||||
/// 後方互換のため同期シグネチャを維持します(外部ツールの自動取得は内部で同期待機)。
|
||||
/// </summary>
|
||||
public string? ExtractPackageNw(string exePath, string gameRoot, out string extractedDir, IProgress<string>? progress = null)
|
||||
{
|
||||
extractedDir = GetExtractedDir(gameRoot);
|
||||
|
||||
try
|
||||
{
|
||||
if (!File.Exists(exePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 冪等: 展開済みならスキップ
|
||||
if (Directory.Exists(extractedDir) && IsExtractionComplete(extractedDir, out _))
|
||||
{
|
||||
progress?.Report("既に展開済みです(_extracted を再利用)。");
|
||||
return NwjsPackageUnpacker.IsExtractionComplete(extractedDir, out _, out var rel) ? rel : "js/plugins.js";
|
||||
}
|
||||
|
||||
// 戦略1: 組み込みZIP展開
|
||||
progress?.Report("展開戦略: 組み込みZIP展開を試行します。");
|
||||
var relBuiltin = NwjsPackageUnpacker.ExtractEmbeddedZip(exePath, extractedDir, progress);
|
||||
if (relBuiltin != null)
|
||||
{
|
||||
return relBuiltin;
|
||||
}
|
||||
|
||||
// 戦略2: 外部ツール委譲
|
||||
progress?.Report("展開戦略: 外部アンパッカーへの委譲を試行します。");
|
||||
var relExternal = ExtractViaExternalTool(exePath, extractedDir, progress);
|
||||
if (relExternal != null)
|
||||
{
|
||||
return relExternal;
|
||||
}
|
||||
|
||||
progress?.Report("展開できませんでした(起動のみ対応)。");
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
progress?.Report($"展開処理中にエラーが発生しました: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 外部アンパッカー(未配置なら自動取得)で exe 内コンテナを `_extracted` へ展開します。
|
||||
/// 失敗(ネット未接続等)時は例外を投げず null を返し、呼び出し側で「起動のみ」へフォールバックさせます。
|
||||
/// </summary>
|
||||
private static string? ExtractViaExternalTool(string exePath, string extractedDir, IProgress<string>? progress)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 外部ツールの可用性確保(初回は自動ダウンロード)。同期待機で取得。
|
||||
var available = NwjsUnpackerToolProvider.IsToolAvailable()
|
||||
|| Task.Run(() => NwjsUnpackerToolProvider.EnsureToolAvailableAsync(progress)).GetAwaiter().GetResult();
|
||||
|
||||
if (!available)
|
||||
{
|
||||
progress?.Report("外部アンパッカーを取得できませんでした(ネット未接続等)。起動のみ対応へフォールバックします。");
|
||||
return null;
|
||||
}
|
||||
|
||||
var tool = NwjsUnpackerToolProvider.GetToolPath();
|
||||
if (tool == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 展開先を一旦クリーンにする(部分展開の混在を避ける)
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(extractedDir))
|
||||
{
|
||||
Directory.Delete(extractedDir, recursive: true);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (!NwjsUnpackerToolProvider.ExtractWithExternalTool(tool, exePath, extractedDir, progress))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 展開結果から plugins.js を解決
|
||||
var plugins = NwjsPackageUnpacker.ResolvePluginsJs(extractedDir);
|
||||
if (plugins == null)
|
||||
{
|
||||
progress?.Report("展開は完了しましたが、js/plugins.js が見つかりませんでした。");
|
||||
return null;
|
||||
}
|
||||
|
||||
var rel = Path.GetRelativePath(extractedDir, plugins).Replace(Path.DirectorySeparatorChar, '/');
|
||||
progress?.Report($"外部アンパッカーでの展開が完了しました: {rel}");
|
||||
return rel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
progress?.Report($"外部アンパッカー委譲でエラーが発生しました: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user