Files
Marvin 2f61e5dc00 Refactor ViewModels to inherit from BaseViewModel and improve UI thread handling
- Updated HookBrowserViewModel, MainViewModel, SettingsViewModel, and SyncViewModel to inherit from BaseViewModel.
- Introduced BaseViewModel with methods for running actions on the UI thread.
- Enhanced SyncViewModel to handle property changes on the UI thread.
- Refactored ExtractorService to return ExtractorResult instead of IReadOnlyList<HookDefinition>.
- Added ExtractorResult class to encapsulate extraction results, including success status and error messages.
- Implemented UIProgress class for reporting progress on the UI thread.
- Updated hook_groups.json with additional classes and methods for various categories.
- Improved error handling and logging in ExtractorService and SyncViewModel.
2026-04-20 04:26:06 +02:00

149 lines
4.5 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using gregExtractor.Utils;
namespace gregExtractor.GUI.ViewModels;
public sealed class SettingsViewModel : BaseViewModel
{
private string _gamePath = SteamLocator.FindGamePath() ?? string.Empty;
private string _frameworkSourcePath = Path.Combine(Directory.GetCurrentDirectory(), "..", "gregCore", "src");
private string _modsOutputPath = Directory.GetCurrentDirectory();
private bool _ignoreGettersSetters = true;
private bool _includePrivateMethods;
private bool _backupBeforeSync = true;
private bool _gitDiffAfterSync;
private bool _reduceAnimations;
private bool _monospaceEverywhere = true;
private bool _isLoading;
public SettingsViewModel()
{
BrowseGamePathCommand = new AsyncRelayCommand(BrowseGamePathAsync);
BrowseFrameworkPathCommand = new AsyncRelayCommand(BrowseFrameworkPathAsync);
BrowseOutputPathCommand = new AsyncRelayCommand(BrowseOutputPathAsync);
AutoDetectGamePathCommand = new RelayCommand(() => GamePath = SteamLocator.FindGamePath() ?? string.Empty);
CopyDebugInfoCommand = new RelayCommand(CopyDebugInfo);
}
public Func<string?, Task<string?>>? BrowseFolderHandler { get; set; }
public string GamePath
{
get => _gamePath;
set => SetProperty(ref _gamePath, value?.Trim() ?? string.Empty);
}
public string FrameworkSourcePath
{
get => _frameworkSourcePath;
set => SetProperty(ref _frameworkSourcePath, value?.Trim() ?? string.Empty);
}
public string ModsOutputPath
{
get => _modsOutputPath;
set => SetProperty(ref _modsOutputPath, value?.Trim() ?? string.Empty);
}
public bool IgnoreGettersSetters
{
get => _ignoreGettersSetters;
set => SetProperty(ref _ignoreGettersSetters, value);
}
public bool IncludePrivateMethods
{
get => _includePrivateMethods;
set => SetProperty(ref _includePrivateMethods, value);
}
public bool BackupBeforeSync
{
get => _backupBeforeSync;
set => SetProperty(ref _backupBeforeSync, value);
}
public bool GitDiffAfterSync
{
get => _gitDiffAfterSync;
set => SetProperty(ref _gitDiffAfterSync, value);
}
public bool ReduceAnimations
{
get => _reduceAnimations;
set => SetProperty(ref _reduceAnimations, value);
}
public bool MonospaceEverywhere
{
get => _monospaceEverywhere;
set => SetProperty(ref _monospaceEverywhere, value);
}
public bool IsLoading
{
get => _isLoading;
set => SetProperty(ref _isLoading, value);
}
public IAsyncRelayCommand BrowseGamePathCommand { get; }
public IAsyncRelayCommand BrowseFrameworkPathCommand { get; }
public IAsyncRelayCommand BrowseOutputPathCommand { get; }
public IRelayCommand AutoDetectGamePathCommand { get; }
public IRelayCommand CopyDebugInfoCommand { get; }
private async Task BrowseGamePathAsync()
{
if (BrowseFolderHandler is null)
return;
string? selected = await BrowseFolderHandler("SettingsGamePath").ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(selected))
GamePath = selected;
}
private async Task BrowseFrameworkPathAsync()
{
if (BrowseFolderHandler is null)
return;
string? selected = await BrowseFolderHandler("SettingsFrameworkPath").ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(selected))
FrameworkSourcePath = selected;
}
private async Task BrowseOutputPathAsync()
{
if (BrowseFolderHandler is null)
return;
string? selected = await BrowseFolderHandler("SettingsOutputPath").ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(selected))
ModsOutputPath = selected;
}
private void CopyDebugInfo()
{
string content =
$"gregExtractor Debug Info{Environment.NewLine}" +
$"GamePath={GamePath}{Environment.NewLine}" +
$"FrameworkSourcePath={FrameworkSourcePath}{Environment.NewLine}" +
$"ModsOutputPath={ModsOutputPath}{Environment.NewLine}" +
$"OS={Environment.OSVersion}{Environment.NewLine}" +
$"Runtime={Environment.Version}";
try
{
File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "debug-info.txt"), content, Encoding.UTF8);
}
catch
{
}
}
}