Support newest XDG Base Directory Specification for Linux, fixes #164.

This commit is contained in:
2018-06-17 00:23:43 +01:00
parent 24d88bafdc
commit 32ec415eff

View File

@@ -46,9 +46,14 @@ namespace DiscImageChef.Settings
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>
public ulong GdprCompliance;
/// <summary>
/// If set to <c>true</c>, reports will be saved locally
@@ -62,10 +67,6 @@ namespace DiscImageChef.Settings
/// Statistics
/// </summary>
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
@@ -134,6 +135,11 @@ namespace DiscImageChef.Settings
/// </summary>
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>
/// Current statistcs
/// </summary>
@@ -156,6 +162,7 @@ namespace DiscImageChef.Settings
{
Current = new DicSettings();
PlatformID ptId = DetectOS.GetRealPlatformID();
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
try
{
@@ -205,12 +212,19 @@ namespace DiscImageChef.Settings
// Otherwise, statistics and reports will be saved in ~/.claunia.com/DiscImageChef
default:
{
string appSupportPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".claunia.com");
if(!Directory.Exists(appSupportPath)) Directory.CreateDirectory(appSupportPath);
string xdgDataPath =
Path.Combine(homePath,
Environment.GetEnvironmentVariable(XDG_DATA_HOME) ?? XDG_DATA_HOME_RESOLVED);
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);
ReportsPath = Path.Combine(dicPath, "Reports");
@@ -292,7 +306,9 @@ namespace DiscImageChef.Settings
}
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();
}
@@ -354,11 +370,23 @@ namespace DiscImageChef.Settings
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
default:
{
string configPath =
string oldConfigPath =
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();
SaveSettings();
@@ -481,11 +509,14 @@ namespace DiscImageChef.Settings
// Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
default:
{
string configPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
string settingsPath = Path.Combine(configPath, "DiscImageChef.xml");
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(configPath)) Directory.CreateDirectory(configPath);
if(!Directory.Exists(xdgConfigPath)) Directory.CreateDirectory(xdgConfigPath);
FileStream fs = new FileStream(settingsPath, FileMode.Create);
XmlSerializer xs = new XmlSerializer(Current.GetType());