Fix special user dir lookup on OSX

This uses newer methods that support more folders
such as Downloads.

Closes #1048
This commit is contained in:
Patrick Griffis 2018-06-08 12:01:25 -04:00
parent e1eaea3eea
commit 4a4d7188f6
3 changed files with 28 additions and 38 deletions

View File

@ -357,6 +357,11 @@ libglib_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-export-dynamic $(no_undefined)
if OS_COCOA
libglib_2_0_la_CFLAGS += -xobjective-c
libglib_2_0_la_LDFLAGS += -Wl,-framework,Foundation
endif
INSTALL_PROGS=
if ENABLE_DTRACE

View File

@ -119,8 +119,8 @@
# include <process.h>
#endif
#ifdef HAVE_CARBON
#include <CoreServices/CoreServices.h>
#ifdef HAVE_COCOA
#include <Cocoa/Cocoa.h>
#endif
#ifdef HAVE_CODESET
@ -1402,56 +1402,38 @@ g_get_user_runtime_dir (void)
return runtime_dir;
}
#ifdef HAVE_CARBON
#ifdef HAVE_COCOA
static gchar *
find_folder (OSType type)
find_folder (NSSearchPathDirectory type)
{
gchar *filename = NULL;
FSRef found;
gchar *filename;
NSString *path;
NSArray *paths;
if (FSFindFolder (kUserDomain, type, kDontCreateFolder, &found) == noErr)
paths = NSSearchPathForDirectoriesInDomains (type, NSUserDomainMask, YES);
path = [paths firstObject];
if (path == nil)
{
CFURLRef url = CFURLCreateFromFSRef (kCFAllocatorSystemDefault, &found);
if (url)
{
CFStringRef path = CFURLCopyFileSystemPath (url, kCFURLPOSIXPathStyle);
if (path)
{
filename = g_strdup (CFStringGetCStringPtr (path, kCFStringEncodingUTF8));
if (! filename)
{
filename = g_new0 (gchar, CFStringGetLength (path) * 3 + 1);
CFStringGetCString (path, filename,
CFStringGetLength (path) * 3 + 1,
kCFStringEncodingUTF8);
}
CFRelease (path);
}
CFRelease (url);
}
return NULL;
}
filename = g_strdup ([path UTF8String]);
return filename;
}
static void
load_user_special_dirs (void)
{
g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = find_folder (kDesktopFolderType);
g_user_special_dirs[G_USER_DIRECTORY_DOCUMENTS] = find_folder (kDocumentsFolderType);
g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = find_folder (kDesktopFolderType); /* XXX correct ? */
g_user_special_dirs[G_USER_DIRECTORY_MUSIC] = find_folder (kMusicDocumentsFolderType);
g_user_special_dirs[G_USER_DIRECTORY_PICTURES] = find_folder (kPictureDocumentsFolderType);
g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = NULL;
g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = find_folder (NSDesktopDirectory);
g_user_special_dirs[G_USER_DIRECTORY_DOCUMENTS] = find_folder (NSDocumentDirectory);
g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = find_folder (NSDownloadsDirectory);
g_user_special_dirs[G_USER_DIRECTORY_MUSIC] = find_folder (NSMusicDirectory);
g_user_special_dirs[G_USER_DIRECTORY_PICTURES] = find_folder (NSPicturesDirectory);
g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = find_folder (NSSharedPublicDirectory);
g_user_special_dirs[G_USER_DIRECTORY_TEMPLATES] = NULL;
g_user_special_dirs[G_USER_DIRECTORY_VIDEOS] = find_folder (kMovieDocumentsFolderType);
g_user_special_dirs[G_USER_DIRECTORY_VIDEOS] = find_folder (NSMoviesDirectory);
}
#elif defined(G_OS_WIN32)

View File

@ -569,6 +569,7 @@ if host_system == 'linux'
endif
osx_ldflags = []
osx_cargs = []
glib_have_os_x_9_or_later = false
glib_have_carbon = false
glib_have_cocoa = false
@ -603,12 +604,14 @@ if host_system == 'darwin'
if glib_have_cocoa
glib_conf.set('HAVE_COCOA', true)
osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
osx_cargs += ['-xobjective-c']
endif
# FIXME: libgio mix C and objC source files and there is no way to reliably
# know which language flags it's going to use to link. Add to both languages
# for now. See https://github.com/mesonbuild/meson/issues/3585.
add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
add_project_arguments(osx_cargs, language : ['c'])
endif
# Check for futex(2)