Files
MPF/MPF.Frontend/ViewModels/OptionsViewModel.cs

163 lines
5.1 KiB
C#
Raw Permalink Normal View History

2026-02-07 14:13:29 -05:00
using System.Collections.Generic;
using System.ComponentModel;
2024-05-23 15:40:12 -04:00
using MPF.Frontend.ComboBoxItems;
using LogCompression = MPF.Processors.LogCompression;
2025-05-30 12:43:25 -04:00
using RedumperDriveType = MPF.ExecutionContexts.Redumper.DriveType;
2024-05-28 14:41:51 -04:00
using RedumperReadMethod = MPF.ExecutionContexts.Redumper.ReadMethod;
using RedumperSectorOrder = MPF.ExecutionContexts.Redumper.SectorOrder;
2024-05-23 15:40:12 -04:00
namespace MPF.Frontend.ViewModels
{
2023-11-14 23:40:41 -05:00
/// <summary>
/// Constructor
/// </summary>
2023-11-23 03:37:00 -05:00
public class OptionsViewModel : INotifyPropertyChanged
{
#region Fields
/// <summary>
/// Title for the window
/// </summary>
public string? Title
{
get => _title;
set
{
_title = value;
TriggerPropertyChanged(nameof(Title));
}
}
private string? _title;
/// <summary>
/// Current set of options
/// </summary>
2026-02-07 15:11:46 -05:00
public Options Options { get; }
/// <summary>
/// Flag for if settings were saved or not
/// </summary>
2023-10-07 23:37:01 -04:00
public bool SavedSettings { get; set; }
/// <inheritdoc/>
public event PropertyChangedEventHandler? PropertyChanged;
2023-11-06 22:07:40 -05:00
#endregion
#region Lists
/// <summary>
/// List of available internal programs
/// </summary>
2023-11-06 23:06:11 -05:00
public static List<Element<InternalProgram>> InternalPrograms => PopulateInternalPrograms();
Initial UI lang code (#899) * Test using resources * Include system namespace in resource xaml * system namespace name * rename strings * Default strings * Window resources * add keys * just one key * Combo box example * window resources * Dropdown in menu bar * nullable * non nullable * string list init * simple * English default * Add menu item for language * parent is menuitem * fix * no null lang * Only build win-x64, GHA storage limit * Korean * test * Set resource strings at app level * remove lost endif * Better UI * Move langs next to buttons * update * fix button * More translations * Better menu size * too many semicolons * top right menu bar * Tweaks * Top bar positioning * title bar width * try again * final * Back to original publish script * more windows * pre-merge test * Test non-latin underscore * More strings * fix * FindResource is a function * space * cast spells * Log about text * semicolon * Good * cast spells * using System.Windows in Frontend * Translate in MainViewModel * Dynamic GetFormattedVolumeLabel * Nullability * Fix * using for dict * Translate func in MVM * Don't translate in init * Update MVM translations * closing brace * Deprecate resource string * test * test2 * set current system * trial field * field is preview * default empty string * default null * fix build * empty string * GIve up on no system selected text * Fix context menu border * Revert half fix * Translate more IRD Window strings * Loose string * Detect current locale * fix * System.Globalization * Locale detection for default lang * break on zh case * default startup lang * default lang option * fix * fix2 * fix3 * nonnullable * final fix * final final fix * default language option * use default language on startup * empty entry * semicolon
2025-10-17 00:47:36 +09:00
/// <summary>
/// List of available interface languages
Initial UI lang code (#899) * Test using resources * Include system namespace in resource xaml * system namespace name * rename strings * Default strings * Window resources * add keys * just one key * Combo box example * window resources * Dropdown in menu bar * nullable * non nullable * string list init * simple * English default * Add menu item for language * parent is menuitem * fix * no null lang * Only build win-x64, GHA storage limit * Korean * test * Set resource strings at app level * remove lost endif * Better UI * Move langs next to buttons * update * fix button * More translations * Better menu size * too many semicolons * top right menu bar * Tweaks * Top bar positioning * title bar width * try again * final * Back to original publish script * more windows * pre-merge test * Test non-latin underscore * More strings * fix * FindResource is a function * space * cast spells * Log about text * semicolon * Good * cast spells * using System.Windows in Frontend * Translate in MainViewModel * Dynamic GetFormattedVolumeLabel * Nullability * Fix * using for dict * Translate func in MVM * Don't translate in init * Update MVM translations * closing brace * Deprecate resource string * test * test2 * set current system * trial field * field is preview * default empty string * default null * fix build * empty string * GIve up on no system selected text * Fix context menu border * Revert half fix * Translate more IRD Window strings * Loose string * Detect current locale * fix * System.Globalization * Locale detection for default lang * break on zh case * default startup lang * default lang option * fix * fix2 * fix3 * nonnullable * final fix * final final fix * default language option * use default language on startup * empty entry * semicolon
2025-10-17 00:47:36 +09:00
/// </summary>
public static List<Element<InterfaceLanguage>> InterfaceLanguages => Element<InterfaceLanguage>.GenerateElements();
Initial UI lang code (#899) * Test using resources * Include system namespace in resource xaml * system namespace name * rename strings * Default strings * Window resources * add keys * just one key * Combo box example * window resources * Dropdown in menu bar * nullable * non nullable * string list init * simple * English default * Add menu item for language * parent is menuitem * fix * no null lang * Only build win-x64, GHA storage limit * Korean * test * Set resource strings at app level * remove lost endif * Better UI * Move langs next to buttons * update * fix button * More translations * Better menu size * too many semicolons * top right menu bar * Tweaks * Top bar positioning * title bar width * try again * final * Back to original publish script * more windows * pre-merge test * Test non-latin underscore * More strings * fix * FindResource is a function * space * cast spells * Log about text * semicolon * Good * cast spells * using System.Windows in Frontend * Translate in MainViewModel * Dynamic GetFormattedVolumeLabel * Nullability * Fix * using for dict * Translate func in MVM * Don't translate in init * Update MVM translations * closing brace * Deprecate resource string * test * test2 * set current system * trial field * field is preview * default empty string * default null * fix build * empty string * GIve up on no system selected text * Fix context menu border * Revert half fix * Translate more IRD Window strings * Loose string * Detect current locale * fix * System.Globalization * Locale detection for default lang * break on zh case * default startup lang * default lang option * fix * fix2 * fix3 * nonnullable * final fix * final final fix * default language option * use default language on startup * empty entry * semicolon
2025-10-17 00:47:36 +09:00
/// <summary>
/// List of available log compression methods
/// </summary>
2025-10-16 22:35:31 -04:00
public static List<Element<LogCompression>> LogCompressions => Element<LogCompression>.GenerateElements();
/// <summary>
/// Current list of supported Redumper read methods
/// </summary>
2025-10-16 22:35:31 -04:00
public static List<Element<RedumperReadMethod>> RedumperReadMethods => Element<RedumperReadMethod>.GenerateElements();
/// <summary>
/// Current list of supported Redumper sector orders
/// </summary>
2025-10-16 22:35:31 -04:00
public static List<Element<RedumperSectorOrder>> RedumperSectorOrders => Element<RedumperSectorOrder>.GenerateElements();
/// <summary>
/// Current list of supported Redumper drive types
/// </summary>
2025-10-16 22:35:31 -04:00
public static List<Element<RedumperDriveType>> RedumperDriveTypes => Element<RedumperDriveType>.GenerateElements();
/// <summary>
/// Current list of supported system profiles
/// </summary>
2024-11-21 11:55:00 -05:00
public static List<RedumpSystemComboBoxItem> Systems => RedumpSystemComboBoxItem.GenerateElements();
#endregion
2023-11-23 03:37:00 -05:00
/// <summary>
/// Constructor for pure view model
/// </summary>
public OptionsViewModel()
{
2026-02-07 15:11:46 -05:00
Options = new Options();
2023-11-23 03:37:00 -05:00
}
/// <summary>
/// Constructor for in-code
/// </summary>
2026-02-07 15:11:46 -05:00
public OptionsViewModel(Options baseOptions)
2023-11-23 03:37:00 -05:00
{
2026-02-07 15:11:46 -05:00
Options = new Options(baseOptions);
2023-11-23 03:37:00 -05:00
}
#region Population
/// <summary>
/// Get a complete list of supported internal programs
/// </summary>
private static List<Element<InternalProgram>> PopulateInternalPrograms()
{
2026-01-27 16:16:34 -05:00
var internalPrograms = new List<InternalProgram>
{
InternalProgram.Redumper,
InternalProgram.DiscImageCreator,
InternalProgram.Aaru,
// InternalProgram.Dreamdump,
};
2024-11-12 22:18:08 -05:00
return internalPrograms.ConvertAll(ip => new Element<InternalProgram>(ip));
}
#endregion
#region UI Commands
/// <summary>
/// Get the human-readable result for a Redump login result
/// </summary>
public static string GetRedumpLoginResult(bool? success)
{
return success switch
2024-10-18 13:04:53 -04:00
{
true => "Redump username and password accepted!",
false => "Redump username and password denied!",
null => "An error occurred validating your credentials!",
};
}
/// <summary>
/// Reset Redumper non-redump options (Read Method, Sector Order, Drive Type)
/// </summary>
public void NonRedumpModeUnChecked()
{
Options.Dumping.Redumper.ReadMethod = RedumperReadMethod.NONE;
Options.Dumping.Redumper.SectorOrder = RedumperSectorOrder.NONE;
Options.Dumping.Redumper.DriveType = RedumperDriveType.NONE;
TriggerPropertyChanged(nameof(Options));
}
#endregion
#region Property Updates
/// <summary>
/// Trigger a property changed event
/// </summary>
private void TriggerPropertyChanged(string propertyName)
{
// If the property change event is initialized
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}