Remove benchmark command.

This commit is contained in:
2020-01-03 18:13:57 +00:00
parent 51b39da0d6
commit 56e24f1ed9
22 changed files with 420 additions and 1307 deletions

View File

@@ -40,99 +40,61 @@ using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
namespace DiscImageChef.Settings
{
/// <summary>
/// Settings
/// </summary>
/// <summary>Settings</summary>
public class DicSettings
{
/// <summary>
/// Level for GDPR compliance checking. Every time a new feature may share user information this level should go up,
/// and the user asked to opt-in.
/// Level for GDPR compliance checking. Every time a new feature may share user information this level should go
/// up, and the user asked to opt-in.
/// </summary>
public const ulong GdprLevel = 1;
/// <summary>
/// Set of GDPR compliance, if lower than <see cref="GdprLevel" />, ask user for compliance.
/// </summary>
/// <summary>Set of GDPR compliance, if lower than <see cref="GdprLevel" />, ask user for compliance.</summary>
public ulong GdprCompliance;
/// <summary>
/// If set to <c>true</c>, reports will be saved locally
/// </summary>
/// <summary>If set to <c>true</c>, reports will be saved locally</summary>
public bool SaveReportsGlobally;
/// <summary>
/// If set to <c>true</c>, reports will be sent to DiscImageChef.Server
/// </summary>
/// <summary>If set to <c>true</c>, reports will be sent to DiscImageChef.Server</summary>
public bool ShareReports;
/// <summary>
/// Statistics
/// </summary>
/// <summary>Statistics</summary>
public StatsSettings Stats;
}
// TODO: Use this
/// <summary>
/// User settings, for media dumps, completely unused
/// </summary>
/// <summary>User settings, for media dumps, completely unused</summary>
public class UserSettings
{
public string Email;
public string Name;
}
/// <summary>
/// Statistics settings
/// </summary>
/// <summary>Statistics settings</summary>
public class StatsSettings
{
/// <summary>
/// If set to <c>true</c>, benchmark statistics will be stored
/// </summary>
public bool BenchmarkStats;
/// <summary>
/// If set to <c>true</c>, command usage statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, benchmark statistics will be stored</summary>
public bool BenchmarkStats = false;
/// <summary>If set to <c>true</c>, command usage statistics will be stored</summary>
public bool CommandStats;
/// <summary>
/// If set to <c>true</c>, device statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, device statistics will be stored</summary>
public bool DeviceStats;
/// <summary>
/// If set to <c>true</c>, filesystem statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, filesystem statistics will be stored</summary>
public bool FilesystemStats;
/// <summary>
/// If set to <c>true</c>, filters statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, filters statistics will be stored</summary>
public bool FilterStats;
/// <summary>
/// If set to <c>true</c>, dump media images statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, dump media images statistics will be stored</summary>
public bool MediaImageStats;
/// <summary>
/// If set to <c>true</c>, media scan statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, media scan statistics will be stored</summary>
public bool MediaScanStats;
/// <summary>
/// If set to <c>true</c>, media types statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, media types statistics will be stored</summary>
public bool MediaStats;
/// <summary>
/// If set to <c>true</c>, partition schemes statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, partition schemes statistics will be stored</summary>
public bool PartitionStats;
/// <summary>
/// If set to <c>true</c>, statistics will be sent to DiscImageChef.Server
/// </summary>
/// <summary>If set to <c>true</c>, statistics will be sent to DiscImageChef.Server</summary>
public bool ShareStats;
/// <summary>
/// If set to <c>true</c>, dump media verification statistics will be stored
/// </summary>
/// <summary>If set to <c>true</c>, dump media verification statistics will be stored</summary>
public bool VerifyStats;
}
/// <summary>
/// Manages statistics
/// </summary>
/// <summary>Manages statistics</summary>
public static class Settings
{
const string XDG_DATA_HOME = "XDG_DATA_HOME";
@@ -140,27 +102,19 @@ namespace DiscImageChef.Settings
const string OLD_DATA_HOME = ".claunia.com";
const string XDG_DATA_HOME_RESOLVED = ".local/share";
const string XDG_CONFIG_HOME_RESOLVED = ".config";
/// <summary>
/// Current statistcs
/// </summary>
/// <summary>Current statistcs</summary>
public static DicSettings Current;
/// <summary>
/// Global path to save reports
/// </summary>
/// <summary>Global path to save reports</summary>
static string ReportsPath { get; set; }
/// <summary>
/// Global path to save statistics
/// </summary>
/// <summary>Global path to save statistics</summary>
public static string StatsPath { get; private set; }
public static string LocalDbPath { get; private set; }
public static string MasterDbPath { get; private set; }
/// <summary>
/// Loads settings
/// </summary>
/// <summary>Loads settings</summary>
public static void LoadSettings()
{
Current = new DicSettings();
@@ -180,21 +134,31 @@ namespace DiscImageChef.Settings
string appSupportPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library",
"Application Support", "Claunia.com");
if(!Directory.Exists(appSupportPath)) Directory.CreateDirectory(appSupportPath);
if(!Directory.Exists(appSupportPath))
Directory.CreateDirectory(appSupportPath);
string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
if(!Directory.Exists(dicPath))
Directory.CreateDirectory(dicPath);
LocalDbPath = Path.Combine(dicPath, LocalDbPath);
MasterDbPath = Path.Combine(dicPath, MasterDbPath);
ReportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath);
if(!Directory.Exists(ReportsPath))
Directory.CreateDirectory(ReportsPath);
StatsPath = Path.Combine(dicPath, "Statistics");
if(!Directory.Exists(StatsPath)) Directory.CreateDirectory(StatsPath);
if(!Directory.Exists(StatsPath))
Directory.CreateDirectory(StatsPath);
}
break;
// In case of Windows statistics and reports will be saved in %APPDATA%\Claunia.com\DiscImageChef
case PlatformID.Win32NT:
case PlatformID.Win32S:
@@ -205,21 +169,31 @@ namespace DiscImageChef.Settings
string appSupportPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Claunia.com");
if(!Directory.Exists(appSupportPath)) Directory.CreateDirectory(appSupportPath);
if(!Directory.Exists(appSupportPath))
Directory.CreateDirectory(appSupportPath);
string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
if(!Directory.Exists(dicPath))
Directory.CreateDirectory(dicPath);
LocalDbPath = Path.Combine(dicPath, LocalDbPath);
MasterDbPath = Path.Combine(dicPath, MasterDbPath);
ReportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath);
if(!Directory.Exists(ReportsPath))
Directory.CreateDirectory(ReportsPath);
StatsPath = Path.Combine(dicPath, "Statistics");
if(!Directory.Exists(StatsPath)) Directory.CreateDirectory(StatsPath);
if(!Directory.Exists(StatsPath))
Directory.CreateDirectory(StatsPath);
}
break;
// Otherwise, statistics and reports will be saved in ~/.claunia.com/DiscImageChef
default:
{
@@ -227,30 +201,40 @@ namespace DiscImageChef.Settings
Path.Combine(homePath,
Environment.GetEnvironmentVariable(XDG_DATA_HOME) ?? XDG_DATA_HOME_RESOLVED);
string oldDicPath = Path.Combine(homePath, ".claunia.com", "DiscImageChef");
string oldDicPath = Path.Combine(homePath, ".claunia.com", "DiscImageChef");
string dicPath = Path.Combine(xdgDataPath, "DiscImageChef");
if(Directory.Exists(oldDicPath) && !Directory.Exists(dicPath))
if(Directory.Exists(oldDicPath) &&
!Directory.Exists(dicPath))
{
Directory.Move(oldDicPath, dicPath);
Directory.Delete(Path.Combine(homePath, ".claunia.com"));
}
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
if(!Directory.Exists(dicPath))
Directory.CreateDirectory(dicPath);
LocalDbPath = Path.Combine(dicPath, LocalDbPath);
MasterDbPath = Path.Combine(dicPath, MasterDbPath);
ReportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(ReportsPath)) Directory.CreateDirectory(ReportsPath);
if(!Directory.Exists(ReportsPath))
Directory.CreateDirectory(ReportsPath);
StatsPath = Path.Combine(dicPath, "Statistics");
if(!Directory.Exists(StatsPath)) Directory.CreateDirectory(StatsPath);
if(!Directory.Exists(StatsPath))
Directory.CreateDirectory(StatsPath);
}
break;
}
}
catch { ReportsPath = null; }
catch
{
ReportsPath = null;
}
FileStream prefsFs = null;
StreamReader prefsSr = null;
@@ -266,6 +250,7 @@ namespace DiscImageChef.Settings
string preferencesPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library",
"Preferences");
string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.discimagechef.plist");
if(!File.Exists(preferencesFilePath))
@@ -276,7 +261,8 @@ namespace DiscImageChef.Settings
prefsFs = new FileStream(preferencesFilePath, FileMode.Open, FileAccess.Read);
NSDictionary parsedPreferences = (NSDictionary)BinaryPropertyListParser.Parse(prefsFs);
var parsedPreferences = (NSDictionary)BinaryPropertyListParser.Parse(prefsFs);
if(parsedPreferences != null)
{
Current.SaveReportsGlobally =
@@ -288,47 +274,38 @@ namespace DiscImageChef.Settings
if(parsedPreferences.TryGetValue("Stats", out obj))
{
NSDictionary stats = (NSDictionary)obj;
var stats = (NSDictionary)obj;
if(stats != null)
Current.Stats = new StatsSettings
{
ShareStats =
stats.TryGetValue("ShareStats", out NSObject obj2) &&
((NSNumber)obj2).ToBool(),
BenchmarkStats =
stats.TryGetValue("BenchmarkStats", out obj2) &&
((NSNumber)obj2).ToBool(),
CommandStats =
stats.TryGetValue("CommandStats", out obj2) &&
((NSNumber)obj2).ToBool(),
DeviceStats =
stats.TryGetValue("DeviceStats", out obj2) && ((NSNumber)obj2).ToBool(),
ShareStats = stats.TryGetValue("ShareStats", out NSObject obj2) &&
((NSNumber)obj2).ToBool(),
CommandStats = stats.TryGetValue("CommandStats", out obj2) &&
((NSNumber)obj2).ToBool(),
DeviceStats = stats.TryGetValue("DeviceStats", out obj2) &&
((NSNumber)obj2).ToBool(),
FilesystemStats =
stats.TryGetValue("FilesystemStats", out obj2) &&
((NSNumber)obj2).ToBool(),
FilterStats =
stats.TryGetValue("FilterStats", out obj2) && ((NSNumber)obj2).ToBool(),
stats.TryGetValue("FilesystemStats", out obj2) && ((NSNumber)obj2).ToBool(),
FilterStats = stats.TryGetValue("FilterStats", out obj2) &&
((NSNumber)obj2).ToBool(),
MediaImageStats =
stats.TryGetValue("MediaImageStats", out obj2) &&
((NSNumber)obj2).ToBool(),
stats.TryGetValue("MediaImageStats", out obj2) && ((NSNumber)obj2).ToBool(),
MediaScanStats =
stats.TryGetValue("MediaScanStats", out obj2) &&
((NSNumber)obj2).ToBool(),
stats.TryGetValue("MediaScanStats", out obj2) && ((NSNumber)obj2).ToBool(),
PartitionStats =
stats.TryGetValue("PartitionStats", out obj2) &&
((NSNumber)obj2).ToBool(),
MediaStats =
stats.TryGetValue("MediaStats", out obj2) && ((NSNumber)obj2).ToBool(),
VerifyStats =
stats.TryGetValue("VerifyStats", out obj2) && ((NSNumber)obj2).ToBool()
stats.TryGetValue("PartitionStats", out obj2) && ((NSNumber)obj2).ToBool(),
MediaStats = stats.TryGetValue("MediaStats", out obj2) &&
((NSNumber)obj2).ToBool(),
VerifyStats = stats.TryGetValue("VerifyStats", out obj2) &&
((NSNumber)obj2).ToBool()
};
}
else Current.Stats = null;
else
Current.Stats = null;
Current.GdprCompliance = parsedPreferences.TryGetValue("GdprCompliance", out obj)
? (ulong)((NSNumber)obj).ToLong()
: 0;
? (ulong)((NSNumber)obj).ToLong() : 0;
prefsFs.Close();
}
@@ -340,8 +317,10 @@ namespace DiscImageChef.Settings
SaveSettings();
}
}
break;
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0
// In case of Windows settings will be saved in the registry: HKLM/SOFTWARE/Claunia.com/DiscImageChef
case PlatformID.Win32NT:
case PlatformID.Win32S:
@@ -350,18 +329,22 @@ namespace DiscImageChef.Settings
case PlatformID.WindowsPhone:
{
RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE")?.OpenSubKey("Claunia.com");
if(parentKey == null)
{
SetDefaultSettings();
SaveSettings();
return;
}
RegistryKey key = parentKey.OpenSubKey("DiscImageChef");
if(key == null)
{
SetDefaultSettings();
SaveSettings();
return;
}
@@ -370,11 +353,11 @@ namespace DiscImageChef.Settings
Current.GdprCompliance = Convert.ToUInt64(key.GetValue("GdprCompliance"));
bool stats = Convert.ToBoolean(key.GetValue("Statistics"));
if(stats)
Current.Stats = new StatsSettings
{
ShareStats = Convert.ToBoolean(key.GetValue("ShareStats")),
BenchmarkStats = Convert.ToBoolean(key.GetValue("BenchmarkStats")),
CommandStats = Convert.ToBoolean(key.GetValue("CommandStats")),
DeviceStats = Convert.ToBoolean(key.GetValue("DeviceStats")),
FilesystemStats = Convert.ToBoolean(key.GetValue("FilesystemStats")),
@@ -388,23 +371,29 @@ namespace DiscImageChef.Settings
}
break;
#endif
#endif
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
default:
{
string oldConfigPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
string oldSettingsPath = Path.Combine(oldConfigPath, "DiscImageChef.xml");
string xdgConfigPath =
Path.Combine(homePath,
Environment.GetEnvironmentVariable(XDG_CONFIG_HOME) ??
XDG_CONFIG_HOME_RESOLVED);
string settingsPath = Path.Combine(xdgConfigPath, "DiscImageChef.xml");
if(File.Exists(oldSettingsPath) && !File.Exists(settingsPath))
if(File.Exists(oldSettingsPath) &&
!File.Exists(settingsPath))
{
if(!Directory.Exists(xdgConfigPath)) Directory.CreateDirectory(xdgConfigPath);
if(!Directory.Exists(xdgConfigPath))
Directory.CreateDirectory(xdgConfigPath);
File.Move(oldSettingsPath, settingsPath);
}
@@ -412,10 +401,11 @@ namespace DiscImageChef.Settings
{
SetDefaultSettings();
SaveSettings();
return;
}
XmlSerializer xs = new XmlSerializer(Current.GetType());
var xs = new XmlSerializer(Current.GetType());
prefsSr = new StreamReader(settingsPath);
Current = (DicSettings)xs.Deserialize(prefsSr);
}
@@ -444,42 +434,72 @@ namespace DiscImageChef.Settings
case PlatformID.MacOSX:
case PlatformID.iOS:
{
NSDictionary root = new NSDictionary
var root = new NSDictionary
{
{"SaveReportsGlobally", Current.SaveReportsGlobally},
{"ShareReports", Current.ShareReports},
{"GdprCompliance", Current.GdprCompliance}
{
"SaveReportsGlobally", Current.SaveReportsGlobally
},
{
"ShareReports", Current.ShareReports
},
{
"GdprCompliance", Current.GdprCompliance
}
};
if(Current.Stats != null)
{
NSDictionary stats = new NSDictionary
var stats = new NSDictionary
{
{"ShareStats", Current.Stats.ShareStats},
{"BenchmarkStats", Current.Stats.BenchmarkStats},
{"CommandStats", Current.Stats.CommandStats},
{"DeviceStats", Current.Stats.DeviceStats},
{"FilesystemStats", Current.Stats.FilesystemStats},
{"FilterStats", Current.Stats.FilterStats},
{"MediaImageStats", Current.Stats.MediaImageStats},
{"MediaScanStats", Current.Stats.MediaScanStats},
{"PartitionStats", Current.Stats.PartitionStats},
{"MediaStats", Current.Stats.MediaStats},
{"VerifyStats", Current.Stats.VerifyStats}
{
"ShareStats", Current.Stats.ShareStats
},
{
"CommandStats", Current.Stats.CommandStats
},
{
"DeviceStats", Current.Stats.DeviceStats
},
{
"FilesystemStats", Current.Stats.FilesystemStats
},
{
"FilterStats", Current.Stats.FilterStats
},
{
"MediaImageStats", Current.Stats.MediaImageStats
},
{
"MediaScanStats", Current.Stats.MediaScanStats
},
{
"PartitionStats", Current.Stats.PartitionStats
},
{
"MediaStats", Current.Stats.MediaStats
},
{
"VerifyStats", Current.Stats.VerifyStats
}
};
root.Add("Stats", stats);
}
string preferencesPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library",
"Preferences");
string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.discimagechef.plist");
FileStream fs = new FileStream(preferencesFilePath, FileMode.Create);
var fs = new FileStream(preferencesFilePath, FileMode.Create);
BinaryPropertyListWriter.Write(fs, root);
fs.Close();
}
break;
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0
// In case of Windows settings will be saved in the registry: HKLM/SOFTWARE/Claunia.com/DiscImageChef
case PlatformID.Win32NT:
case PlatformID.Win32S:
@@ -489,64 +509,69 @@ namespace DiscImageChef.Settings
{
RegistryKey parentKey =
Registry.CurrentUser.OpenSubKey("SOFTWARE", true)?.CreateSubKey("Claunia.com");
RegistryKey key = parentKey?.CreateSubKey("DiscImageChef");
if(key != null)
{
key.SetValue("SaveReportsGlobally", Current.SaveReportsGlobally);
key.SetValue("ShareReports", Current.ShareReports);
key.SetValue("GdprCompliance", Current.GdprCompliance);
key.SetValue("ShareReports", Current.ShareReports);
key.SetValue("GdprCompliance", Current.GdprCompliance);
if(Current.Stats != null)
{
key.SetValue("Statistics", true);
key.SetValue("ShareStats", Current.Stats.ShareStats);
key.SetValue("BenchmarkStats", Current.Stats.BenchmarkStats);
key.SetValue("CommandStats", Current.Stats.CommandStats);
key.SetValue("DeviceStats", Current.Stats.DeviceStats);
key.SetValue("Statistics", true);
key.SetValue("ShareStats", Current.Stats.ShareStats);
key.SetValue("CommandStats", Current.Stats.CommandStats);
key.SetValue("DeviceStats", Current.Stats.DeviceStats);
key.SetValue("FilesystemStats", Current.Stats.FilesystemStats);
key.SetValue("FilterStats", Current.Stats.FilterStats);
key.SetValue("FilterStats", Current.Stats.FilterStats);
key.SetValue("MediaImageStats", Current.Stats.MediaImageStats);
key.SetValue("MediaScanStats", Current.Stats.MediaScanStats);
key.SetValue("PartitionStats", Current.Stats.PartitionStats);
key.SetValue("MediaStats", Current.Stats.MediaStats);
key.SetValue("VerifyStats", Current.Stats.VerifyStats);
key.SetValue("MediaScanStats", Current.Stats.MediaScanStats);
key.SetValue("PartitionStats", Current.Stats.PartitionStats);
key.SetValue("MediaStats", Current.Stats.MediaStats);
key.SetValue("VerifyStats", Current.Stats.VerifyStats);
}
else
{
key.SetValue("Statistics", true);
key.DeleteValue("ShareStats", false);
key.DeleteValue("BenchmarkStats", false);
key.DeleteValue("CommandStats", false);
key.DeleteValue("DeviceStats", false);
key.DeleteValue("ShareStats", false);
key.DeleteValue("CommandStats", false);
key.DeleteValue("DeviceStats", false);
key.DeleteValue("FilesystemStats", false);
key.DeleteValue("MediaImageStats", false);
key.DeleteValue("MediaScanStats", false);
key.DeleteValue("PartitionStats", false);
key.DeleteValue("MediaStats", false);
key.DeleteValue("VerifyStats", false);
key.DeleteValue("MediaScanStats", false);
key.DeleteValue("PartitionStats", false);
key.DeleteValue("MediaStats", false);
key.DeleteValue("VerifyStats", false);
}
}
}
break;
#endif
#endif
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
default:
{
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string xdgConfigPath =
Path.Combine(homePath,
Environment.GetEnvironmentVariable(XDG_CONFIG_HOME) ??
XDG_CONFIG_HOME_RESOLVED);
string settingsPath = Path.Combine(xdgConfigPath, "DiscImageChef.xml");
if(!Directory.Exists(xdgConfigPath)) Directory.CreateDirectory(xdgConfigPath);
if(!Directory.Exists(xdgConfigPath))
Directory.CreateDirectory(xdgConfigPath);
FileStream fs = new FileStream(settingsPath, FileMode.Create);
XmlSerializer xs = new XmlSerializer(Current.GetType());
var fs = new FileStream(settingsPath, FileMode.Create);
var xs = new XmlSerializer(Current.GetType());
xs.Serialize(fs, Current);
fs.Close();
}
break;
}
}
@@ -558,31 +583,15 @@ namespace DiscImageChef.Settings
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
}
/// <summary>
/// Sets default settings as all statistics, share everything
/// </summary>
static void SetDefaultSettings()
/// <summary>Sets default settings as all statistics, share everything</summary>
static void SetDefaultSettings() => Current = new DicSettings
{
Current = new DicSettings
SaveReportsGlobally = true, ShareReports = true, GdprCompliance = 0, Stats = new StatsSettings
{
SaveReportsGlobally = true,
ShareReports = true,
GdprCompliance = 0,
Stats = new StatsSettings
{
BenchmarkStats = true,
CommandStats = true,
DeviceStats = true,
FilesystemStats = true,
MediaImageStats = true,
MediaScanStats = true,
FilterStats = true,
MediaStats = true,
PartitionStats = true,
ShareStats = true,
VerifyStats = true
}
};
}
CommandStats = true, DeviceStats = true, FilesystemStats = true, MediaImageStats = true,
MediaScanStats = true, FilterStats = true, MediaStats = true, PartitionStats = true,
ShareStats = true, VerifyStats = true
}
};
}
}