- 自インスタンスメンバーアクセスへの this. 付与(28ファイル) - .editorconfig に準拠したインデント・波括弧・空白スタイルの適用 - UTF-8 (BOMあり)、CRLF改行コード、行末空白除去の整合性検証
178 lines
6.1 KiB
C#
178 lines
6.1 KiB
C#
using System;
|
||
using System.ComponentModel;
|
||
using System.Linq;
|
||
using System.Runtime.CompilerServices;
|
||
using GameLauncher.Models;
|
||
|
||
namespace GameLauncher.Engines.Unity
|
||
{
|
||
/// <summary>
|
||
/// PlayerPrefs(レジストリ)の1エントリを表すモデル
|
||
/// </summary>
|
||
public class PlayerPrefsEntry : INotifyPropertyChanged
|
||
{
|
||
private string _rawKey = string.Empty;
|
||
private string _cleanKey = string.Empty;
|
||
private PlayerPrefsType _type = PlayerPrefsType.Int;
|
||
private object? _value;
|
||
private string _editValue = string.Empty;
|
||
private bool _isModified;
|
||
|
||
public event PropertyChangedEventHandler? PropertyChanged;
|
||
|
||
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||
{
|
||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||
}
|
||
|
||
/// <summary>レジストリの生キー名(例: ClearedLevel_h1378399435)</summary>
|
||
public string RawKey
|
||
{
|
||
get => this._rawKey;
|
||
set { if (this._rawKey != value) { this._rawKey = value; this.OnPropertyChanged(); } }
|
||
}
|
||
|
||
/// <summary>Unityのハッシュを除去した整形式キー名(例: ClearedLevel)</summary>
|
||
public string CleanKey
|
||
{
|
||
get => this._cleanKey;
|
||
set { if (this._cleanKey != value) { this._cleanKey = value; this.OnPropertyChanged(); } }
|
||
}
|
||
|
||
/// <summary>値のデータ型</summary>
|
||
public PlayerPrefsType Type
|
||
{
|
||
get => this._type;
|
||
set { if (this._type != value) { this._type = value; this.OnPropertyChanged(); this.OnPropertyChanged(nameof(this.TypeDisplay)); } }
|
||
}
|
||
|
||
/// <summary>実際の値(int, float, string, byte[])</summary>
|
||
public object? Value
|
||
{
|
||
get => this._value;
|
||
set
|
||
{
|
||
if (!Equals(this._value, value))
|
||
{
|
||
this._value = value;
|
||
this.OnPropertyChanged();
|
||
this.UpdateEditValue();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>UI表示・編集用の文字列値</summary>
|
||
public string EditValue
|
||
{
|
||
get => this._editValue;
|
||
set
|
||
{
|
||
if (this._editValue != value)
|
||
{
|
||
this._editValue = value;
|
||
this._isModified = true;
|
||
this.OnPropertyChanged();
|
||
this.OnPropertyChanged(nameof(this.IsModified));
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>値が変更されたかどうか</summary>
|
||
public bool IsModified
|
||
{
|
||
get => this._isModified;
|
||
set { if (this._isModified != value) { this._isModified = value; this.OnPropertyChanged(); } }
|
||
}
|
||
|
||
public string TypeDisplay => this.Type switch
|
||
{
|
||
PlayerPrefsType.Int => "Int (数値)",
|
||
PlayerPrefsType.Float => "Float (小数)",
|
||
PlayerPrefsType.String => "String (文字列)",
|
||
PlayerPrefsType.Binary => "Binary (バイナリ)",
|
||
_ => "Unknown"
|
||
};
|
||
|
||
private void UpdateEditValue()
|
||
{
|
||
if (this._value == null)
|
||
{
|
||
this._editValue = string.Empty;
|
||
}
|
||
else if (this._value is byte[] bytes)
|
||
{
|
||
try
|
||
{
|
||
var text = System.Text.Encoding.UTF8.GetString(bytes).TrimEnd('\0');
|
||
if (text.All(c => !char.IsControl(c) || c == '\r' || c == '\n' || c == '\t'))
|
||
{
|
||
this._editValue = text;
|
||
this._type = PlayerPrefsType.String;
|
||
return;
|
||
}
|
||
}
|
||
catch { }
|
||
|
||
if (bytes.Length == 4)
|
||
{
|
||
float f = BitConverter.ToSingle(bytes, 0);
|
||
if (!float.IsNaN(f) && !float.IsInfinity(f))
|
||
{
|
||
this._editValue = f.ToString("G");
|
||
this._type = PlayerPrefsType.Float;
|
||
return;
|
||
}
|
||
}
|
||
|
||
this._editValue = BitConverter.ToString(bytes).Replace("-", " ");
|
||
}
|
||
else
|
||
{
|
||
this._editValue = this._value.ToString() ?? string.Empty;
|
||
}
|
||
this._isModified = false;
|
||
this.OnPropertyChanged(nameof(this.EditValue));
|
||
this.OnPropertyChanged(nameof(this.IsModified));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// ディスク上のセーブファイル(LocalLow または ゲームフォルダ内)を表すモデル
|
||
/// </summary>
|
||
public class SaveFileEntry
|
||
{
|
||
public string FileName { get; set; } = string.Empty;
|
||
public string FilePath { get; set; } = string.Empty;
|
||
public long FileSize { get; set; }
|
||
public DateTime LastModified { get; set; }
|
||
public string LocationType { get; set; } = string.Empty; // "LocalLow" または "ゲームフォルダ"
|
||
public bool IsTextOrJson { get; set; }
|
||
|
||
public string FileSizeDisplay
|
||
{
|
||
get
|
||
{
|
||
if (this.FileSize < 1024) return $"{this.FileSize} B";
|
||
if (this.FileSize < 1024 * 1024) return $"{this.FileSize / 1024.0:F1} KB";
|
||
return $"{this.FileSize / (1024.0 * 1024.0):F2} MB";
|
||
}
|
||
}
|
||
|
||
public string LastModifiedDisplay => this.LastModified.ToString("yyyy/MM/dd HH:mm:ss");
|
||
}
|
||
|
||
/// <summary>
|
||
/// セーブデータのバックアップ履歴モデル
|
||
/// </summary>
|
||
public class SaveBackupEntry
|
||
{
|
||
public string Name { get; set; } = string.Empty;
|
||
public string BackupPath { get; set; } = string.Empty;
|
||
public DateTime Timestamp { get; set; }
|
||
public string BackupType { get; set; } = string.Empty; // "Registry (.reg)" または "ファイル"
|
||
public string Note { get; set; } = string.Empty;
|
||
|
||
public string TimestampDisplay => this.Timestamp.ToString("yyyy/MM/dd HH:mm:ss");
|
||
}
|
||
}
|