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>
|
||||||
@@ -156,6 +162,7 @@ namespace DiscImageChef.Settings
|
|||||||
{
|
{
|
||||||
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");
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
@@ -481,11 +509,14 @@ 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());
|
||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user