From cbff449f8fcac9b5a6428ccaea5e3b0b2773bf29 Mon Sep 17 00:00:00 2001
From: Thomas Goyne <plorkyeran@aegisub.org>
Date: Mon, 21 Oct 2013 18:09:34 -0700
Subject: [PATCH] Put config files in the right place on OS X

---
 .../libaegisub/include/libaegisub/util_osx.h   |  2 ++
 aegisub/libaegisub/osx/util.mm                 |  6 ++++++
 aegisub/libaegisub/unix/path.cpp               | 18 +++++++++---------
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/aegisub/libaegisub/include/libaegisub/util_osx.h b/aegisub/libaegisub/include/libaegisub/util_osx.h
index 1e17e83d9..0efb46a7c 100644
--- a/aegisub/libaegisub/include/libaegisub/util_osx.h
+++ b/aegisub/libaegisub/include/libaegisub/util_osx.h
@@ -93,6 +93,8 @@ std::string OSX_GetBundleExecutablePath();
 /// Pass the basename of the executable to get the path.
 std::string OSX_GetBundleAuxillaryExecutablePath(std::string const& executableName);
 
+std::string OSX_GetApplicationSupportDirectory();
+
 /// @brief Open a URI using the Launcher.
 /// @param location URI of file
 /// @note If this is a FILE or DIRECTORY the path must be ABSOLUTE no 'file://'
diff --git a/aegisub/libaegisub/osx/util.mm b/aegisub/libaegisub/osx/util.mm
index 28162902c..4d718942e 100644
--- a/aegisub/libaegisub/osx/util.mm
+++ b/aegisub/libaegisub/osx/util.mm
@@ -95,6 +95,12 @@ std::string OSX_GetBundleAuxillaryExecutablePath(std::string const& executableNa
 	}
 }
 
+std::string OSX_GetApplicationSupportDirectory() {
+	@autoreleasepool {
+		return EmptyIfNil([NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject]);
+	}
+}
+
 void OSX_OpenLocation(std::string const& location) {
 	@autoreleasepool {
 		NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:location.c_str()]];
diff --git a/aegisub/libaegisub/unix/path.cpp b/aegisub/libaegisub/unix/path.cpp
index 994f5595c..72ad772d7 100644
--- a/aegisub/libaegisub/unix/path.cpp
+++ b/aegisub/libaegisub/unix/path.cpp
@@ -22,6 +22,7 @@
 #include <pwd.h>
 
 namespace {
+#ifndef __APPLE__
 std::string home_dir() {
 	const char *env = getenv("HOME");
 	if (env) return env;
@@ -33,24 +34,23 @@ std::string home_dir() {
 
 	throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set.");
 }
-
-std::string data_dir() {
-#ifndef __APPLE__
-	return P_DATA;
-#else
-	return agi::util::OSX_GetBundleSharedSupportDirectory();
 #endif
 }
 
-}
-
 namespace agi {
 
 void Path::FillPlatformSpecificPaths() {
+#ifndef __APPLE__
 	agi::fs::path home = home_dir();
 	SetToken("?user", home/".aegisub");
 	SetToken("?local", home/".aegisub");
-	SetToken("?data", data_dir());
+	SetToken("?data", P_DATA);
+#else
+	agi::fs::path app_support = agi::util::OSX_GetApplicationSupportDirectory();
+	SetToken("?user", app_support/"Aegisub");
+	SetToken("?local", app_support/"Aegisub");
+	SetToken("?data", agi::util::OSX_GetBundleSharedSupportDirectory());
+#endif
 	SetToken("?temp", boost::filesystem::temp_directory_path());
 	SetToken("?dictionary", "/usr/share/hunspell");
 	SetToken("?docs", P_DOC);
-- 
GitLab