177 lines
5.8 KiB
C#
177 lines
5.8 KiB
C#
using System;
|
||
using System.ComponentModel;
|
||
using System.Linq;
|
||
using System.Runtime.CompilerServices;
|
||
|
||
namespace GameLauncher.Models
|
||
{
|
||
/// <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 => _rawKey;
|
||
set { if (_rawKey != value) { _rawKey = value; OnPropertyChanged(); } }
|
||
}
|
||
|
||
/// <summary>Unityのハッシュを除去した整形式キー名(例: ClearedLevel)</summary>
|
||
public string CleanKey
|
||
{
|
||
get => _cleanKey;
|
||
set { if (_cleanKey != value) { _cleanKey = value; OnPropertyChanged(); } }
|
||
}
|
||
|
||
/// <summary>値のデータ型</summary>
|
||
public PlayerPrefsType Type
|
||
{
|
||
get => _type;
|
||
set { if (_type != value) { _type = value; OnPropertyChanged(); OnPropertyChanged(nameof(TypeDisplay)); } }
|
||
}
|
||
|
||
/// <summary>実際の値(int, float, string, byte[])</summary>
|
||
public object? Value
|
||
{
|
||
get => _value;
|
||
set
|
||
{
|
||
if (!Equals(_value, value))
|
||
{
|
||
_value = value;
|
||
OnPropertyChanged();
|
||
UpdateEditValue();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>UI表示・編集用の文字列値</summary>
|
||
public string EditValue
|
||
{
|
||
get => _editValue;
|
||
set
|
||
{
|
||
if (_editValue != value)
|
||
{
|
||
_editValue = value;
|
||
_isModified = true;
|
||
OnPropertyChanged();
|
||
OnPropertyChanged(nameof(IsModified));
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>値が変更されたかどうか</summary>
|
||
public bool IsModified
|
||
{
|
||
get => _isModified;
|
||
set { if (_isModified != value) { _isModified = value; OnPropertyChanged(); } }
|
||
}
|
||
|
||
public string TypeDisplay => Type switch
|
||
{
|
||
PlayerPrefsType.Int => "Int (数値)",
|
||
PlayerPrefsType.Float => "Float (小数)",
|
||
PlayerPrefsType.String => "String (文字列)",
|
||
PlayerPrefsType.Binary => "Binary (バイナリ)",
|
||
_ => "Unknown"
|
||
};
|
||
|
||
private void UpdateEditValue()
|
||
{
|
||
if (_value == null)
|
||
{
|
||
_editValue = string.Empty;
|
||
}
|
||
else if (_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'))
|
||
{
|
||
_editValue = text;
|
||
_type = PlayerPrefsType.String;
|
||
return;
|
||
}
|
||
}
|
||
catch { }
|
||
|
||
if (bytes.Length == 4)
|
||
{
|
||
float f = BitConverter.ToSingle(bytes, 0);
|
||
if (!float.IsNaN(f) && !float.IsInfinity(f))
|
||
{
|
||
_editValue = f.ToString("G");
|
||
_type = PlayerPrefsType.Float;
|
||
return;
|
||
}
|
||
}
|
||
|
||
_editValue = BitConverter.ToString(bytes).Replace("-", " ");
|
||
}
|
||
else
|
||
{
|
||
_editValue = _value.ToString() ?? string.Empty;
|
||
}
|
||
_isModified = false;
|
||
OnPropertyChanged(nameof(EditValue));
|
||
OnPropertyChanged(nameof(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 (FileSize < 1024) return $"{FileSize} B";
|
||
if (FileSize < 1024 * 1024) return $"{FileSize / 1024.0:F1} KB";
|
||
return $"{FileSize / (1024.0 * 1024.0):F2} MB";
|
||
}
|
||
}
|
||
|
||
public string LastModifiedDisplay => 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 => Timestamp.ToString("yyyy/MM/dd HH:mm:ss");
|
||
}
|
||
}
|