mirror of
https://github.com/SabreTools/MPF.git
synced 2026-02-15 05:36:04 +00:00
* Abstract out non-UI code to separate DLL This change seems rather large, but it's mostly just moving anything that is not directly driving the UI to its own, separate library. This will make it easier at a later date for any UI improvements or changes as well as making the code much more discrete. One TODO has been added as a result of this change. * Remove MessageBox from library This change removes the last UI-driven elements from the library. This now makes the library (in theory) UI-agnostic and removes the TODO. * Options is more UI-related * Fix Nuget references in csproj * Add Winforms UI This is a clone of the current WPF UI but implemented in Windows Forms. WPF is not currently supported by Mono for Linux and macOS, so this can provide an alternative to those users who want to run on those systems instead. This also adds a second artifact for the Winforms build.
98 lines
4.6 KiB
C#
98 lines
4.6 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.Reflection;
|
|
using DICUI.Data;
|
|
|
|
namespace DICUI
|
|
{
|
|
public class Options
|
|
{
|
|
public string DefaultOutputPath { get; private set; }
|
|
public string DICPath { get; private set; }
|
|
public string SubDumpPath { get; private set; }
|
|
|
|
public int preferredDumpSpeedCD { get; set; }
|
|
public int preferredDumpSpeedDVD { get; set; }
|
|
public int preferredDumpSpeedBD { get; set; }
|
|
|
|
public bool QuietMode { get; set; }
|
|
public bool ParanoidMode { get; set; }
|
|
public bool ScanForProtection { get; set; }
|
|
public int RereadAmountForC2 { get; set; }
|
|
|
|
public bool SkipMediaTypeDetection { get; set; }
|
|
|
|
public bool VerboseLogging { get; set; }
|
|
public bool OpenLogWindowAtStartup { get; set; }
|
|
|
|
public void Save()
|
|
{
|
|
Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
|
//TODO: reflection is used
|
|
//TODO: is remove needed, doesn't the value get directly overridden
|
|
Array.ForEach(
|
|
GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance),
|
|
p => {
|
|
configFile.AppSettings.Settings.Remove(p.Name);
|
|
configFile.AppSettings.Settings.Add(p.Name, Convert.ToString(p.GetValue(this)));
|
|
}
|
|
);
|
|
|
|
configFile.Save(ConfigurationSaveMode.Modified);
|
|
}
|
|
|
|
public void Load()
|
|
{
|
|
//TODO: hardcoded, we should find a better way
|
|
DICPath = ConfigurationManager.AppSettings["DICPath"] ?? @"Programs\DiscImageCreator.exe";
|
|
SubDumpPath = ConfigurationManager.AppSettings["SubDumpPath"] ?? "subdump.exe";
|
|
DefaultOutputPath = ConfigurationManager.AppSettings["DefaultOutputPath"] ?? "ISO";
|
|
|
|
this.preferredDumpSpeedCD = Int32.TryParse(ConfigurationManager.AppSettings["preferredDumpSpeedCD"], out int maxDumpSpeedCD) ? maxDumpSpeedCD : 72;
|
|
this.preferredDumpSpeedDVD = Int32.TryParse(ConfigurationManager.AppSettings["preferredDumpSpeedDVD"], out int maxDumpSpeedDVD) ? maxDumpSpeedDVD : 24;
|
|
this.preferredDumpSpeedBD = Int32.TryParse(ConfigurationManager.AppSettings["preferredDumpSpeedBD"], out int maxDumpSpeedBD) ? maxDumpSpeedBD : 16;
|
|
|
|
this.QuietMode = Boolean.TryParse(ConfigurationManager.AppSettings["QuietMode"], out bool quietMode) ? quietMode : false;
|
|
this.ParanoidMode = Boolean.TryParse(ConfigurationManager.AppSettings["ParanoidMode"], out bool paranoidMode) ? paranoidMode : false;
|
|
this.ScanForProtection = Boolean.TryParse(ConfigurationManager.AppSettings["ScanForProtection"], out bool scanForProtection) ? scanForProtection : true;
|
|
this.SkipMediaTypeDetection = Boolean.TryParse(ConfigurationManager.AppSettings["SkipMediaTypeDetection"], out bool skipMediaTypeDetection) ? skipMediaTypeDetection : false;
|
|
this.RereadAmountForC2 = Int32.TryParse(ConfigurationManager.AppSettings["RereadAmountForC2"], out int rereadAmountForC2) ? rereadAmountForC2 : 20;
|
|
this.VerboseLogging = Boolean.TryParse(ConfigurationManager.AppSettings["VerboseLogging"], out bool verboseLogging) ? verboseLogging : true;
|
|
this.OpenLogWindowAtStartup = Boolean.TryParse(ConfigurationManager.AppSettings["OpenLogWindowAtStartup"], out bool openLogWindowAtStartup) ? openLogWindowAtStartup : true;
|
|
}
|
|
|
|
|
|
//TODO: probably should be generic for non-string options
|
|
//TODO: using reflection for Set and Get is orthodox but it works, should be changed to a key,value map probably
|
|
public void Set(string key, string value)
|
|
{
|
|
GetType().GetProperty(key, BindingFlags.Public | BindingFlags.Instance).SetValue(this, value);
|
|
}
|
|
|
|
public string Get(string key)
|
|
{
|
|
return GetType().GetProperty(key, BindingFlags.Public | BindingFlags.Instance).GetValue(this) as string;
|
|
}
|
|
|
|
public int GetPreferredDumpSpeedForMediaType(MediaType? type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case MediaType.CDROM:
|
|
case MediaType.GDROM:
|
|
return preferredDumpSpeedCD;
|
|
case MediaType.DVD:
|
|
case MediaType.HDDVD:
|
|
case MediaType.NintendoGameCube:
|
|
case MediaType.NintendoWiiOpticalDisc:
|
|
return preferredDumpSpeedDVD;
|
|
case MediaType.BluRay:
|
|
return preferredDumpSpeedBD;
|
|
default:
|
|
return 8;
|
|
}
|
|
}
|
|
}
|
|
}
|