mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Support newest XDG Base Directory Specification for Linux, fixes #164.
This commit is contained in:
@@ -46,9 +46,14 @@ namespace DiscImageChef.Settings
|
|||||||
public class DicSettings
|
public class DicSettings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public const ulong GdprLevel = 1;
|
public const ulong GdprLevel = 1;
|
||||||
|
/// <summary>
|
||||||
|
/// Set of GDPR compliance, if lower than <see cref="GdprLevel" />, ask user for compliance.
|
||||||
|
/// </summary>
|
||||||
|
public ulong GdprCompliance;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If set to <c>true</c>, reports will be saved locally
|
/// If set to <c>true</c>, reports will be saved locally
|
||||||
@@ -62,10 +67,6 @@ namespace DiscImageChef.Settings
|
|||||||
/// Statistics
|
/// Statistics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StatsSettings Stats;
|
public StatsSettings Stats;
|
||||||
/// <summary>
|
|
||||||
/// Set of GDPR compliance, if lower than <see cref="GdprLevel"/>, ask user for compliance.
|
|
||||||
/// </summary>
|
|
||||||
public ulong GdprCompliance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use this
|
// TODO: Use this
|
||||||
@@ -134,6 +135,11 @@ namespace DiscImageChef.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Settings
|
public static class Settings
|
||||||
{
|
{
|
||||||
|
const string XDG_DATA_HOME = "XDG_DATA_HOME";
|
||||||
|
const string XDG_CONFIG_HOME = "XDG_CONFIG_HOME";
|
||||||
|
const string OLD_DATA_HOME = ".claunia.com";
|
||||||
|
const string XDG_DATA_HOME_RESOLVED = ".local/share";
|
||||||
|
const string XDG_CONFIG_HOME_RESOLVED = ".config";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current statistcs
|
/// Current statistcs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -155,7 +161,8 @@ namespace DiscImageChef.Settings
|
|||||||
public static void LoadSettings()
|
public static void LoadSettings()
|
||||||
{
|
{
|
||||||
Current = new DicSettings();
|
Current = new DicSettings();
|
||||||
PlatformID ptId = DetectOS.GetRealPlatformID();
|
PlatformID ptId = DetectOS.GetRealPlatformID();
|
||||||
|
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -205,12 +212,19 @@ namespace DiscImageChef.Settings
|
|||||||
// Otherwise, statistics and reports will be saved in ~/.claunia.com/DiscImageChef
|
// Otherwise, statistics and reports will be saved in ~/.claunia.com/DiscImageChef
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
string appSupportPath =
|
string xdgDataPath =
|
||||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
Path.Combine(homePath,
|
||||||
".claunia.com");
|
Environment.GetEnvironmentVariable(XDG_DATA_HOME) ?? XDG_DATA_HOME_RESOLVED);
|
||||||
if(!Directory.Exists(appSupportPath)) Directory.CreateDirectory(appSupportPath);
|
|
||||||
|
string oldDicPath = Path.Combine(homePath, ".claunia.com", "DiscImageChef");
|
||||||
|
string dicPath = Path.Combine(xdgDataPath, "DiscImageChef");
|
||||||
|
|
||||||
|
if(Directory.Exists(oldDicPath) && !Directory.Exists(dicPath))
|
||||||
|
{
|
||||||
|
Directory.Move(oldDicPath, dicPath);
|
||||||
|
Directory.Delete(Path.Combine(homePath, ".claunia.com"));
|
||||||
|
}
|
||||||
|
|
||||||
string dicPath = Path.Combine(appSupportPath, "DiscImageChef");
|
|
||||||
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
|
if(!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
|
||||||
|
|
||||||
ReportsPath = Path.Combine(dicPath, "Reports");
|
ReportsPath = Path.Combine(dicPath, "Reports");
|
||||||
@@ -224,7 +238,7 @@ namespace DiscImageChef.Settings
|
|||||||
}
|
}
|
||||||
catch { ReportsPath = null; }
|
catch { ReportsPath = null; }
|
||||||
|
|
||||||
FileStream prefsFs = null;
|
FileStream prefsFs = null;
|
||||||
StreamReader prefsSr = null;
|
StreamReader prefsSr = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -292,7 +306,9 @@ namespace DiscImageChef.Settings
|
|||||||
}
|
}
|
||||||
else Current.Stats = null;
|
else Current.Stats = null;
|
||||||
|
|
||||||
Current.GdprCompliance = parsedPreferences.TryGetValue("GdprCompliance", out obj) ? (ulong)((NSNumber)obj).ToLong() : 0;
|
Current.GdprCompliance = parsedPreferences.TryGetValue("GdprCompliance", out obj)
|
||||||
|
? (ulong)((NSNumber)obj).ToLong()
|
||||||
|
: 0;
|
||||||
|
|
||||||
prefsFs.Close();
|
prefsFs.Close();
|
||||||
}
|
}
|
||||||
@@ -329,24 +345,24 @@ namespace DiscImageChef.Settings
|
|||||||
}
|
}
|
||||||
|
|
||||||
Current.SaveReportsGlobally = Convert.ToBoolean(key.GetValue("SaveReportsGlobally"));
|
Current.SaveReportsGlobally = Convert.ToBoolean(key.GetValue("SaveReportsGlobally"));
|
||||||
Current.ShareReports = Convert.ToBoolean(key.GetValue("ShareReports"));
|
Current.ShareReports = Convert.ToBoolean(key.GetValue("ShareReports"));
|
||||||
Current.GdprCompliance = Convert.ToUInt64(key.GetValue("GdprCompliance"));
|
Current.GdprCompliance = Convert.ToUInt64(key.GetValue("GdprCompliance"));
|
||||||
|
|
||||||
bool stats = Convert.ToBoolean(key.GetValue("Statistics"));
|
bool stats = Convert.ToBoolean(key.GetValue("Statistics"));
|
||||||
if(stats)
|
if(stats)
|
||||||
Current.Stats = new StatsSettings
|
Current.Stats = new StatsSettings
|
||||||
{
|
{
|
||||||
ShareStats = Convert.ToBoolean(key.GetValue("ShareStats")),
|
ShareStats = Convert.ToBoolean(key.GetValue("ShareStats")),
|
||||||
BenchmarkStats = Convert.ToBoolean(key.GetValue("BenchmarkStats")),
|
BenchmarkStats = Convert.ToBoolean(key.GetValue("BenchmarkStats")),
|
||||||
CommandStats = Convert.ToBoolean(key.GetValue("CommandStats")),
|
CommandStats = Convert.ToBoolean(key.GetValue("CommandStats")),
|
||||||
DeviceStats = Convert.ToBoolean(key.GetValue("DeviceStats")),
|
DeviceStats = Convert.ToBoolean(key.GetValue("DeviceStats")),
|
||||||
FilesystemStats = Convert.ToBoolean(key.GetValue("FilesystemStats")),
|
FilesystemStats = Convert.ToBoolean(key.GetValue("FilesystemStats")),
|
||||||
FilterStats = Convert.ToBoolean(key.GetValue("FilterStats")),
|
FilterStats = Convert.ToBoolean(key.GetValue("FilterStats")),
|
||||||
MediaImageStats = Convert.ToBoolean(key.GetValue("MediaImageStats")),
|
MediaImageStats = Convert.ToBoolean(key.GetValue("MediaImageStats")),
|
||||||
MediaScanStats = Convert.ToBoolean(key.GetValue("MediaScanStats")),
|
MediaScanStats = Convert.ToBoolean(key.GetValue("MediaScanStats")),
|
||||||
PartitionStats = Convert.ToBoolean(key.GetValue("PartitionStats")),
|
PartitionStats = Convert.ToBoolean(key.GetValue("PartitionStats")),
|
||||||
MediaStats = Convert.ToBoolean(key.GetValue("MediaStats")),
|
MediaStats = Convert.ToBoolean(key.GetValue("MediaStats")),
|
||||||
VerifyStats = Convert.ToBoolean(key.GetValue("VerifyStats"))
|
VerifyStats = Convert.ToBoolean(key.GetValue("VerifyStats"))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,11 +370,23 @@ namespace DiscImageChef.Settings
|
|||||||
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
|
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
string configPath =
|
string oldConfigPath =
|
||||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
|
||||||
string settingsPath = Path.Combine(configPath, "DiscImageChef.xml");
|
string oldSettingsPath = Path.Combine(oldConfigPath, "DiscImageChef.xml");
|
||||||
|
|
||||||
if(!Directory.Exists(configPath))
|
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(!Directory.Exists(xdgConfigPath)) Directory.CreateDirectory(xdgConfigPath);
|
||||||
|
File.Move(oldSettingsPath, settingsPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!File.Exists(settingsPath))
|
||||||
{
|
{
|
||||||
SetDefaultSettings();
|
SetDefaultSettings();
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
@@ -443,37 +471,37 @@ namespace DiscImageChef.Settings
|
|||||||
if(key != null)
|
if(key != null)
|
||||||
{
|
{
|
||||||
key.SetValue("SaveReportsGlobally", Current.SaveReportsGlobally);
|
key.SetValue("SaveReportsGlobally", Current.SaveReportsGlobally);
|
||||||
key.SetValue("ShareReports", Current.ShareReports);
|
key.SetValue("ShareReports", Current.ShareReports);
|
||||||
key.SetValue("GdprCompliance", Current.GdprCompliance);
|
key.SetValue("GdprCompliance", Current.GdprCompliance);
|
||||||
|
|
||||||
if(Current.Stats != null)
|
if(Current.Stats != null)
|
||||||
{
|
{
|
||||||
key.SetValue("Statistics", true);
|
key.SetValue("Statistics", true);
|
||||||
key.SetValue("ShareStats", Current.Stats.ShareStats);
|
key.SetValue("ShareStats", Current.Stats.ShareStats);
|
||||||
key.SetValue("BenchmarkStats", Current.Stats.BenchmarkStats);
|
key.SetValue("BenchmarkStats", Current.Stats.BenchmarkStats);
|
||||||
key.SetValue("CommandStats", Current.Stats.CommandStats);
|
key.SetValue("CommandStats", Current.Stats.CommandStats);
|
||||||
key.SetValue("DeviceStats", Current.Stats.DeviceStats);
|
key.SetValue("DeviceStats", Current.Stats.DeviceStats);
|
||||||
key.SetValue("FilesystemStats", Current.Stats.FilesystemStats);
|
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("MediaImageStats", Current.Stats.MediaImageStats);
|
||||||
key.SetValue("MediaScanStats", Current.Stats.MediaScanStats);
|
key.SetValue("MediaScanStats", Current.Stats.MediaScanStats);
|
||||||
key.SetValue("PartitionStats", Current.Stats.PartitionStats);
|
key.SetValue("PartitionStats", Current.Stats.PartitionStats);
|
||||||
key.SetValue("MediaStats", Current.Stats.MediaStats);
|
key.SetValue("MediaStats", Current.Stats.MediaStats);
|
||||||
key.SetValue("VerifyStats", Current.Stats.VerifyStats);
|
key.SetValue("VerifyStats", Current.Stats.VerifyStats);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key.SetValue("Statistics", true);
|
key.SetValue("Statistics", true);
|
||||||
key.DeleteValue("ShareStats", false);
|
key.DeleteValue("ShareStats", false);
|
||||||
key.DeleteValue("BenchmarkStats", false);
|
key.DeleteValue("BenchmarkStats", false);
|
||||||
key.DeleteValue("CommandStats", false);
|
key.DeleteValue("CommandStats", false);
|
||||||
key.DeleteValue("DeviceStats", false);
|
key.DeleteValue("DeviceStats", false);
|
||||||
key.DeleteValue("FilesystemStats", false);
|
key.DeleteValue("FilesystemStats", false);
|
||||||
key.DeleteValue("MediaImageStats", false);
|
key.DeleteValue("MediaImageStats", false);
|
||||||
key.DeleteValue("MediaScanStats", false);
|
key.DeleteValue("MediaScanStats", false);
|
||||||
key.DeleteValue("PartitionStats", false);
|
key.DeleteValue("PartitionStats", false);
|
||||||
key.DeleteValue("MediaStats", false);
|
key.DeleteValue("MediaStats", false);
|
||||||
key.DeleteValue("VerifyStats", false);
|
key.DeleteValue("VerifyStats", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -481,13 +509,16 @@ namespace DiscImageChef.Settings
|
|||||||
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
|
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
string configPath =
|
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
|
string xdgConfigPath =
|
||||||
string settingsPath = Path.Combine(configPath, "DiscImageChef.xml");
|
Path.Combine(homePath,
|
||||||
|
Environment.GetEnvironmentVariable(XDG_CONFIG_HOME) ??
|
||||||
|
XDG_CONFIG_HOME_RESOLVED);
|
||||||
|
string settingsPath = Path.Combine(xdgConfigPath, "DiscImageChef.xml");
|
||||||
|
|
||||||
if(!Directory.Exists(configPath)) Directory.CreateDirectory(configPath);
|
if(!Directory.Exists(xdgConfigPath)) Directory.CreateDirectory(xdgConfigPath);
|
||||||
|
|
||||||
FileStream fs = new FileStream(settingsPath, FileMode.Create);
|
FileStream fs = new FileStream(settingsPath, FileMode.Create);
|
||||||
XmlSerializer xs = new XmlSerializer(Current.GetType());
|
XmlSerializer xs = new XmlSerializer(Current.GetType());
|
||||||
xs.Serialize(fs, Current);
|
xs.Serialize(fs, Current);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
@@ -495,12 +526,12 @@ namespace DiscImageChef.Settings
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -511,21 +542,21 @@ namespace DiscImageChef.Settings
|
|||||||
Current = new DicSettings
|
Current = new DicSettings
|
||||||
{
|
{
|
||||||
SaveReportsGlobally = true,
|
SaveReportsGlobally = true,
|
||||||
ShareReports = true,
|
ShareReports = true,
|
||||||
GdprCompliance = 0,
|
GdprCompliance = 0,
|
||||||
Stats = new StatsSettings
|
Stats = new StatsSettings
|
||||||
{
|
{
|
||||||
BenchmarkStats = true,
|
BenchmarkStats = true,
|
||||||
CommandStats = true,
|
CommandStats = true,
|
||||||
DeviceStats = true,
|
DeviceStats = true,
|
||||||
FilesystemStats = true,
|
FilesystemStats = true,
|
||||||
MediaImageStats = true,
|
MediaImageStats = true,
|
||||||
MediaScanStats = true,
|
MediaScanStats = true,
|
||||||
FilterStats = true,
|
FilterStats = true,
|
||||||
MediaStats = true,
|
MediaStats = true,
|
||||||
PartitionStats = true,
|
PartitionStats = true,
|
||||||
ShareStats = true,
|
ShareStats = true,
|
||||||
VerifyStats = true
|
VerifyStats = true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user