summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2015-04-19 14:38:38 +0000
committerjstebbins <[email protected]>2015-04-19 14:38:38 +0000
commit76308dc3563db85da5a3daae74014637423cb249 (patch)
treec53612b2947e5eef6e896cbac8d6cb2340a99b72 /libhb
parent2b0b91800b4e3461f0b9c1d8c3070968b1b9fe90 (diff)
ports: add functions for looking up user config directory
These will be used by the CLI for loading custom user presets. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7105 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/module.defs5
-rw-r--r--libhb/module.rules5
-rw-r--r--libhb/platform/macosx/config.m14
-rw-r--r--libhb/ports.c61
-rw-r--r--libhb/ports.h5
5 files changed, 88 insertions, 2 deletions
diff --git a/libhb/module.defs b/libhb/module.defs
index 79222a2fa..445d66433 100644
--- a/libhb/module.defs
+++ b/libhb/module.defs
@@ -15,6 +15,7 @@ LIBHB.m4.out = $(patsubst $(LIBHB.src/)%.m4,$(LIBHB.build/)%,$(LIBHB.m4.in))
LIBHB.c = $(wildcard $(LIBHB.src/)*.c)
LIBHB.c.o = $(patsubst $(SRC/)%.c,$(BUILD/)%.o,$(LIBHB.c))
+LIBHB.m.o = $(patsubst $(SRC/)%.m,$(BUILD/)%.o,$(LIBHB.m))
LIBHB.d = $(LIBHB.m4.out) $(LIBHB.h.out) \
$(foreach n,$(LIBHB.prerequisites),$($n.INSTALL.target) )
@@ -30,6 +31,7 @@ LIBHB.a = $(LIBHB.build/)$(call TARGET.archive,handbrake)
LIBHB.out += $(LIBHB.m4.out)
LIBHB.out += $(LIBHB.c.o)
+LIBHB.out += $(LIBHB.m.o)
LIBHB.out += $(LIBHB.h.out)
LIBHB.out += $(LIBHB.a)
@@ -50,6 +52,7 @@ ifeq ($(BUILD.system),cygwin)
else ifeq ($(BUILD.system),darwin)
LIBHB.GCC.D += SYS_DARWIN
LIBHB.c += $(wildcard $(LIBHB.src/)platform/macosx/*.c)
+ LIBHB.m += $(wildcard $(LIBHB.src/)platform/macosx/*.m)
else ifeq ($(BUILD.system),linux)
LIBHB.GCC.D += SYS_LINUX _LARGEFILE_SOURCE _FILE_OFFSET_BITS=64
else ifeq ($(BUILD.system),mingw)
@@ -168,7 +171,7 @@ else
endif
LIBHB.GCC.args.extra.dylib++ += -Wl,--out-implib,$(LIBHB.lib)
-LIBHB.GCC.l += ws2_32
+LIBHB.GCC.l += ws2_32 uuid
ifeq ($(HAS.dlfcn),1)
LIBHB.GCC.l += dl
endif
diff --git a/libhb/module.rules b/libhb/module.rules
index c92ababa2..65525cd07 100644
--- a/libhb/module.rules
+++ b/libhb/module.rules
@@ -3,13 +3,16 @@ $(eval $(call import.MODULE.rules,LIBHB))
libhb.build: $(LIBHB.a)
$(LIBHB.a): | $(dir $(LIBHB.a))
-$(LIBHB.a): $(LIBHB.c.o) $(LIBHB.yasm.o)
+$(LIBHB.a): $(LIBHB.c.o) $(LIBHB.m.o) $(LIBHB.yasm.o)
$(AR.exe) rsu $@ $^
$(LIBHB.c.o): $(LIBHB.d)
$(LIBHB.c.o): | $(dir $(LIBHB.c.o))
$(LIBHB.c.o): $(BUILD/)%.o: $(SRC/)%.c
$(call LIBHB.GCC.C_O,$@,$<)
+$(LIBHB.m.o): | $(dir $(LIBHB.m.o))
+$(LIBHB.m.o): $(BUILD/)%.o: $(SRC/)%.m
+ $(call LIBHB.GCC.C_O,$@,$<)
$(LIBHB.m4.out): $(BUILD/)project/handbrake.m4
$(LIBHB.m4.out): | $(dir $(LIBHB.m4.out))
diff --git a/libhb/platform/macosx/config.m b/libhb/platform/macosx/config.m
new file mode 100644
index 000000000..9fa86aaaf
--- /dev/null
+++ b/libhb/platform/macosx/config.m
@@ -0,0 +1,14 @@
+#import <Foundation/Foundation.h>
+/* #import <Cocoa/Cocoa.h> */
+
+void osx_get_user_config_directory(char path[512])
+{
+ @autoreleasepool {
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(
+ NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ NSString *dir = paths[0];
+ strncpy(path, dir.UTF8String, 512);
+ path[511] = 0;
+ }
+}
+
diff --git a/libhb/ports.c b/libhb/ports.c
index 048f478cf..c75a7c943 100644
--- a/libhb/ports.c
+++ b/libhb/ports.c
@@ -7,6 +7,10 @@
For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
*/
+#ifdef SYS_MINGW
+#define _WIN32_WINNT 0x600
+#endif
+
#ifdef USE_PTHREAD
#ifdef SYS_LINUX
#define _GNU_SOURCE
@@ -50,6 +54,7 @@
#include <wchar.h>
#include <mbctype.h>
#include <locale.h>
+#include <shlobj.h>
#endif
#ifdef SYS_SunOS
@@ -493,6 +498,62 @@ int hb_platform_init()
}
/************************************************************************
+ * Get app data config directory
+ ***********************************************************************/
+void hb_get_user_config_directory( char path[512] )
+{
+ /* Create the base */
+#if defined( SYS_CYGWIN ) || defined( SYS_MINGW )
+ WCHAR *wide_path;
+ SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &wide_path);
+ WideCharToMultiByte(CP_UTF8, 0, wide_path, -1, path, 512, NULL, NULL );
+ path[511] = 0;
+#elif defined( SYS_LINUX )
+ char *p;
+
+ if ((p = getenv("XDG_CONFIG_HOME")) != NULL)
+ {
+ strncpy(path, p, 511);
+ path[511] = 0;
+ }
+ else if ((p = getenv("HOME")) != NULL)
+ {
+ strncpy(path, p, 511);
+ path[511] = 0;
+ int len = strlen(path);
+ strncpy(path + len, "/.config", 511 - len - 1);
+ path[511] = 0;
+ }
+ else
+ {
+ hb_error("Failed to lookup user config directory!");
+ path[0] = 0;
+ }
+#elif defined( __APPLE__ )
+ osx_get_user_config_directory(path);
+#endif
+}
+
+/************************************************************************
+ * Get a user config filename for HB
+ ***********************************************************************/
+void hb_get_user_config_filename( char name[1024], char *fmt, ... )
+{
+ va_list args;
+
+ hb_get_user_config_directory( name );
+#if defined( SYS_CYGWIN ) || defined( SYS_MINGW )
+ strcat( name, "\\" );
+#else
+ strcat( name, "/" );
+#endif
+
+ va_start( args, fmt );
+ vsnprintf( &name[strlen(name)], 1024 - strlen(name), fmt, args );
+ va_end( args );
+}
+
+/************************************************************************
* Get a temporary directory for HB
***********************************************************************/
void hb_get_temporary_directory( char path[512] )
diff --git a/libhb/ports.h b/libhb/ports.h
index 649d3995f..42cdede6a 100644
--- a/libhb/ports.h
+++ b/libhb/ports.h
@@ -100,6 +100,11 @@ void hb_get_temporary_directory( char path[512] );
void hb_get_tempory_filename( hb_handle_t *, char name[1024],
char * fmt, ... );
+#if defined( SYS_DARWIN )
+void osx_get_user_config_directory( char path[512] );
+#endif
+void hb_get_user_config_directory( char path[512] );
+void hb_get_user_config_filename( char name[1024], char *fmt, ... );
/************************************************************************
* Threads
***********************************************************************/