642 lines
26 KiB
C#
642 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.Encodings.Web;
|
|
using System.Text.Json;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Input;
|
|
using Microsoft.Win32;
|
|
using GameLauncher.Helpers;
|
|
using GameLauncher.Models;
|
|
using GameLauncher.Services;
|
|
using GameLauncher.Services.Codecs;
|
|
using GameLauncher.Engines.Unity;
|
|
using GameLauncher.Engines.Nwjs;
|
|
using GameLauncher.Engines.Wolf;
|
|
using GameLauncher.Engines.Rgss;
|
|
using GameLauncher.Engines.Tkool;
|
|
|
|
namespace GameLauncher
|
|
{
|
|
/// <summary>
|
|
/// Unityゲームのセーブデータ(PlayerPrefs & ファイル)統合エディタウィンドウ
|
|
/// </summary>
|
|
public partial class SaveEditorWindow : Window
|
|
{
|
|
private readonly UnitySaveManagerService _saveService = new();
|
|
public UnityGameItem Game { get; }
|
|
|
|
// PlayerPrefs データ
|
|
private readonly ObservableCollection<PlayerPrefsEntry> _allPrefs = [];
|
|
private ListCollectionView _prefsView = null!;
|
|
|
|
// ファイル一覧データ
|
|
private readonly ObservableCollection<SaveFileEntry> _saveFiles = [];
|
|
private SaveFileEntry? _currentSelectedFile;
|
|
|
|
// GUIセーブプロパティデータ
|
|
private readonly ObservableCollection<SaveDataPropertyEntry> _guiProperties = [];
|
|
private ListCollectionView _guiPropsView = null!;
|
|
private ISaveDataCodec? _currentCodec;
|
|
|
|
// バックアップ一覧データ
|
|
private readonly ObservableCollection<SaveBackupEntry> _backups = [];
|
|
|
|
public SaveEditorWindow(UnityGameItem game)
|
|
{
|
|
InitializeComponent();
|
|
Game = game;
|
|
|
|
lblGameTitle.Text = game.Title;
|
|
lblGameInfo.Text = $"{game.CompanyName} / {game.ProductName} ({game.BackendBadgeText})";
|
|
|
|
// PlayerPrefs ビュー
|
|
_prefsView = (ListCollectionView)CollectionViewSource.GetDefaultView(_allPrefs);
|
|
_prefsView.Filter = FilterPrefs;
|
|
dgPlayerPrefs.ItemsSource = _prefsView;
|
|
|
|
// ファイル一覧
|
|
lstSaveFiles.ItemsSource = _saveFiles;
|
|
|
|
// GUI プロパティビュー
|
|
_guiPropsView = (ListCollectionView)CollectionViewSource.GetDefaultView(_guiProperties);
|
|
_guiPropsView.Filter = FilterGuiProperties;
|
|
dgGuiProperties.ItemsSource = _guiPropsView;
|
|
|
|
// バックアップ一覧
|
|
dgBackups.ItemsSource = _backups;
|
|
|
|
Loaded += SaveEditorWindow_Loaded;
|
|
}
|
|
|
|
private void SaveEditorWindow_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
ReloadPlayerPrefs();
|
|
ReloadSaveFiles();
|
|
ReloadBackups();
|
|
}
|
|
|
|
// ====================================================================
|
|
// PlayerPrefs タブ処理
|
|
// ====================================================================
|
|
|
|
public void ReloadPlayerPrefs()
|
|
{
|
|
_allPrefs.Clear();
|
|
if (string.IsNullOrEmpty(Game.RegistryPath))
|
|
{
|
|
lblStatus.Text = "レジストリ情報が設定されていません (app.info が見つかりませんでした)";
|
|
return;
|
|
}
|
|
|
|
var entries = _saveService.GetPlayerPrefs(Game.RegistryPath);
|
|
foreach (var entry in entries)
|
|
{
|
|
_allPrefs.Add(entry);
|
|
}
|
|
|
|
lblStatus.Text = $"PlayerPrefs: {entries.Count} 件のキーを読み込みました (HKCU\\{Game.RegistryPath})";
|
|
}
|
|
|
|
private bool FilterPrefs(object obj)
|
|
{
|
|
if (obj is not PlayerPrefsEntry entry) return false;
|
|
var query = txtSearchPrefs.Text.Trim();
|
|
if (string.IsNullOrEmpty(query)) return true;
|
|
|
|
return entry.CleanKey.Contains(query, StringComparison.OrdinalIgnoreCase) ||
|
|
entry.RawKey.Contains(query, StringComparison.OrdinalIgnoreCase) ||
|
|
entry.EditValue.Contains(query, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
private void txtSearchPrefs_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
_prefsView.Refresh();
|
|
}
|
|
|
|
private void dgPlayerPrefs_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (dgPlayerPrefs.SelectedItem is PlayerPrefsEntry entry)
|
|
{
|
|
lblSelectedKeyName.Text = entry.CleanKey;
|
|
txtEditValueBar.Text = entry.EditValue;
|
|
txtEditValueBar.IsEnabled = true;
|
|
btnSaveCurrentPref.IsEnabled = true;
|
|
btnDeleteCurrentPref.IsEnabled = true;
|
|
}
|
|
else
|
|
{
|
|
lblSelectedKeyName.Text = "(なし)";
|
|
txtEditValueBar.Text = string.Empty;
|
|
txtEditValueBar.IsEnabled = false;
|
|
btnSaveCurrentPref.IsEnabled = false;
|
|
btnDeleteCurrentPref.IsEnabled = false;
|
|
}
|
|
}
|
|
|
|
private void txtEditValueBar_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Enter)
|
|
{
|
|
SaveCurrentSelectedPref();
|
|
}
|
|
}
|
|
|
|
private void btnSaveCurrentPref_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SaveCurrentSelectedPref();
|
|
}
|
|
|
|
private void SaveCurrentSelectedPref()
|
|
{
|
|
if (dgPlayerPrefs.SelectedItem is not PlayerPrefsEntry entry) return;
|
|
|
|
entry.EditValue = txtEditValueBar.Text;
|
|
bool success = _saveService.SavePlayerPref(Game.RegistryPath, entry);
|
|
if (success)
|
|
{
|
|
lblStatus.Text = $"キー '{entry.CleanKey}' の値を正常に更新しました。";
|
|
dgPlayerPrefs.Items.Refresh();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show($"キー '{entry.CleanKey}' の値の更新に失敗しました。型が正しいか確認してください。",
|
|
"保存失敗", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void btnDeleteCurrentPref_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (dgPlayerPrefs.SelectedItem is not PlayerPrefsEntry entry) return;
|
|
|
|
var res = MessageBox.Show($"キー '{entry.CleanKey}' ({entry.RawKey}) をレジストリから削除しますか?",
|
|
"キー削除の確認", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
|
if (res != MessageBoxResult.Yes) return;
|
|
|
|
if (_saveService.DeletePlayerPref(Game.RegistryPath, entry.RawKey))
|
|
{
|
|
_allPrefs.Remove(entry);
|
|
lblStatus.Text = $"キー '{entry.CleanKey}' を削除しました。";
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("キーの削除に失敗しました。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void btnAddPref_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var dlg = new AddKeyDialog { Owner = this };
|
|
if (dlg.ShowDialog() == true)
|
|
{
|
|
if (_saveService.AddPlayerPref(Game.RegistryPath, dlg.KeyName, dlg.KeyType, dlg.KeyValue, out string rawKey))
|
|
{
|
|
ReloadPlayerPrefs();
|
|
lblStatus.Text = $"新規キー '{dlg.KeyName}' ({rawKey}) を追加しました。";
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("キーの追加に失敗しました。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnBackupPrefs_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var backupDir = AppPathHelper.GetGameBackupDirectory(Game.FolderName, Game.RootDirectory);
|
|
var result = _saveService.BackupRegistry(Game.RegistryPath, backupDir);
|
|
if (result != null)
|
|
{
|
|
ReloadBackups();
|
|
lblStatus.Text = $"レジストリをバックアップしました: {Path.GetFileName(result)}";
|
|
MessageBox.Show($"レジストリをバックアップしました:\n\n{result}", "バックアップ完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("レジストリのバックアップに失敗しました。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void btnRestorePrefs_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var backupDir = AppPathHelper.GetGameBackupDirectory(Game.FolderName, Game.RootDirectory);
|
|
var dlg = new OpenFileDialog
|
|
{
|
|
Title = "復元する .reg ファイルを選択",
|
|
InitialDirectory = Directory.Exists(backupDir) ? backupDir : AppPathHelper.GetBackupsDirectory(),
|
|
Filter = "レジストリファイル (*.reg)|*.reg|すべてのファイル (*.*)|*.*"
|
|
};
|
|
|
|
if (dlg.ShowDialog() == true)
|
|
{
|
|
var res = MessageBox.Show($"ファイル '{Path.GetFileName(dlg.FileName)}' からレジストリを復元しますか?\n現在のPlayerPrefs値は上書きされます。",
|
|
"復元の確認", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
|
if (res != MessageBoxResult.Yes) return;
|
|
|
|
if (_saveService.RestoreRegistry(dlg.FileName))
|
|
{
|
|
ReloadPlayerPrefs();
|
|
lblStatus.Text = "レジストリを正常に復元しました。";
|
|
MessageBox.Show("レジストリを正常に復元しました。", "復元完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("レジストリの復元に失敗しました。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnReloadPrefs_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ReloadPlayerPrefs();
|
|
}
|
|
|
|
private void ctxSavePref_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SaveCurrentSelectedPref();
|
|
}
|
|
|
|
private void ctxCopyKey_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (dgPlayerPrefs.SelectedItem is PlayerPrefsEntry entry)
|
|
{
|
|
Clipboard.SetText(entry.CleanKey);
|
|
}
|
|
}
|
|
|
|
private void ctxCopyValue_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (dgPlayerPrefs.SelectedItem is PlayerPrefsEntry entry)
|
|
{
|
|
Clipboard.SetText(entry.EditValue);
|
|
}
|
|
}
|
|
|
|
private void ctxDeletePref_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
btnDeleteCurrentPref_Click(sender, e);
|
|
}
|
|
|
|
// ====================================================================
|
|
// セーブファイル タブ処理(GUI / テキスト / 未対応プロンプト)
|
|
// ====================================================================
|
|
|
|
public void ReloadSaveFiles()
|
|
{
|
|
_saveFiles.Clear();
|
|
var files = _saveService.GetSaveFiles(Game);
|
|
foreach (var f in files)
|
|
{
|
|
_saveFiles.Add(f);
|
|
}
|
|
|
|
if (_saveFiles.Count > 0)
|
|
{
|
|
lstSaveFiles.SelectedIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
lblCurrentFileName.Text = "セーブファイルは見つかりませんでした";
|
|
lblCurrentFilePath.Text = string.Empty;
|
|
txtFileContent.Text = string.Empty;
|
|
HideAllEditorPanels();
|
|
}
|
|
}
|
|
|
|
private void HideAllEditorPanels()
|
|
{
|
|
pnlGuiEditor.Visibility = Visibility.Collapsed;
|
|
pnlTextEditor.Visibility = Visibility.Collapsed;
|
|
pnlUnsupportedBinary.Visibility = Visibility.Collapsed;
|
|
btnFormatJson.Visibility = Visibility.Collapsed;
|
|
btnSaveFileContent.Visibility = Visibility.Collapsed;
|
|
btnSaveGuiProperties.Visibility = Visibility.Collapsed;
|
|
badgeCodec.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
private void lstSaveFiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (lstSaveFiles.SelectedItem is not SaveFileEntry entry) return;
|
|
_currentSelectedFile = entry;
|
|
|
|
lblCurrentFileName.Text = entry.FileName;
|
|
lblCurrentFilePath.Text = entry.FilePath;
|
|
HideAllEditorPanels();
|
|
|
|
// 1. コーデック(対応形式)が存在するか判定
|
|
var codec = SaveDataCodecManager.Instance.FindCodec(Game, entry);
|
|
if (codec != null)
|
|
{
|
|
// GUI エディタモードをアクティブ化
|
|
_currentCodec = codec;
|
|
badgeCodec.Visibility = Visibility.Visible;
|
|
lblCodecName.Text = codec.CodecName;
|
|
|
|
LoadGuiPropertiesFromCodec(codec, entry.FilePath);
|
|
pnlGuiEditor.Visibility = Visibility.Visible;
|
|
btnSaveGuiProperties.Visibility = Visibility.Visible;
|
|
lblStatus.Text = $"{codec.CodecName} で読み込みました: {entry.FileName}";
|
|
return;
|
|
}
|
|
|
|
// 2. プレーンテキスト/JSON形式の場合
|
|
if (entry.IsTextOrJson)
|
|
{
|
|
pnlTextEditor.Visibility = Visibility.Visible;
|
|
txtFileContent.Text = _saveService.ReadSaveFileText(entry.FilePath);
|
|
btnFormatJson.Visibility = Visibility.Visible;
|
|
btnSaveFileContent.Visibility = Visibility.Visible;
|
|
lblStatus.Text = $"テキストとして開きました: {entry.FileName}";
|
|
return;
|
|
}
|
|
|
|
// 3. 未対応のバイナリセーブデータ形式の場合
|
|
pnlUnsupportedBinary.Visibility = Visibility.Visible;
|
|
DisplayUnsupportedBinaryInfo(entry);
|
|
lblStatus.Text = $"未対応のバイナリセーブデータ: {entry.FileName}";
|
|
}
|
|
|
|
private void LoadGuiPropertiesFromCodec(ISaveDataCodec codec, string filePath)
|
|
{
|
|
_guiProperties.Clear();
|
|
var props = codec.LoadProperties(filePath);
|
|
foreach (var p in props)
|
|
{
|
|
_guiProperties.Add(p);
|
|
}
|
|
lblGuiPropCount.Text = $"{props.Count} 項目";
|
|
if (props.Count > 0)
|
|
{
|
|
dgGuiProperties.SelectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
private bool FilterGuiProperties(object obj)
|
|
{
|
|
if (obj is not SaveDataPropertyEntry prop) return false;
|
|
var query = txtSearchGuiProps.Text.Trim();
|
|
if (string.IsNullOrEmpty(query)) return true;
|
|
|
|
return prop.Key.Contains(query, StringComparison.OrdinalIgnoreCase) ||
|
|
prop.Category.Contains(query, StringComparison.OrdinalIgnoreCase) ||
|
|
prop.EditValue.Contains(query, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
private void txtSearchGuiProps_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
_guiPropsView.Refresh();
|
|
int visibleCount = _guiPropsView.Cast<object>().Count();
|
|
lblGuiPropCount.Text = $"{visibleCount} / {_guiProperties.Count} 項目";
|
|
}
|
|
|
|
private void dgGuiProperties_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (dgGuiProperties.SelectedItem is SaveDataPropertyEntry prop)
|
|
{
|
|
lblSelectedPropKey.Text = prop.Key;
|
|
txtEditPropValueBar.Text = prop.EditValue;
|
|
txtEditPropValueBar.IsEnabled = true;
|
|
btnApplyPropValue.IsEnabled = true;
|
|
}
|
|
else
|
|
{
|
|
lblSelectedPropKey.Text = "(未選択)";
|
|
txtEditPropValueBar.Text = string.Empty;
|
|
txtEditPropValueBar.IsEnabled = false;
|
|
btnApplyPropValue.IsEnabled = false;
|
|
}
|
|
}
|
|
|
|
private void txtEditPropValueBar_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Enter)
|
|
{
|
|
btnApplyPropValue_Click(sender, e);
|
|
}
|
|
}
|
|
|
|
private void btnApplyPropValue_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (dgGuiProperties.SelectedItem is SaveDataPropertyEntry prop)
|
|
{
|
|
prop.EditValue = txtEditPropValueBar.Text;
|
|
dgGuiProperties.Items.Refresh();
|
|
lblStatus.Text = $"項目 '{prop.Key}' の値を変更しました。(「変更を保存」ボタンでファイルへ書き戻せます)";
|
|
}
|
|
}
|
|
|
|
private void btnSaveGuiProperties_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_currentSelectedFile == null || _currentCodec == null) return;
|
|
|
|
bool success = _currentCodec.SaveProperties(_currentSelectedFile.FilePath, _guiProperties.ToList());
|
|
if (success)
|
|
{
|
|
lblStatus.Text = $"セーブファイルを正常に更新しました (自動バックアップ .bak 作成済み): {_currentSelectedFile.FileName}";
|
|
MessageBox.Show("セーブファイルを正常に更新・保存しました。\n(元のファイルは同階層に .bak として自動バックアップされています)",
|
|
"保存完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("セーブデータの保存・再エンコードに失敗しました。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void DisplayUnsupportedBinaryInfo(SaveFileEntry entry)
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(entry.FilePath))
|
|
{
|
|
byte[] bytes = File.ReadAllBytes(entry.FilePath);
|
|
int count = Math.Min(32, bytes.Length);
|
|
var hexList = new List<string>();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
hexList.Add(bytes[i].ToString("X2"));
|
|
}
|
|
lblHexPreview.Text = string.Join(" ", hexList) + (bytes.Length > 32 ? " ..." : "");
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
lblHexPreview.Text = "(読み込み失敗)";
|
|
}
|
|
}
|
|
|
|
private void btnCopyIdePrompt_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_currentSelectedFile == null) return;
|
|
|
|
string prompt = SaveDataCodecManager.Instance.GenerateAntigravityPrompt(Game, _currentSelectedFile);
|
|
Clipboard.SetText(prompt);
|
|
|
|
lblStatus.Text = "📋 Antigravity IDE 用の解析依頼プロンプトをクリップボードにコピーしました!";
|
|
MessageBox.Show("Antigravity IDE 解析用プロンプトをコピーしました!\n\nAntigravity IDE のチャット欄に貼り付けて送信すると、AIがこのゲームのセーブデータ構造を解析し、GUI編集プラグインを自動で追加してくれます。",
|
|
"プロンプトをコピーしました", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
|
|
private void btnForceShowBinary_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_currentSelectedFile == null) return;
|
|
pnlUnsupportedBinary.Visibility = Visibility.Collapsed;
|
|
pnlTextEditor.Visibility = Visibility.Visible;
|
|
btnSaveFileContent.Visibility = Visibility.Visible;
|
|
txtFileContent.Text = _saveService.ReadSaveFileText(_currentSelectedFile.FilePath);
|
|
}
|
|
|
|
private void btnFormatJson_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var raw = txtFileContent.Text;
|
|
if (string.IsNullOrWhiteSpace(raw)) return;
|
|
|
|
using var doc = JsonDocument.Parse(raw);
|
|
var formatted = JsonSerializer.Serialize(doc.RootElement, new JsonSerializerOptions
|
|
{
|
|
WriteIndented = true,
|
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
});
|
|
txtFileContent.Text = formatted;
|
|
lblStatus.Text = "JSONを整形しました。";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"JSONの解析に失敗しました:\n\n{ex.Message}", "フォーマット失敗", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
}
|
|
}
|
|
|
|
private void btnSaveFileContent_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_currentSelectedFile == null) return;
|
|
|
|
bool success = _saveService.WriteSaveFileText(_currentSelectedFile.FilePath, txtFileContent.Text);
|
|
if (success)
|
|
{
|
|
lblStatus.Text = $"ファイルを保存しました (自動バックアップ .bak 作成済み): {_currentSelectedFile.FileName}";
|
|
MessageBox.Show("ファイルを保存しました。\n(元のファイルは同階層に .bak としてバックアップされています)",
|
|
"保存完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("ファイルの保存に失敗しました。書き込み権限等を確認してください。",
|
|
"エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void btnBackupSingleFile_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_currentSelectedFile == null) return;
|
|
|
|
var backupDir = AppPathHelper.GetGameBackupDirectory(Game.FolderName, Game.RootDirectory);
|
|
var result = _saveService.BackupSaveFile(_currentSelectedFile.FilePath, backupDir);
|
|
if (result != null)
|
|
{
|
|
ReloadBackups();
|
|
lblStatus.Text = $"ファイルをバックアップしました: {Path.GetFileName(result)}";
|
|
MessageBox.Show($"ファイルをバックアップしました:\n\n{result}", "バックアップ完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("ファイルのバックアップに失敗しました。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void btnReloadSaveFiles_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ReloadSaveFiles();
|
|
}
|
|
|
|
// ====================================================================
|
|
// バックアップ履歴 タブ処理
|
|
// ====================================================================
|
|
|
|
public void ReloadBackups()
|
|
{
|
|
_backups.Clear();
|
|
var list = _saveService.GetBackupList(Game);
|
|
foreach (var b in list)
|
|
{
|
|
_backups.Add(b);
|
|
}
|
|
}
|
|
|
|
private void btnReloadBackups_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ReloadBackups();
|
|
}
|
|
|
|
private void btnOpenBackupDir_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var backupDir = AppPathHelper.GetGameBackupDirectory(Game.FolderName, Game.RootDirectory);
|
|
UnitySaveManagerService.OpenFolderInExplorer(backupDir);
|
|
}
|
|
|
|
private void btnRestoreFromBackupRow_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is not Button btn || btn.DataContext is not SaveBackupEntry backup) return;
|
|
|
|
if (backup.BackupPath.EndsWith(".reg", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
var res = MessageBox.Show($"レジストリバックアップ '{backup.Name}' を復元しますか?",
|
|
"復元の確認", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
|
if (res == MessageBoxResult.Yes)
|
|
{
|
|
if (_saveService.RestoreRegistry(backup.BackupPath))
|
|
{
|
|
ReloadPlayerPrefs();
|
|
MessageBox.Show("レジストリを正常に復元しました。", "復元完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("復元に失敗しました。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show($"バックアップファイル:\n{backup.BackupPath}\n\nバックアップフォルダから復元したい場所へコピーしてください。",
|
|
"バックアップファイルの復元", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
UnitySaveManagerService.OpenFolderInExplorer(Path.GetDirectoryName(backup.BackupPath)!);
|
|
}
|
|
}
|
|
|
|
// ====================================================================
|
|
// ヘッダークイックオープン
|
|
// ====================================================================
|
|
|
|
private void btnOpenLocalLow_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(Game.LocalLowPath))
|
|
{
|
|
if (!Directory.Exists(Game.LocalLowPath))
|
|
{
|
|
var parent = Path.GetDirectoryName(Game.LocalLowPath);
|
|
if (parent != null && Directory.Exists(parent))
|
|
{
|
|
UnitySaveManagerService.OpenFolderInExplorer(parent);
|
|
return;
|
|
}
|
|
}
|
|
UnitySaveManagerService.OpenFolderInExplorer(Game.LocalLowPath);
|
|
}
|
|
}
|
|
|
|
private void btnOpenGameFolder_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
UnitySaveManagerService.OpenFolderInExplorer(Game.RootDirectory);
|
|
}
|
|
|
|
private void btnOpenRegedit_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
_saveService.OpenRegistryEditor(Game.RegistryPath);
|
|
}
|
|
}
|
|
}
|