2023-10-07 22:48:43 -04:00
|
|
|
|
using System.Collections.Generic;
|
2023-10-18 02:59:41 -04:00
|
|
|
|
using System.ComponentModel;
|
2021-08-04 14:17:53 -07:00
|
|
|
|
using System.Linq;
|
2022-07-26 13:47:19 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2021-09-29 11:48:37 -07:00
|
|
|
|
using MPF.Core.Data;
|
2023-10-07 01:30:11 -04:00
|
|
|
|
using MPF.Core.UI.ComboBoxItems;
|
2023-09-05 00:08:09 -04:00
|
|
|
|
using SabreTools.RedumpLib.Web;
|
2021-08-04 14:17:53 -07:00
|
|
|
|
|
2023-10-07 23:37:01 -04:00
|
|
|
|
namespace MPF.Core.UI.ViewModels
|
2021-08-04 14:17:53 -07:00
|
|
|
|
{
|
2023-11-14 23:40:41 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor
|
|
|
|
|
|
/// </summary>
|
2023-11-23 03:37:00 -05:00
|
|
|
|
public class OptionsViewModel : INotifyPropertyChanged
|
2021-08-04 14:17:53 -07:00
|
|
|
|
{
|
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
2023-10-18 02:59:41 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Title for the window
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string? Title
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _title;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_title = value;
|
|
|
|
|
|
TriggerPropertyChanged(nameof(Title));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private string? _title;
|
|
|
|
|
|
|
2021-08-04 14:17:53 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Current set of options
|
|
|
|
|
|
/// </summary>
|
2023-11-23 03:37:00 -05:00
|
|
|
|
public Options Options { get; }
|
2021-08-04 14:17:53 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Flag for if settings were saved or not
|
|
|
|
|
|
/// </summary>
|
2023-10-07 23:37:01 -04:00
|
|
|
|
public bool SavedSettings { get; set; }
|
2021-08-04 14:17:53 -07:00
|
|
|
|
|
2023-10-18 02:59:41 -04:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
|
|
2023-11-06 22:07:40 -05:00
|
|
|
|
#endregion
|
2021-08-04 14:17:53 -07:00
|
|
|
|
|
|
|
|
|
|
#region Lists
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List of available internal programs
|
|
|
|
|
|
/// </summary>
|
2023-11-06 23:06:11 -05:00
|
|
|
|
public static List<Element<InternalProgram>> InternalPrograms => PopulateInternalPrograms();
|
2021-08-04 14:17:53 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Current list of supported system profiles
|
|
|
|
|
|
/// </summary>
|
2023-11-06 23:06:11 -05:00
|
|
|
|
public static List<RedumpSystemComboBoxItem> Systems => RedumpSystemComboBoxItem.GenerateElements().ToList();
|
2021-08-04 14:17:53 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2023-11-23 03:37:00 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor for pure view model
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public OptionsViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Options = new Options();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor for in-code
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public OptionsViewModel(Options baseOptions)
|
|
|
|
|
|
{
|
|
|
|
|
|
Options = new Options(baseOptions);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-04 14:17:53 -07:00
|
|
|
|
#region Population
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a complete list of supported internal programs
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static List<Element<InternalProgram>> PopulateInternalPrograms()
|
|
|
|
|
|
{
|
2024-02-06 12:57:26 -05:00
|
|
|
|
var internalPrograms = new List<InternalProgram> { InternalProgram.Redumper, InternalProgram.DiscImageCreator, InternalProgram.Aaru };
|
2021-08-04 14:17:53 -07:00
|
|
|
|
return internalPrograms.Select(ip => new Element<InternalProgram>(ip)).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region UI Commands
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Test Redump login credentials
|
|
|
|
|
|
/// </summary>
|
2023-11-21 11:13:58 -05:00
|
|
|
|
#if NET40
|
|
|
|
|
|
public static Task<(bool?, string?)> TestRedumpLogin(string username, string password)
|
|
|
|
|
|
#else
|
2023-11-06 23:06:11 -05:00
|
|
|
|
public static async Task<(bool?, string?)> TestRedumpLogin(string username, string password)
|
2023-11-21 11:13:58 -05:00
|
|
|
|
#endif
|
2021-08-04 14:17:53 -07:00
|
|
|
|
{
|
2023-11-22 23:38:59 -05:00
|
|
|
|
#if NET40
|
2023-11-21 11:13:58 -05:00
|
|
|
|
return Task.Factory.StartNew(() => RedumpWebClient.ValidateCredentials(username, password));
|
2023-11-20 13:15:06 -05:00
|
|
|
|
#elif NETFRAMEWORK
|
2023-11-14 23:09:55 -05:00
|
|
|
|
return await Task.Run(() => RedumpWebClient.ValidateCredentials(username, password));
|
|
|
|
|
|
#else
|
2023-10-07 22:40:51 -04:00
|
|
|
|
return await RedumpHttpClient.ValidateCredentials(username, password);
|
2023-11-14 23:09:55 -05:00
|
|
|
|
#endif
|
2021-08-04 14:17:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-09 20:54:52 -04:00
|
|
|
|
#endregion
|
2023-10-18 02:59:41 -04:00
|
|
|
|
|
|
|
|
|
|
#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
|
2021-08-04 14:17:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|