150 lines
4.4 KiB
C#
150 lines
4.4 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using gregExtractor.Utils;
|
|
|
|
namespace gregExtractor.GUI.ViewModels;
|
|
|
|
public sealed class SettingsViewModel : ObservableObject
|
|
{
|
|
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);
|
|
}
|
|
|
|
public string FrameworkSourcePath
|
|
{
|
|
get => _frameworkSourcePath;
|
|
set => SetProperty(ref _frameworkSourcePath, value);
|
|
}
|
|
|
|
public string ModsOutputPath
|
|
{
|
|
get => _modsOutputPath;
|
|
set => SetProperty(ref _modsOutputPath, value);
|
|
}
|
|
|
|
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
|
|
{
|
|
}
|
|
}
|
|
}
|