[aquaria] What about using Freedesktop config-spec ? (Patch included)

Julien Humbert julroy67 at gmail.com
Fri Apr 22 07:10:20 EDT 2011


2011/4/22 Thomas W. Most <twm at freecog.net>:
> On Thu, Apr 21, 2011 at 10:03 PM, Ryan C. Gordon <icculus at icculus.org> wrote:
>> On 4/21/11 6:58 PM, Julien Humbert wrote:
>>> Hello everyone !
>>>
>>> Aquaria uses ATM the « ~/.Aquaria » config directory, and I think it
>>> is a bad practice. $HOME is cluttered with many « ~/.something » files
>>> and dirs. Freedesktop has a spec for this. Apps should use « ~/.config
>>> » for user config files and « ~/.local/share » for user data.
>>
>> Mac OS X has the same sort of split (~/Library/Preferences and ~/Library/Application Support), but I think separating the files is counterproductive, so it all goes under Application Support on the Mac.
>>
>> I agree having the ~/.Aquaria directory is undesirable, and it's only there for the sake of Unix legacy. Would there be a lot of complaints, though, if we settled on ~/.local/share/Aquaria for everything?
>
> I disagree about the separation.  In general, the point of separating
> them is that things in ~/.config can be blown away without loosing
> user data, while stuff in ~/.local/share can be treated as more
> precious.  In Aquaria's particular case, it is nice to separate them
> because the user settings include machine-specific stuff like screen
> resolution.  In contrast, data like saved games would be useful to
> synchronize between machines, and this is made easier by segregation.
>
> Regardless, if we mean to implement the XDG spec properly then we'll
> need to check the $XDG_DATA_HOME and $XDG_CONFIG_HOME environment
> variables, using "~/.local/share" and "~/.config" as their default
> values, as defined in the spec [1].
>
> --Tom
>
> [1]: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
> _______________________________________________
> aquaria mailing list
> aquaria at icculus.org
> http://icculus.org/mailman/listinfo/aquaria
>

As Thomas explained, I think separating is better, but altough it is
easy to change and store all in one dir if no one agrees.

As for the XDG spec, I updated the patch and I use separate dirs on
Linux only (OSX uses only one dir for the moment).
Hope it is better handled and I took care of OSX correctly (as in the
previous patch the OSX build was surely broken).
-------------- next part --------------
diff -r ebd81d4a03a4 BBGE/Core.cpp
--- a/BBGE/Core.cpp	Fri Apr 22 04:14:59 2011 -0400
+++ b/BBGE/Core.cpp	Fri Apr 22 13:08:58 2011 +0200
@@ -877,15 +877,40 @@
 
 	mkdir(home.c_str(), 0700);  // just in case.
 
-	// "/home/icculus/.Aquaria" or something. Spaces are okay.
+	// Using XDG Spec for Linux and separate config/data.
 	#ifdef BBGE_BUILD_MACOSX
 	const std::string prefix("Library/Application Support/");
-	#else
-	const std::string prefix(".");
-	#endif
 
 	userDataFolder = home + "/" + prefix + userDataSubFolder;
 	mkdir(userDataFolder.c_str(), 0700);
+
+	#else
+
+	// Checking XDG env vars
+	const char *xdgConfigHome;
+	const char *xdgDataHome;
+
+	if (xdgConfigHome == NULL)
+	{
+		const std::string configPrefix(".config/");
+		userConfigFolder = home + "/" + configPrefix + userDataSubFolder;
+	}
+	else
+		userConfigFolder = xdgConfigHome;
+
+	if (xdgDataHome == NULL)
+	{
+		const std::string dataPrefix(".local/share/");
+		userDataFolder = home + "/" + dataPrefix + userDataSubFolder;
+	}
+	else
+		userDataFolder = xdgDataHome;
+
+	mkdir(userConfigFolder.c_str(), 0700);
+	mkdir(userDataFolder.c_str(), 0700);
+	
+	#endif
+	
 	debugLogPath = userDataFolder + "/";
 	mkdir((userDataFolder + "/screenshots").c_str(), 0700);
 	std::string prefpath(getPreferencesFolder());
@@ -1045,7 +1070,11 @@
 std::string Core::getPreferencesFolder()
 {
 #ifdef BBGE_BUILD_UNIX
-	return userDataFolder + "/preferences";
+	#ifdef BBGE_BUILD_MACOSX
+		return userDataFolder + "/preferences";
+	#else
+		return userConfigFolder;
+	#endif
 #endif
 #ifdef BBGE_BUILD_WINDOWS
 	return "";
diff -r ebd81d4a03a4 BBGE/Core.h
--- a/BBGE/Core.h	Fri Apr 22 04:14:59 2011 -0400
+++ b/BBGE/Core.h	Fri Apr 22 13:08:58 2011 +0200
@@ -1318,6 +1318,7 @@
 
 	void updateCullData();
 
+	std::string userConfigFolder;
 	std::string userDataFolder;
 
 	int grabInputOnReentry;


More information about the aquaria mailing list