Start reorganizing options and internals

This commit is contained in:
Matt Nadareski
2020-05-06 14:24:37 -07:00
parent e01fd37e6b
commit 6742444182
9 changed files with 429 additions and 363 deletions

View File

@@ -102,19 +102,17 @@ namespace DICUI.Check
string filepath = Path.GetFullPath(args[i]);
// Now populate an environment
var env = new DumpEnvironment
var options = new Options
{
OutputDirectory = "",
OutputFilename = filepath,
System = knownSystem,
Type = mediaType,
InternalProgram = internalProgram,
ScanForProtection = false,
PromptForDiscInformation = false,
InternalProgram = Converters.ToInternalProgram(internalProgram),
Username = username,
Password = password,
};
var env = new DumpEnvironment(options, "", filepath, null, knownSystem, mediaType, null);
env.FixOutputPaths();
// Finally, attempt to do the output dance

View File

@@ -6,11 +6,11 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)'!='netcoreapp2.1' AND '$(TargetFramework)'!='netcoreapp3.1'">
<PropertyGroup Condition="'$(TargetFramework)'!='netcoreapp3.1'">
<DefineConstants>NET_FRAMEWORK</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)'!='netcoreapp2.1' AND '$(TargetFramework)'!='netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)'!='netcoreapp3.1'">
<COMReference Include="IMAPI2">
<Guid>{2735412F-7F64-5B0F-8F00-5D77AFBE261E}</Guid>
<VersionMajor>1</VersionMajor>

View File

@@ -0,0 +1,169 @@
using System;
using System.Collections.Generic;
namespace DICUI.Data
{
public class Options
{
#region Internal Program
public string AaruPath { get; set; }
public string CreatorPath { get; set; }
public string DDPath { get; set; }
public string InternalProgram { get; set; }
#endregion
#region Extra Paths
public string DefaultOutputPath { get; set; }
public string SubDumpPath { get; set; }
#endregion
#region Dumping Speeds
public int PreferredDumpSpeedCD { get; set; }
public int PreferredDumpSpeedDVD { get; set; }
public int PreferredDumpSpeedBD { get; set; }
#endregion
#region Extra Dumping Options
public bool QuietMode { get; set; }
public bool ParanoidMode { get; set; }
public bool ScanForProtection { get; set; }
public int RereadAmountForC2 { get; set; }
public bool AddPlaceholders { get; set; }
public bool PromptForDiscInformation { get; set; }
public bool IgnoreFixedDrives { get; set; }
public bool ResetDriveAfterDump { get; set; }
#endregion
#region Skip Options
public bool SkipMediaTypeDetection { get; set; }
public bool SkipSystemDetection { get; set; }
#endregion
#region Logging Options
public bool VerboseLogging { get; set; }
public bool OpenLogWindowAtStartup { get; set; }
#endregion
#region Redump Login Information
public string Username { get; set; }
public string Password { get; set; }
#endregion
/// <summary>
/// Load settings from a Dictionary<string, string></string>
/// </summary>
/// <param name="settings">Settings dictionary to pull from</param>
public void Load(Dictionary<string, string> settings)
{
// Internal Program
this.AaruPath = GetStringSetting(settings, "AaruPath", "Programs\\Aaru\\Aaru.exe");
this.CreatorPath = GetStringSetting(settings, "CreatorPath", "Programs\\Creator\\DiscImageCreator.exe");
this.DDPath = GetStringSetting(settings, "DDPath", "Programs\\DD\\dd.exe");
this.InternalProgram = GetStringSetting(settings, "InternalProgram", Data.InternalProgram.DiscImageCreator.ToString());
// Extra Paths
this.DefaultOutputPath = GetStringSetting(settings, "DefaultOutputPath", "ISO");
this.SubDumpPath = GetStringSetting(settings, "SubDumpPath", "Programs\\Subdump\\subdump.exe");
// Dumping Speeds
this.PreferredDumpSpeedCD = GetInt32Setting(settings, "PreferredDumpSpeedCD", 72);
this.PreferredDumpSpeedDVD = GetInt32Setting(settings, "PreferredDumpSpeedDVD", 24);
this.PreferredDumpSpeedBD = GetInt32Setting(settings, "PreferredDumpSpeedBD", 16);
// Extra Dumping Options
this.QuietMode = GetBooleanSetting(settings, "QuietMode", false);
this.ParanoidMode = GetBooleanSetting(settings, "ParanoidMode", false);
this.ScanForProtection = GetBooleanSetting(settings, "ScanForProtection", true);
this.RereadAmountForC2 = GetInt32Setting(settings, "RereadAmountForC2", 20);
this.AddPlaceholders = GetBooleanSetting(settings, "AddPlaceholders", true);
this.PromptForDiscInformation = GetBooleanSetting(settings, "PromptForDiscInformation", true);
this.IgnoreFixedDrives = GetBooleanSetting(settings, "IgnoreFixedDrives", false);
this.ResetDriveAfterDump = GetBooleanSetting(settings, "ResetDriveAfterDump", false);
// Skip Options
this.SkipMediaTypeDetection = GetBooleanSetting(settings, "SkipMediaTypeDetection", false);
this.SkipSystemDetection = GetBooleanSetting(settings, "SkipSystemDetection", false);
// Logging Options
this.VerboseLogging = GetBooleanSetting(settings, "VerboseLogging", true);
this.OpenLogWindowAtStartup = GetBooleanSetting(settings, "OpenLogWindowAtStartup", true);
// Redump Login Information
this.Username = GetStringSetting(settings, "Username", "");
this.Password = GetStringSetting(settings, "Password", "");
}
/// <summary>
/// Get a Boolean setting from a settings, dictionary
/// </summary>
/// <param name="settings">Dictionary representing the settings</param>
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
private bool GetBooleanSetting(Dictionary<string, string> settings, string key, bool defaultValue)
{
if (settings.ContainsKey(key))
{
if (Boolean.TryParse(settings[key], out bool value))
return value;
else
return defaultValue;
}
else
{
return defaultValue;
}
}
/// <summary>
/// Get an Int32 setting from a settings, dictionary
/// </summary>
/// <param name="settings">Dictionary representing the settings</param>
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
private int GetInt32Setting(Dictionary<string, string> settings, string key, int defaultValue)
{
if (settings.ContainsKey(key))
{
if (Int32.TryParse(settings[key], out int value))
return value;
else
return defaultValue;
}
else
{
return defaultValue;
}
}
/// <summary>
/// Get a String setting from a settings, dictionary
/// </summary>
/// <param name="settings">Dictionary representing the settings</param>
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
private string GetStringSetting(Dictionary<string, string> settings, string key, string defaultValue)
{
if (settings.ContainsKey(key))
return settings[key];
else
return defaultValue;
}
}
}

View File

@@ -18,6 +18,7 @@ namespace DICUI.Utilities
/// <summary>
/// Represents the state of all settings to be used during dumping
/// </summary>
/// TODO: Look into splitting this up in a more reasonable way
public class DumpEnvironment
{
#region Tool paths
@@ -60,16 +61,16 @@ namespace DICUI.Utilities
/// </summary>
public MediaType? Type { get; set; }
/// <summary>
/// Parameters object representing what to send to the internal program
/// </summary>
public BaseParameters Parameters { get; set; }
/// <summary>
/// Internal program to run
/// </summary>
public InternalProgram InternalProgram { get; set; }
/// <summary>
/// Parameters object representing what to send to the internal program
/// </summary>
public BaseParameters Parameters { get; set; }
/// <summary>
/// Scan for copy protection, where applicable
/// </summary>
@@ -135,10 +136,55 @@ namespace DICUI.Utilities
#endregion
/// <summary>
/// Empty constructor for the rest of the magic
/// Empty constructor for testing only
/// </summary>
public DumpEnvironment()
/// TODO: Remove this and fix tests
public DumpEnvironment() { }
/// <summary>
/// Constructor for a full DumpEnvironment object from user information
/// </summary>
/// <param name="options"></param>
/// <param name="outputDirectory"></param>
/// <param name="outputFilename"></param>
/// <param name="drive"></param>
/// <param name="system"></param>
/// <param name="type"></param>
/// <param name="parameters"></param>
public DumpEnvironment(Options options,
string outputDirectory,
string outputFilename,
Drive drive,
KnownSystem? system,
MediaType? type,
string parameters)
{
// Tool paths
this.SubdumpPath = options.SubDumpPath;
// Output paths
this.OutputDirectory = outputDirectory;
this.OutputFilename = outputFilename;
// UI information
this.Drive = drive;
this.System = system;
this.Type = type;
this.InternalProgram = Converters.ToInternalProgram(options.InternalProgram);
SetParameters(parameters);
SetInternalToolPath(options);
this.ScanForProtection = options.ScanForProtection;
this.AddPlaceholders = options.AddPlaceholders;
this.PromptForDiscInformation = options.PromptForDiscInformation;
// Extra arguments
this.QuietMode = options.QuietMode;
this.ParanoidMode = options.ParanoidMode;
this.RereadAmountC2 = options.RereadAmountForC2;
// Redump login information
this.Username = options.Username;
this.Password = options.Password;
}
#region Public Functionality
@@ -149,23 +195,51 @@ namespace DICUI.Utilities
/// <param name="parameters">String representation of the parameters</param>
public void SetParameters(string parameters)
{
switch (InternalProgram)
switch (this.InternalProgram)
{
case InternalProgram.Aaru:
Parameters = new Aaru.Parameters(parameters);
this.Parameters = new Aaru.Parameters(parameters);
break;
case InternalProgram.DD:
Parameters = new DD.Parameters(parameters);
this.Parameters = new DD.Parameters(parameters);
break;
case InternalProgram.DiscImageCreator:
Parameters = new DiscImageCreator.Parameters(parameters);
this.Parameters = new DiscImageCreator.Parameters(parameters);
break;
// This should never happen, but it needs a fallback.
default:
Parameters = new DiscImageCreator.Parameters(parameters);
this.Parameters = new DiscImageCreator.Parameters(parameters);
break;
}
}
/// <summary>
/// Set the path on the parameters object based on the intermal program
/// </summary>
/// <param name="options"></param>
public void SetInternalToolPath(Options options)
{
switch (this.InternalProgram)
{
case InternalProgram.Aaru:
this.Parameters.Path = options.AaruPath;
break;
case InternalProgram.DD:
this.Parameters.Path = options.DDPath;
break;
case InternalProgram.DiscImageCreator:
this.Parameters.Path = options.CreatorPath;
break;
// This should never happen, but it needs a fallback.
default:
this.InternalProgram = InternalProgram.DiscImageCreator;
this.Parameters.Path = options.CreatorPath;
break;
}
}

View File

@@ -1,211 +0,0 @@
using System;
using System.Configuration;
using System.Linq;
using System.Reflection;
using DICUI.Data;
namespace DICUI
{
public class Options
{
public string AaruPath { get; private set; }
public string CreatorPath { get; private set; }
public string DDPath { get; private set; }
public string DefaultOutputPath { get; private set; }
public string SubDumpPath { get; private set; }
public string InternalProgram { get; 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 AddPlaceholders { get; set; }
public bool PromptForDiscInformation { get; set; }
public bool IgnoreFixedDrives { get; set; }
public bool ResetDriveAfterDump { get; set; }
public bool SkipMediaTypeDetection { get; set; }
public bool SkipSystemDetection { get; set; }
public bool VerboseLogging { get; set; }
public bool OpenLogWindowAtStartup { get; set; }
public string Username { get; set; }
public string Password { 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()
{
Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//TODO: hardcoded, we should find a better way
this.AaruPath = GetStringSetting(configFile, "AaruPath", "Programs\\Aaru\\Aaru.exe");
this.CreatorPath = GetStringSetting(configFile, "CreatorPath", "Programs\\Creator\\DiscImageCreator.exe");
this.DDPath = GetStringSetting(configFile, "DDPath", "Programs\\DD\\dd.exe");
this.SubDumpPath = GetStringSetting(configFile, "SubDumpPath", "Programs\\Subdump\\subdump.exe");
this.DefaultOutputPath = GetStringSetting(configFile, "DefaultOutputPath", "ISO");
this.InternalProgram = GetStringSetting(configFile, "InternalProgram", Data.InternalProgram.DiscImageCreator.ToString());
this.PreferredDumpSpeedCD = GetInt32Setting(configFile, "PreferredDumpSpeedCD", 72);
this.PreferredDumpSpeedDVD = GetInt32Setting(configFile, "PreferredDumpSpeedDVD", 24);
this.PreferredDumpSpeedBD = GetInt32Setting(configFile, "PreferredDumpSpeedBD", 16);
this.QuietMode = GetBooleanSetting(configFile, "QuietMode", false);
this.ParanoidMode = GetBooleanSetting(configFile, "ParanoidMode", false);
this.ScanForProtection = GetBooleanSetting(configFile, "ScanForProtection", true);
this.SkipMediaTypeDetection = GetBooleanSetting(configFile, "SkipMediaTypeDetection", false);
this.SkipSystemDetection = GetBooleanSetting(configFile, "SkipSystemDetection", false);
this.RereadAmountForC2 = GetInt32Setting(configFile, "RereadAmountForC2", 20);
this.VerboseLogging = GetBooleanSetting(configFile, "VerboseLogging", true);
this.OpenLogWindowAtStartup = GetBooleanSetting(configFile, "OpenLogWindowAtStartup", true);
this.AddPlaceholders = GetBooleanSetting(configFile, "AddPlaceholders", true);
this.PromptForDiscInformation = GetBooleanSetting(configFile, "PromptForDiscInformation", true);
this.IgnoreFixedDrives = GetBooleanSetting(configFile, "IgnoreFixedDrives", false);
this.ResetDriveAfterDump = GetBooleanSetting(configFile, "ResetDriveAfterDump", false);
this.Username = GetStringSetting(configFile, "Username", "");
this.Password = GetStringSetting(configFile, "Password", "");
}
/// <summary>
/// Get a boolean setting from a configuration
/// </summary>
/// <param name="configFile">Current configuration file</param>
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
public bool GetBooleanSetting(Configuration configFile, string key, bool defaultValue)
{
var settings = configFile.AppSettings.Settings;
if (settings.AllKeys.Contains(key))
{
if (Boolean.TryParse(settings[key].Value, out bool value))
return value;
else
return defaultValue;
}
else
{
return defaultValue;
}
}
/// <summary>
/// Get a boolean setting from a configuration
/// </summary>
/// <param name="configFile">Current configuration file</param>
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
public int GetInt32Setting(Configuration configFile, string key, int defaultValue)
{
var settings = configFile.AppSettings.Settings;
if (settings.AllKeys.Contains(key))
{
if (Int32.TryParse(settings[key].Value, out int value))
return value;
else
return defaultValue;
}
else
{
return defaultValue;
}
}
/// <summary>
/// Get a boolean setting from a configuration
/// </summary>
/// <param name="configFile">Current configuration file</param>
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
public long GetInt64Setting(Configuration configFile, string key, long defaultValue)
{
var settings = configFile.AppSettings.Settings;
if (settings.AllKeys.Contains(key))
{
if (Int64.TryParse(settings[key].Value, out long value))
return value;
else
return defaultValue;
}
else
{
return defaultValue;
}
}
/// <summary>
/// Get a boolean setting from a configuration
/// </summary>
/// <param name="configFile">Current configuration file</param>
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
public string GetStringSetting(Configuration configFile, string key, string defaultValue)
{
var settings = configFile.AppSettings.Settings;
if (settings.AllKeys.Contains(key))
return settings[key].Value;
else
return defaultValue;
}
//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.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
return PreferredDumpSpeedDVD;
case MediaType.BluRay:
return PreferredDumpSpeedBD;
default:
return 8;
}
}
}
}

98
DICUI/UIOptions.cs Normal file
View File

@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using DICUI.Data;
namespace DICUI
{
public class UIOptions
{
public Options Options { get; set; }
/// <summary>
/// Default constructor
/// </summary>
public UIOptions()
{
Options = new Options();
}
/// <summary>
/// Move these to some utility class in DICUI application
/// </summary>
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(
Options.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()
{
Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = ConvertToDictionary(configFile);
Options.Load(settings);
}
/// <summary>
/// Convert the AppSettings to a dictionary
/// </summary>
/// <param name="configFile"></param>
/// <returns></returns>
private Dictionary<string, string> ConvertToDictionary(Configuration configFile)
{
var settings = configFile.AppSettings.Settings;
var dict = new Dictionary<string, string>();
foreach (string key in settings.AllKeys)
{
dict[key] = settings[key]?.Value ?? string.Empty;
}
return dict;
}
//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)
{
Options.GetType().GetProperty(key, BindingFlags.Public | BindingFlags.Instance).SetValue(this, value);
}
public string Get(string key)
{
return Options.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 this.Options.PreferredDumpSpeedCD;
case MediaType.DVD:
case MediaType.HDDVD:
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
return this.Options.PreferredDumpSpeedDVD;
case MediaType.BluRay:
return this.Options.PreferredDumpSpeedBD;
default:
return this.Options.PreferredDumpSpeedCD;
}
}
}
}

View File

@@ -6,113 +6,113 @@ namespace DICUI
{
public class OptionsViewModel
{
private Options _options;
private UIOptions _uiOptions;
public OptionsViewModel(Options options)
public OptionsViewModel(UIOptions uiOptions)
{
this._options = options;
this._uiOptions = uiOptions;
}
public string InternalProgram
{
get { return _options.InternalProgram; }
set { _options.InternalProgram = value; }
get { return _uiOptions.Options.InternalProgram; }
set { _uiOptions.Options.InternalProgram = value; }
}
public bool QuietMode
{
get { return _options.QuietMode; }
set { _options.QuietMode = value; }
get { return _uiOptions.Options.QuietMode; }
set { _uiOptions.Options.QuietMode = value; }
}
public bool ParanoidMode
{
get { return _options.ParanoidMode; }
set { _options.ParanoidMode = value; }
get { return _uiOptions.Options.ParanoidMode; }
set { _uiOptions.Options.ParanoidMode = value; }
}
public bool ScanForProtection
{
get { return _options.ScanForProtection; }
set { _options.ScanForProtection = value; }
get { return _uiOptions.Options.ScanForProtection; }
set { _uiOptions.Options.ScanForProtection = value; }
}
public string RereadAmountForC2
{
get { return Convert.ToString(_options.RereadAmountForC2); }
get { return Convert.ToString(_uiOptions.Options.RereadAmountForC2); }
set
{
if (Int32.TryParse(value, out int result))
_options.RereadAmountForC2 = result;
_uiOptions.Options.RereadAmountForC2 = result;
}
}
public bool AddPlaceholders
{
get { return _options.AddPlaceholders; }
set { _options.AddPlaceholders = value; }
get { return _uiOptions.Options.AddPlaceholders; }
set { _uiOptions.Options.AddPlaceholders = value; }
}
public bool PromptForDiscInformation
{
get { return _options.PromptForDiscInformation; }
set { _options.PromptForDiscInformation = value; }
get { return _uiOptions.Options.PromptForDiscInformation; }
set { _uiOptions.Options.PromptForDiscInformation = value; }
}
public bool IgnoreFixedDrives
{
get { return _options.IgnoreFixedDrives; }
set { _options.IgnoreFixedDrives = value; }
get { return _uiOptions.Options.IgnoreFixedDrives; }
set { _uiOptions.Options.IgnoreFixedDrives = value; }
}
public bool ResetDriveAfterDump
{
get { return _options.ResetDriveAfterDump; }
set { _options.ResetDriveAfterDump = value; }
get { return _uiOptions.Options.ResetDriveAfterDump; }
set { _uiOptions.Options.ResetDriveAfterDump = value; }
}
public bool SkipMediaTypeDetection
{
get { return _options.SkipMediaTypeDetection; }
set { _options.SkipMediaTypeDetection = value; }
get { return _uiOptions.Options.SkipMediaTypeDetection; }
set { _uiOptions.Options.SkipMediaTypeDetection = value; }
}
public bool SkipSystemDetection
{
get { return _options.SkipSystemDetection; }
set { _options.SkipSystemDetection = value; }
get { return _uiOptions.Options.SkipSystemDetection; }
set { _uiOptions.Options.SkipSystemDetection = value; }
}
public bool VerboseLogging
{
get { return _options.VerboseLogging; }
get { return _uiOptions.Options.VerboseLogging; }
set
{
_options.VerboseLogging = value;
_options.Save();
_uiOptions.Options.VerboseLogging = value;
_uiOptions.Save();
}
}
public bool OpenLogWindowAtStartup
{
get { return _options.OpenLogWindowAtStartup; }
get { return _uiOptions.Options.OpenLogWindowAtStartup; }
set
{
_options.OpenLogWindowAtStartup = value;
_options.Save();
_uiOptions.Options.OpenLogWindowAtStartup = value;
_uiOptions.Save();
}
}
public string Username
{
get { return _options.Username; }
set { _options.Username = value; }
get { return _uiOptions.Options.Username; }
set { _uiOptions.Options.Username = value; }
}
public string Password
{
get { return _options.Password; }
set { _options.Password = value; }
get { return _uiOptions.Options.Password; }
set { _uiOptions.Options.Password = value; }
}
}

View File

@@ -26,7 +26,7 @@ namespace DICUI.Windows
private DumpEnvironment _env;
// Option related
private Options _options;
private UIOptions _uiOptions;
private OptionsWindow _optionsWindow;
// User input related
@@ -39,9 +39,9 @@ namespace DICUI.Windows
InitializeComponent();
// Initializes and load Options object
_options = new Options();
_options.Load();
ViewModels.OptionsViewModel = new OptionsViewModel(_options);
_uiOptions = new UIOptions();
_uiOptions.Load();
ViewModels.OptionsViewModel = new OptionsViewModel(_uiOptions);
_logWindow = new LogWindow(this);
ViewModels.LoggerViewModel.SetWindow(_logWindow);
@@ -51,7 +51,7 @@ namespace DICUI.Windows
DiskScanButton.IsEnabled = false;
CopyProtectScanButton.IsEnabled = false;
if (_options.OpenLogWindowAtStartup)
if (_uiOptions.Options.OpenLogWindowAtStartup)
{
this.WindowStartupLocation = WindowStartupLocation.Manual;
double combinedHeight = this.Height + _logWindow.Height + Constants.LogWindowMarginFromMainWindow;
@@ -73,7 +73,7 @@ namespace DICUI.Windows
_alreadyShown = true;
if (_options.OpenLogWindowAtStartup)
if (_uiOptions.Options.OpenLogWindowAtStartup)
{
//TODO: this should be bound directly to WindowVisible property in two way fashion
// we need to study how to properly do it in XAML
@@ -109,7 +109,7 @@ namespace DICUI.Windows
_env.EjectDisc();
}
if (_options.ResetDriveAfterDump)
if (_uiOptions.Options.ResetDriveAfterDump)
{
ViewModels.LoggerViewModel.VerboseLogLn($"Resetting drive {_env.Drive.Letter}");
_env.ResetDrive();
@@ -242,7 +242,7 @@ namespace DICUI.Windows
// lazy initialization
if (_optionsWindow == null)
{
_optionsWindow = new OptionsWindow(this, _options);
_optionsWindow = new OptionsWindow(this, _uiOptions);
_optionsWindow.Closed += delegate
{
_optionsWindow = null;
@@ -369,7 +369,7 @@ namespace DICUI.Windows
DiskScanButton.IsEnabled = true;
// Populate the list of drives and add it to the combo box
_drives = Validators.CreateListOfDrives(_options.IgnoreFixedDrives);
_drives = Validators.CreateListOfDrives(_uiOptions.Options.IgnoreFixedDrives);
DriveLetterComboBox.ItemsSource = _drives;
if (DriveLetterComboBox.Items.Count > 0)
@@ -391,7 +391,7 @@ namespace DICUI.Windows
CopyProtectScanButton.IsEnabled = true;
// Get the current media type
if (!_options.SkipSystemDetection && index != -1)
if (!_uiOptions.Options.SkipSystemDetection && index != -1)
{
ViewModels.LoggerViewModel.VerboseLog("Trying to detect system for drive {0}.. ", _drives[index].Letter);
var currentSystem = Validators.GetKnownSystem(_drives[index]);
@@ -441,54 +441,13 @@ namespace DICUI.Windows
private DumpEnvironment DetermineEnvironment()
{
// Populate the new environment
var env = new DumpEnvironment()
{
// Paths to tools
SubdumpPath = _options.SubDumpPath,
InternalProgram = Converters.ToInternalProgram(_options.InternalProgram),
OutputDirectory = OutputDirectoryTextBox.Text,
OutputFilename = OutputFilenameTextBox.Text,
// Get the currently selected options
Drive = DriveLetterComboBox.SelectedItem as Drive,
QuietMode = _options.QuietMode,
ParanoidMode = _options.ParanoidMode,
ScanForProtection = _options.ScanForProtection,
RereadAmountC2 = _options.RereadAmountForC2,
AddPlaceholders = _options.AddPlaceholders,
PromptForDiscInformation = _options.PromptForDiscInformation,
Username = _options.Username,
Password = _options.Password,
System = SystemTypeComboBox.SelectedItem as KnownSystemComboBoxItem,
Type = MediaTypeComboBox.SelectedItem as MediaType?,
};
// Set parameters and path accordingly
env.SetParameters(ParametersTextBox.Text);
switch (env.InternalProgram)
{
case InternalProgram.Aaru:
env.Parameters.Path = _options.AaruPath;
break;
case InternalProgram.DD:
env.Parameters.Path = _options.DDPath;
break;
case InternalProgram.DiscImageCreator:
env.Parameters.Path = _options.CreatorPath;
break;
// This should never happen, but it needs a fallback.
default:
env.InternalProgram = InternalProgram.DiscImageCreator;
env.Parameters.Path = _options.CreatorPath;
break;
}
var env = new DumpEnvironment(_uiOptions.Options,
OutputDirectoryTextBox.Text,
OutputFilenameTextBox.Text,
DriveLetterComboBox.SelectedItem as Drive,
SystemTypeComboBox.SelectedItem as KnownSystemComboBoxItem,
MediaTypeComboBox.SelectedItem as MediaType?,
ParametersTextBox.Text);
// Disable automatic reprocessing of the textboxes until we're done
OutputDirectoryTextBox.TextChanged -= OutputDirectoryTextBoxTextChanged;
@@ -585,7 +544,7 @@ namespace DICUI.Windows
// Verify dump output and save it
result = _env.VerifyAndSaveDumpOutput(progress,
EjectWhenDoneCheckBox.IsChecked,
_options.ResetDriveAfterDump,
_uiOptions.Options.ResetDriveAfterDump,
(si) =>
{
// lazy initialization
@@ -668,7 +627,7 @@ namespace DICUI.Windows
// Set the output directory, if we changed drives or it's not already
if (driveChanged || string.IsNullOrEmpty(OutputDirectoryTextBox.Text))
OutputDirectoryTextBox.Text = Path.Combine(_options.DefaultOutputPath, drive?.VolumeLabel ?? string.Empty);
OutputDirectoryTextBox.Text = Path.Combine(_uiOptions.Options.DefaultOutputPath, drive?.VolumeLabel ?? string.Empty);
// Get the extension for the file for the next two statements
string extension = null;
@@ -744,31 +703,10 @@ namespace DICUI.Windows
DriveSpeedComboBox.ItemsSource = values;
ViewModels.LoggerViewModel.VerboseLogLn("Supported media speeds: {0}", string.Join(",", values));
// Find the minimum set to compare against
int preferred = 100;
switch (_currentMediaType)
{
case MediaType.CDROM:
case MediaType.GDROM:
preferred = _options.PreferredDumpSpeedCD;
break;
case MediaType.DVD:
case MediaType.HDDVD:
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
preferred = _options.PreferredDumpSpeedDVD;
break;
case MediaType.BluRay:
preferred = _options.PreferredDumpSpeedBD;
break;
default:
preferred = _options.PreferredDumpSpeedCD;
break;
}
// Set the selected speed
ViewModels.LoggerViewModel.VerboseLogLn("Setting drive speed to: {0}", preferred);
DriveSpeedComboBox.SelectedValue = preferred;
int speed = _uiOptions.GetPreferredDumpSpeedForMediaType(_currentMediaType);
ViewModels.LoggerViewModel.VerboseLogLn("Setting drive speed to: {0}", speed);
DriveSpeedComboBox.SelectedValue = speed;
}
/// <summary>
@@ -782,7 +720,7 @@ namespace DICUI.Windows
return;
// Get the current media type
if (!_options.SkipMediaTypeDetection)
if (!_uiOptions.Options.SkipMediaTypeDetection)
{
ViewModels.LoggerViewModel.VerboseLog("Trying to detect media type for drive {0}.. ", drive.Letter);
_currentMediaType = Validators.GetMediaType(drive);

View File

@@ -14,9 +14,9 @@ namespace DICUI.Windows
public partial class OptionsWindow : Window
{
private readonly MainWindow _mainWindow;
private readonly Options _options;
private readonly UIOptions _options;
public OptionsWindow(MainWindow mainWindow, Options options)
public OptionsWindow(MainWindow mainWindow, UIOptions options)
{
InitializeComponent();
_mainWindow = mainWindow;
@@ -101,12 +101,12 @@ namespace DICUI.Windows
{
Array.ForEach(PathSettings(), setting => TextBoxForPathSetting(setting).Text = _options.Get(setting));
DumpSpeedCDSlider.Value = _options.PreferredDumpSpeedCD;
DumpSpeedDVDSlider.Value = _options.PreferredDumpSpeedDVD;
DumpSpeedBDSlider.Value = _options.PreferredDumpSpeedBD;
DumpSpeedCDSlider.Value = _options.Options.PreferredDumpSpeedCD;
DumpSpeedDVDSlider.Value = _options.Options.PreferredDumpSpeedDVD;
DumpSpeedBDSlider.Value = _options.Options.PreferredDumpSpeedBD;
RedumpUsernameTextBox.Text = _options.Username;
RedumpPasswordBox.Password = _options.Password;
RedumpUsernameTextBox.Text = _options.Options.Username;
RedumpPasswordBox.Password = _options.Options.Password;
}
#region Event Handlers
@@ -115,12 +115,12 @@ namespace DICUI.Windows
{
Array.ForEach(PathSettings(), setting => _options.Set(setting, TextBoxForPathSetting(setting).Text));
_options.PreferredDumpSpeedCD = Convert.ToInt32(DumpSpeedCDSlider.Value);
_options.PreferredDumpSpeedDVD = Convert.ToInt32(DumpSpeedDVDSlider.Value);
_options.PreferredDumpSpeedBD = Convert.ToInt32(DumpSpeedBDSlider.Value);
_options.Options.PreferredDumpSpeedCD = Convert.ToInt32(DumpSpeedCDSlider.Value);
_options.Options.PreferredDumpSpeedDVD = Convert.ToInt32(DumpSpeedDVDSlider.Value);
_options.Options.PreferredDumpSpeedBD = Convert.ToInt32(DumpSpeedBDSlider.Value);
_options.Username = RedumpUsernameTextBox.Text;
_options.Password = RedumpPasswordBox.Password;
_options.Options.Username = RedumpUsernameTextBox.Text;
_options.Options.Password = RedumpPasswordBox.Password;
_options.Save();
Hide();