Files
Aaru/DiscImageChef.Settings/Settings.cs
Natalia Portillo b2ab03407f * LICENSE.MIT:
* LICENSE.LGPL:
	  Added LICENSE files for LGPL and MIT licenses.

	* DiscImageChef.Devices/Enums.cs:
	* DiscImageChef.Partitions/MBR.cs:
	* DiscImageChef.Partitions/RDB.cs:
	* DiscImageChef.DiscImages/GDI.cs:
	* DiscImageChef.Partitions/Sun.cs:
	* DiscImageChef.DiscImages/VHD.cs:
	* DiscImageChef.Partitions/GPT.cs:
	* DiscImageChef.Filesystems/FFS.cs:
	* DiscImageChef.Filesystems/FAT.cs:
	* DiscImageChef.Partitions/NeXT.cs:
	* DiscImageChef.Devices/Command.cs:
	* DiscImageChef.DiscImages/Nero.cs:
	* DiscImageChef.Decoders/CD/PMA.cs:
	* DiscImageChef.Decoders/CD/TOC.cs:
	* DiscImageChef.Filesystems/BFS.cs:
	* DiscImageChef.Filesystems/ODS.cs:
	* DiscImageChef.Helpers/PrintHex.cs:
	* DiscImageChef.Helpers/Swapping.cs:
	* DiscImageChef.Decoders/DVD/PRI.cs:
	* DiscImageChef.Decoders/DVD/DMI.cs:
	* DiscImageChef.Decoders/DVD/DDS.cs:
	* DiscImageChef.Decoders/DVD/RMD.cs:
	* DiscImageChef.Decoders/DVD/UDI.cs:
	* DiscImageChef.Partitions/Atari.cs:
	* DiscImageChef.Decoders/DVD/BCA.cs:
	* DiscImageChef.Filesystems/SysV.cs:
	* DiscImageChef.Filesystems/HPFS.cs:
	* DiscImageChef.Filesystems/NTFS.cs:
	* DiscImageChef.Filesystems/APFS.cs:
	* DiscImageChef.Decoders/DVD/PFI.cs:
	* DiscImageChef.Decoders/CD/ATIP.cs:
	* DiscImageChef.Filesystems/Acorn.cs:
	* DiscImageChef.DiscImages/CDRWin.cs:
	* DiscImageChef.DiscImages/CDRDAO.cs:
	* DiscImageChef.Filesystems/BTRFS.cs:
	* DiscImageChef.Decoders/Xbox/DMI.cs:
	* DiscImageChef.Helpers/ArrayFill.cs:
	* DiscImageChef.Settings/Settings.cs:
	* DiscImageChef.Filesystems/Opera.cs:
	* DiscImageChef.Filesystems/extFS.cs:
	* DiscImageChef.Decoders/DVD/CPRM.cs:
	* DiscImageChef.Decoders/DVD/ADIP.cs:
	* DiscImageChef.Decoders/CD/Enums.cs:
	* DiscImageChef.Decoders/DVD/AACS.cs:
	* DiscImageChef.Decoders/SCSI/EVPD.cs:
	* DiscImageChef.Filesystems/ProDOS.cs:
	* DiscImageChef.Metadata/MediaType.cs:
	* DiscImageChef.Console/DicConsole.cs:
	* DiscImageChef.Decoders/DVD/Spare.cs:
	* DiscImageChef.Filesystems/ext2FS.cs:
	* DiscImageChef.Decoders/DVD/Enums.cs:
	* DiscImageChef.Filesystems/Symbian.cs:
	* DiscImageChef.Decoders/SCSI/Types.cs:
	* DiscImageChef.Filesystems/UNIXBFS.cs:
	* DiscImageChef.DiscImages/TeleDisk.cs:
	* DiscImageChef.Decoders/SCSI/Sense.cs:
	* DiscImageChef.Decoders/CD/FullTOC.cs:
	* DiscImageChef.Decoders/Blu-ray/DI.cs:
	* DiscImageChef.Decoders/ATA/Errors.cs:
	* DiscImageChef.Filesystems/ISO9660.cs:
	* DiscImageChef.Filesystems/MinixFS.cs:
	* DiscImageChef.Devices/Linux/Enums.cs:
	* DiscImageChef.Filesystems/SolarFS.cs:
	* DiscImageChef.Filesystems/Structs.cs:
	* DiscImageChef.DiscImages/Apple2MG.cs:
	* DiscImageChef.Decoders/SCSI/Modes.cs:
	* DiscImageChef.Metadata/Dimensions.cs:
	* DiscImageChef.Partitions/AppleMap.cs:
	* DiscImageChef.Decoders/Floppy/ISO.cs:
	* DiscImageChef.Decoders/DVD/Layers.cs:
	* DiscImageChef.Decoders/CD/Session.cs:
	* DiscImageChef.Decoders/SCSI/Enums.cs:
	* DiscImageChef.Filesystems/Nintendo.cs:
	* DiscImageChef.Helpers/DateHandlers.cs:
	* DiscImageChef.Filesystems/AmigaDOS.cs:
	* DiscImageChef.DiscImages/ImageInfo.cs:
	* DiscImageChef.Checksums/MD5Context.cs:
	* DiscImageChef.Devices/Linux/Extern.cs:
	* DiscImageChef.Filesystems/AppleHFS.cs:
	* DiscImageChef.Filesystems/AppleMFS.cs:
	* DiscImageChef.Helpers/ArrayIsEmpty.cs:
	* DiscImageChef.Decoders/Blu-ray/BCA.cs:
	* DiscImageChef.Decoders/Blu-ray/DDS.cs:
	* DiscImageChef.Filesystems/PCEngine.cs:
	* DiscImageChef.Decoders/ATA/Identify.cs:
	* DiscImageChef.Devices/Linux/Command.cs:
	* DiscImageChef.Devices/FreeBSD/Enums.cs:
	* DiscImageChef.Decoders/SCSI/Inquiry.cs:
	* DiscImageChef.Metadata/DeviceReport.cs:
	* DiscImageChef.Decoders/Floppy/Amiga.cs:
	* DiscImageChef.Devices/Linux/Structs.cs:
	* DiscImageChef.Devices/Windows/Enums.cs:
	* DiscImageChef.Decoders/DVD/CSS&CPRM.cs:
	* DiscImageChef.Checksums/SHA1Context.cs:
	* DiscImageChef.DiscImages/DiskCopy42.cs:
	* DiscImageChef.Partitions/PartPlugin.cs:
	* DiscImageChef.CommonTypes/Partition.cs:
	* DiscImageChef.Decoders/Floppy/Enums.cs:
	* DiscImageChef.CommonTypes/MediaType.cs:
	* DiscImageChef.Decoders/Floppy/Apple2.cs:
	* DiscImageChef.Devices/Windows/Extern.cs:
	* DiscImageChef.Decoders/SCSI/MMC/CPRM.cs:
	* DiscImageChef.Helpers/StringHandlers.cs:
	* DiscImageChef.DiscImages/ImagePlugin.cs:
	* DiscImageChef.Checksums/CRC64Context.cs:
	* DiscImageChef.Checksums/CRC32Context.cs:
	* DiscImageChef.DiscImages/ZZZRawImage.cs:
	* DiscImageChef.Checksums/CRC16Context.cs:
	* DiscImageChef.Filesystems/LisaFS/Dir.cs:
	* DiscImageChef.Decoders/DVD/Cartridge.cs:
	* DiscImageChef.Decoders/Blu-ray/Spare.cs:
	* DiscImageChef.Filesystems/Filesystem.cs:
	* DiscImageChef.Decoders/SCSI/MMC/AACS.cs:
	* DiscImageChef.Devices/FreeBSD/Extern.cs:
	* DiscImageChef.Devices/Device/Commands.cs:
	* DiscImageChef.Checksums/SHA384Context.cs:
	* DiscImageChef.Devices/FreeBSD/Command.cs:
	* DiscImageChef.Checksums/SHA512Context.cs:
	* DiscImageChef.Decoders/SCSI/MMC/Enums.cs:
	* DiscImageChef.Devices/Windows/Command.cs:
	* DiscImageChef.Devices/FreeBSD/Structs.cs:
	* DiscImageChef.Devices/Windows/Structs.cs:
	* DiscImageChef.Filesystems/LisaFS/Info.cs:
	* DiscImageChef.Checksums/SHA256Context.cs:
	* DiscImageChef.Filesystems/LisaFS/File.cs:
	* DiscImageChef.Filesystems/AppleHFSPlus.cs:
	* DiscImageChef.Filesystems/LisaFS/Super.cs:
	* DiscImageChef.Filesystems/LisaFS/Xattr.cs:
	* DiscImageChef.Checksums/Adler32Context.cs:
	* DiscImageChef.Decoders/Floppy/System34.cs:
	* DiscImageChef.Checksums/SpamSumContext.cs:
	* DiscImageChef.Decoders/SCSI/MMC/Hybrid.cs:
	* DiscImageChef.Devices/Device/Variables.cs:
	* DiscImageChef.Filesystems/LisaFS/Consts.cs:
	* DiscImageChef.Filesystems/LisaFS/LisaFS.cs:
	* DiscImageChef.Decoders/Floppy/Commodore.cs:
	* DiscImageChef.Checksums/FletcherContext.cs:
	* DiscImageChef.Filesystems/LisaFS/Extent.cs:
	* DiscImageChef.Devices/Device/Destructor.cs:
	* DiscImageChef.Decoders/Floppy/AppleSony.cs:
	* DiscImageChef.Filesystems/LisaFS/Structs.cs:
	* DiscImageChef.Decoders/SCSI/VendorString.cs:
	* DiscImageChef.Decoders/SCSI/MMC/Features.cs:
	* DiscImageChef.Devices/Device/Constructor.cs:
	* DiscImageChef.Checksums/RIPEMD160Context.cs:
	* DiscImageChef.Decoders/CD/CDTextOnLeadIn.cs:
	* DiscImageChef.Decoders/Blu-ray/Cartridge.cs:
	* DiscImageChef.Decoders/Floppy/System3740.cs:
	* DiscImageChef.Filesystems/LisaFS/Encoding.cs:
	* DiscImageChef.Decoders/SCSI/ModesEncoders.cs:
	* DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs:
	* DiscImageChef.Helpers/BigEndianBitConverter.cs:
	* DiscImageChef.Decoders/Floppy/Perpendicular.cs:
	* DiscImageChef.Decoders/SCSI/SSC/BlockLimits.cs:
	* DiscImageChef.Decoders/SCSI/MMC/WriteProtect.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/HP.cs:
	* DiscImageChef.Devices/Device/AtaCommands/Cfa.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/NEC.cs:
	* DiscImageChef.Helpers/EndianAwareBinaryReader.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/MMC.cs:
	* DiscImageChef.Devices/Device/AtaCommands/MCPT.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/SSC.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/SPC.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/SMC.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/SBC.cs:
	* DiscImageChef.Metadata/Properties/AssemblyInfo.cs:
	* DiscImageChef.Devices/Device/AtaCommands/Atapi.cs:
	* DiscImageChef.Devices/Device/AtaCommands/Ata28.cs:
	* DiscImageChef.Devices/Device/AtaCommands/Smart.cs:
	* DiscImageChef.Decoders/SCSI/SSC/DensitySupport.cs:
	* DiscImageChef.Devices/Device/AtaCommands/Ata48.cs:
	* DiscImageChef.Decoders/SCSI/MMC/DiscInformation.cs:
	* DiscImageChef.Devices/Device/AtaCommands/AtaCHS.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/SyQuest.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/Plasmon.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/Pioneer.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/Adaptec.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/Fujitsu.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/HL-DT-ST.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/Certance.cs:
	* DiscImageChef.Decoders/SCSI/DiscStructureCapabilities.cs:
	* DiscImageChef.Devices/Device/ScsiCommands/ArchiveCorp.cs:
	  Relicensed as LGPL.
	Updated standard header.

	* DiscImageChef/Main.cs:
	* DiscImageChef/Plugins.cs:
	* DiscImageChef/Options.cs:
	* DiscImageChef/Commands/Ls.cs:
	* DiscImageChef/Core/IBGLog.cs:
	* DiscImageChef/Core/MHDDLog.cs:
	* DiscImageChef/AssemblyInfo.cs:
	* DiscImageChef/Core/Checksum.cs:
	* DiscImageChef/Commands/Decode.cs:
	* DiscImageChef/Core/Statistics.cs:
	* DiscImageChef/Commands/Verify.cs:
	* DiscImageChef/Commands/Formats.cs:
	* DiscImageChef/Commands/Entropy.cs:
	* DiscImageChef/Commands/Compare.cs:
	* DiscImageChef.Interop/DetectOS.cs:
	* DiscImageChef/Commands/Analyze.cs:
	* DiscImageChef/Commands/Commands.cs:
	* DiscImageChef/Commands/PrintHex.cs:
	* DiscImageChef/Commands/Checksum.cs:
	* DiscImageChef/DetectImageFormat.cs:
	* DiscImageChef/Commands/DumpMedia.cs:
	* DiscImageChef/Commands/Benchmark.cs:
	* DiscImageChef/Commands/Configure.cs:
	* DiscImageChef/Commands/MediaInfo.cs:
	* DiscImageChef.Interop/PlatformID.cs:
	* DiscImageChef/Commands/MediaScan.cs:
	* DiscImageChef/Commands/Statistics.cs:
	* DiscImageChef/Commands/DeviceInfo.cs:
	* DiscImageChef.Checksums/ReedSolomon.cs:
	* DiscImageChef/Commands/DeviceReport.cs:
	* DiscImageChef/Commands/ExtractFiles.cs:
	* DiscImageChef.Checksums/CDChecksums.cs:
	* DiscImageChef/Commands/CreateSidecar.cs:
	  Updated standard header.

	* DiscImageChef.Checksums/DiscImageChef.Checksums.csproj:
	  Relicensed project as LGPL.
	Updated standard header.
	Embed license as resource.

	* DiscImageChef.Console/DiscImageChef.Console.csproj:
	* DiscImageChef.Devices/DiscImageChef.Devices.csproj:
	* DiscImageChef.Helpers/DiscImageChef.Helpers.csproj:
	* DiscImageChef.Settings/DiscImageChef.Settings.csproj:
	* DiscImageChef.Decoders/DiscImageChef.Decoders.csproj:
	* DiscImageChef.Metadata/DiscImageChef.Metadata.csproj:
	* DiscImageChef.Partitions/DiscImageChef.Partitions.csproj:
	* DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj:
	* DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj:
	* DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj:
	  Relicensed as LGPL.
	Updated standard header.
	Embed license as resource.

	* DiscImageChef/DiscImageChef.csproj:
	* DiscImageChef.Interop/DiscImageChef.Interop.csproj:
	  Updated standard header.
	Embed license as resource.
2016-07-28 18:13:49 +01:00

485 lines
23 KiB
C#

// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Settings.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : DiscImageChef settings.
//
// --[ Description ] ----------------------------------------------------------
//
// Stores and retrieves settings.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using System.Xml.Serialization;
using DiscImageChef.Interop;
using Microsoft.Win32;
using Claunia.PropertyList;
namespace DiscImageChef.Settings
{
public class DicSettings
{
public StatsSettings Stats;
public bool SaveReportsGlobally;
public bool ShareReports;
}
public class UserSettings
{
public string Name;
public string Email;
}
public class StatsSettings
{
public bool ShareStats;
public bool BenchmarkStats;
public bool CommandStats;
public bool DeviceStats;
public bool FilesystemStats;
public bool MediaImageStats;
public bool MediaScanStats;
public bool PartitionStats;
public bool MediaStats;
public bool VerifyStats;
}
public static class Settings
{
public static DicSettings Current;
static string reportsPath;
static string statsPath;
public static string ReportsPath
{
get
{
return reportsPath;
}
}
public static string StatsPath
{
get
{
return statsPath;
}
}
public static void LoadSettings()
{
Current = new DicSettings();
Interop.PlatformID ptID = DetectOS.GetRealPlatformID();
try
{
switch(ptID)
{
case Interop.PlatformID.MacOSX:
case Interop.PlatformID.iOS:
{
string appSupportPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support", "Claunia.com");
if(!Directory.Exists(appSupportPath))
Directory.CreateDirectory(appSupportPath);
string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
if(!Directory.Exists(dicPath))
Directory.CreateDirectory(dicPath);
reportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(reportsPath))
Directory.CreateDirectory(reportsPath);
statsPath = Path.Combine(dicPath, "Statistics");
if(!Directory.Exists(statsPath))
Directory.CreateDirectory(statsPath);
}
break;
case Interop.PlatformID.Win32NT:
case Interop.PlatformID.Win32S:
case Interop.PlatformID.Win32Windows:
case Interop.PlatformID.WinCE:
case Interop.PlatformID.WindowsPhone:
{
string appSupportPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Claunia.com");
if(!Directory.Exists(appSupportPath))
Directory.CreateDirectory(appSupportPath);
string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
if(!Directory.Exists(dicPath))
Directory.CreateDirectory(dicPath);
reportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(reportsPath))
Directory.CreateDirectory(reportsPath);
statsPath = Path.Combine(dicPath, "Statistics");
if(!Directory.Exists(statsPath))
Directory.CreateDirectory(statsPath);
}
break;
default:
{
string appSupportPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".claunia.com");
if(!Directory.Exists(appSupportPath))
Directory.CreateDirectory(appSupportPath);
string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
if(!Directory.Exists(dicPath))
Directory.CreateDirectory(dicPath);
reportsPath = Path.Combine(dicPath, "Reports");
if(!Directory.Exists(reportsPath))
Directory.CreateDirectory(reportsPath);
statsPath = Path.Combine(dicPath, "Statistics");
if(!Directory.Exists(statsPath))
Directory.CreateDirectory(statsPath);
}
break;
}
}
catch
{
reportsPath = null;
}
try
{
switch(ptID)
{
case Interop.PlatformID.MacOSX:
case Interop.PlatformID.iOS:
{
string preferencesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Preferences");
string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.discimagechef.plist");
if(!File.Exists(preferencesFilePath))
{
SetDefaultSettings();
SaveSettings();
}
NSDictionary parsedPreferences = (NSDictionary)BinaryPropertyListParser.Parse(new FileInfo(preferencesFilePath));
if(parsedPreferences != null)
{
NSObject obj;
if(parsedPreferences.TryGetValue("SaveReportsGlobally", out obj))
{
Current.SaveReportsGlobally = ((NSNumber)obj).ToBool();
}
else
Current.SaveReportsGlobally = false;
if(parsedPreferences.TryGetValue("ShareReports", out obj))
{
Current.ShareReports = ((NSNumber)obj).ToBool();
}
else
Current.ShareReports = false;
NSDictionary stats;
if(parsedPreferences.TryGetValue("Stats", out obj))
{
stats = (NSDictionary)obj;
if(stats != null)
{
NSObject obj2;
Current.Stats = new StatsSettings();
if(stats.TryGetValue("ShareStats", out obj2))
{
Current.Stats.ShareStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.ShareStats = false;
if(stats.TryGetValue("BenchmarkStats", out obj2))
{
Current.Stats.BenchmarkStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.BenchmarkStats = false;
if(stats.TryGetValue("CommandStats", out obj2))
{
Current.Stats.CommandStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.CommandStats = false;
if(stats.TryGetValue("DeviceStats", out obj2))
{
Current.Stats.DeviceStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.DeviceStats = false;
if(stats.TryGetValue("FilesystemStats", out obj2))
{
Current.Stats.FilesystemStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.FilesystemStats = false;
if(stats.TryGetValue("MediaImageStats", out obj2))
{
Current.Stats.MediaImageStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.MediaImageStats = false;
if(stats.TryGetValue("MediaScanStats", out obj2))
{
Current.Stats.MediaScanStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.MediaScanStats = false;
if(stats.TryGetValue("PartitionStats", out obj2))
{
Current.Stats.PartitionStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.PartitionStats = false;
if(stats.TryGetValue("MediaStats", out obj2))
{
Current.Stats.MediaStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.MediaStats = false;
if(stats.TryGetValue("VerifyStats", out obj2))
{
Current.Stats.VerifyStats = ((NSNumber)obj2).ToBool();
}
else
Current.Stats.VerifyStats = false;
}
}
else
Current.Stats = null;
}
else
{
SetDefaultSettings();
SaveSettings();
}
}
break;
case Interop.PlatformID.Win32NT:
case Interop.PlatformID.Win32S:
case Interop.PlatformID.Win32Windows:
case Interop.PlatformID.WinCE:
case Interop.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;
}
Current.SaveReportsGlobally = Convert.ToBoolean(key.GetValue("SaveReportsGlobally"));
Current.ShareReports = Convert.ToBoolean(key.GetValue("ShareReports"));
bool stats = Convert.ToBoolean(key.GetValue("Statistics"));
if(stats)
{
Current.Stats = new StatsSettings();
Current.Stats.ShareStats = Convert.ToBoolean(key.GetValue("ShareStats"));
Current.Stats.BenchmarkStats = Convert.ToBoolean(key.GetValue("BenchmarkStats"));
Current.Stats.CommandStats = Convert.ToBoolean(key.GetValue("CommandStats"));
Current.Stats.DeviceStats = Convert.ToBoolean(key.GetValue("DeviceStats"));
Current.Stats.FilesystemStats = Convert.ToBoolean(key.GetValue("FilesystemStats"));
Current.Stats.MediaImageStats = Convert.ToBoolean(key.GetValue("MediaImageStats"));
Current.Stats.MediaScanStats = Convert.ToBoolean(key.GetValue("MediaScanStats"));
Current.Stats.PartitionStats = Convert.ToBoolean(key.GetValue("PartitionStats"));
Current.Stats.MediaStats = Convert.ToBoolean(key.GetValue("MediaStats"));
Current.Stats.VerifyStats = Convert.ToBoolean(key.GetValue("VerifyStats"));
}
}
break;
// TODO: Use the Registry
default:
{
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
string settingsPath = Path.Combine(configPath, "DiscImageChef.xml");
if(!Directory.Exists(configPath))
{
SetDefaultSettings();
SaveSettings();
return;
}
XmlSerializer xs = new XmlSerializer(Current.GetType());
StreamReader sr = new StreamReader(settingsPath);
Current = (DicSettings)xs.Deserialize(sr);
}
break;
}
}
catch
{
SetDefaultSettings();
SaveSettings();
}
}
public static void SaveSettings()
{
try
{
Interop.PlatformID ptID = DetectOS.GetRealPlatformID();
switch(ptID)
{
case Interop.PlatformID.MacOSX:
case Interop.PlatformID.iOS:
{
NSDictionary root = new NSDictionary();
root.Add("SaveReportsGlobally", Current.SaveReportsGlobally);
root.Add("ShareReports", Current.ShareReports);
if(Current.Stats != null)
{
NSDictionary stats = new NSDictionary();
stats.Add("ShareStats", Current.Stats.ShareStats);
stats.Add("BenchmarkStats", Current.Stats.BenchmarkStats);
stats.Add("CommandStats", Current.Stats.CommandStats);
stats.Add("DeviceStats", Current.Stats.DeviceStats);
stats.Add("FilesystemStats", Current.Stats.FilesystemStats);
stats.Add("MediaImageStats", Current.Stats.MediaImageStats);
stats.Add("MediaScanStats", Current.Stats.MediaScanStats);
stats.Add("PartitionStats", Current.Stats.PartitionStats);
stats.Add("MediaStats", Current.Stats.MediaStats);
stats.Add("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);
BinaryPropertyListWriter.Write(fs, root);
fs.Close();
}
break;
case Interop.PlatformID.Win32NT:
case Interop.PlatformID.Win32S:
case Interop.PlatformID.Win32Windows:
case Interop.PlatformID.WinCE:
case Interop.PlatformID.WindowsPhone:
{
RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE").CreateSubKey("Claunia.com");
RegistryKey key = parentKey.CreateSubKey("DiscImageChef");
key.SetValue("SaveReportsGlobally", Current.SaveReportsGlobally);
key.SetValue("ShareReports", Current.ShareReports);
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("FilesystemStats", Current.Stats.FilesystemStats);
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);
}
else
{
key.SetValue("Statistics", true);
key.DeleteValue("ShareStats", false);
key.DeleteValue("BenchmarkStats", 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);
}
}
break;
default:
{
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
string settingsPath = Path.Combine(configPath, "DiscImageChef.xml");
if(!Directory.Exists(configPath))
Directory.CreateDirectory(configPath);
FileStream fs = new FileStream(settingsPath, FileMode.Create);
XmlSerializer xs = new XmlSerializer(Current.GetType());
xs.Serialize(fs, Current);
fs.Close();
}
break;
}
}
catch
{
}
}
public static void SetDefaultSettings()
{
Current = new DicSettings();
Current.SaveReportsGlobally = true;
Current.ShareReports = true;
Current.Stats = new StatsSettings();
Current.Stats.BenchmarkStats = true;
Current.Stats.CommandStats = true;
Current.Stats.DeviceStats = true;
Current.Stats.FilesystemStats = true;
Current.Stats.MediaImageStats = true;
Current.Stats.MediaScanStats = true;
Current.Stats.MediaStats = true;
Current.Stats.PartitionStats = true;
Current.Stats.ShareStats = true;
Current.Stats.VerifyStats = true;
}
}
}