From d4ba1f48ca84a0f3137d5b0c13100920a0009155 Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Sat, 14 Aug 2010 17:42:37 +0000 Subject: [PATCH] Remove libosxutil and fold it into libaegisub. Originally committed to SVN as r4743. --- aegisub/configure.in | 1 - aegisub/libaegisub/Makefile.am | 11 +- .../libaegisub/include/libaegisub/util_osx.h | 131 ++++++++++++++ aegisub/libaegisub/osx/util.cpp | 170 ++++++++++++++++++ aegisub/src/Makefile.am | 13 +- aegisub/src/frame_main_events.cpp | 9 +- aegisub/src/libosxutil/Makefile.am | 14 -- aegisub/src/libosxutil/bundledirs-test.c | 55 ------ aegisub/src/libosxutil/bundledirs.c | 147 --------------- aegisub/src/libosxutil/launch.c | 11 -- aegisub/src/libosxutil/libosxutil.h | 128 ------------- aegisub/src/subtitles_provider_libass.cpp | 6 +- aegisub/src/utils.cpp | 8 +- 13 files changed, 323 insertions(+), 381 deletions(-) create mode 100644 aegisub/libaegisub/include/libaegisub/util_osx.h create mode 100644 aegisub/libaegisub/osx/util.cpp delete mode 100644 aegisub/src/libosxutil/Makefile.am delete mode 100644 aegisub/src/libosxutil/bundledirs-test.c delete mode 100644 aegisub/src/libosxutil/bundledirs.c delete mode 100644 aegisub/src/libosxutil/launch.c delete mode 100644 aegisub/src/libosxutil/libosxutil.h diff --git a/aegisub/configure.in b/aegisub/configure.in index 9d35cfa52..b00e99343 100644 --- a/aegisub/configure.in +++ b/aegisub/configure.in @@ -1241,7 +1241,6 @@ po/Makefile.in reporter/Makefile src/Makefile src/bitmaps/Makefile -src/libosxutil/Makefile src/libresrc/Makefile tools/Makefile universalchardet/Makefile diff --git a/aegisub/libaegisub/Makefile.am b/aegisub/libaegisub/Makefile.am index ae19ae598..e1984200a 100644 --- a/aegisub/libaegisub/Makefile.am +++ b/aegisub/libaegisub/Makefile.am @@ -5,7 +5,7 @@ DISTCLEANFILES= lib_LTLIBRARIES = libaegisub-2.2.la libaegisub_2_2_la_CPPFLAGS = -I../src/include -Iinclude -I. @WX_CPPFLAGS@ -pedantic -DLAGI -libaegisub_2_2_la_LDFLAGS = @ICONV_LDFLAGS@ +AM_LDFLAGS = @ICONV_LDFLAGS@ -L../universalchardet -luniversalchardet if PRECOMPILED_HEADER BUILT_SOURCES = lagi_pre.h.gch @@ -20,6 +20,10 @@ lagi_pre.h.gch: lagi_pre.h DISTCLEANFILES += lagi_pre.h.gch endif +if BUILD_DARWIN +AM_CXXFLAGS += -I/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Headers/ +endif + libaegisub_2_2_la_SOURCES = \ common/charset.cpp \ common/charset_conv.cpp \ @@ -36,5 +40,10 @@ libaegisub_2_2_la_SOURCES = \ unix/access.cpp \ unix/log.cpp +if BUILD_DARWIN +libaegisub_2_2_la_SOURCES += \ + osx/util.cpp +endif + noinst_HEADERS = *.h diff --git a/aegisub/libaegisub/include/libaegisub/util_osx.h b/aegisub/libaegisub/include/libaegisub/util_osx.h new file mode 100644 index 000000000..d63d59d3d --- /dev/null +++ b/aegisub/libaegisub/include/libaegisub/util_osx.h @@ -0,0 +1,131 @@ +// Copyright (c) 2008-2009 Niels Martin Hansen +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Aegisub Project http://www.aegisub.org/ +// +// $Id$ + + +/// @file util_osx.h +/// @brief OSX Utilities +/// @ingroup libaegisub osx +/// +/// Utility functions for running regular *NIX libraries inside application +/// bundles on Apple Macintosh OS X. +/// +/// The GetBundle*Directory functions return the paths of directories inside +/// the appliaction bundle where the application can store static data and +/// shared libraries for its own use. +/// (The bundle and its contents should be considered read-only.) +/// +/// When linking with this library, be sure to add '-framework CoreFoundation' +/// to the GCC commandline. +/// +/// @note All strings returned by these functions are allocated by strdup(), it is +/// the responsibility of the caller to free() them. +/// All of the functions may return NULL on error. + + +namespace agi { + namespace util { + +/// @brief Get the full name of bundle. +/// @return Full name of bundle. +/// Get the full name of the bundle itself. +/// +/// @warning May return NULL if the current executable is not inside a bundle. +char * OSX_GetBundlePath(); + + +/// @brief Get the esources directory. +/// @return Resources directory. +/// +/// Mainly for user interface elements such as graphics and strings +char * OSX_GetBundleResourcesDirectory(); + + +/// @brief Get the built-in plugins directory. +/// @return Built-in plugins directory. +/// +/// This is generaly only used by native Carbon and Cocoa applications. It is +/// not for general shared libraries. +char * OSX_GetBundleBuiltInPlugInsDirectory(); + + +/// @brief Get the private Frameworks directory. +/// @return Private Framework directory. +/// +/// These are suitable locations for shared libraries. +char * OSX_GetBundlePrivateFrameworksDirectory(); + + +/// @brief Get the shared Frameworks directory. +/// @return Shared Framework directory. +/// +/// @see OSX_GetBundlePrivateFrameworksDirectory() +/// @note Does anyone know the difference between private and shared frameworks +/// inside a bundle? +char * OSX_GetBundleSharedFrameworksDirectory(); + + +/// @brief Get the shared support directory +/// @return Shared support directory +/// +/// This is a suitable location for static configuration files. (Remember, +/// bundle is considered read-only.) +char * OSX_GetBundleSharedSupportDirectory(); + + +/// @brief Get the support directory +/// @return Support directory +/// @see OSX_GetBundleSharedSupportDirectory() +/// @note Again, what is the difference between Support and SharedSupport? +char * OSX_GetBundleSupportFilesDirectory(); + + +/// @brief Get the main executable path. +/// @return Main executable path. +/// +/// The binary run when the user launches the bundle from Finder. +char * OSX_GetBundleExecutablePath(); + + +/// @brief Get the auxillary executable path. +/// @return Auxillary executable path. +/// +/// Pass the basename of the executable to get the path. +char * OSX_GetBundleAuxillaryExecutablePath(const char *executableName); + + +/// @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://' +/// @return Error code. +void OSX_OpenLocation(const char *location); + + + } // namespace io +} // namespace agi diff --git a/aegisub/libaegisub/osx/util.cpp b/aegisub/libaegisub/osx/util.cpp new file mode 100644 index 000000000..9c7262f76 --- /dev/null +++ b/aegisub/libaegisub/osx/util.cpp @@ -0,0 +1,170 @@ +// Copyright (c) 2008-2009 Niels Martin Hansen +// Copyright (c) 2010 Amar Takhar +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Aegisub Project http://www.aegisub.org/ +// +// $Id$ + +/// @file util.cpp +/// @brief OSX Utilities +/// @ingroup libosxutil osx + + +#include +#include +#include +#include +#include +#include + +#include "libaegisub/util_osx.h" + +namespace agi { + namespace util { + + +/// @brief Type of functions that return a URL from a bundle. +/// @internal +typedef CFURLRef (*GetURLFunc)(CFBundleRef); + +/// @brief Generic implementation to retrieve pathnames inside a bundle. +/// +/// @internal Provide a generic implementation for most of the logic +/// in path-retrieval, since what differs for the various functions is +/// only the call used to retrieve the actual path inside the bundle. +static char * GetDir(GetURLFunc GetURL) +{ + CFBundleRef bundle; + CFURLRef res_dir_url; + char res_dir_str[MAXPATHLEN]; + Boolean res; + + bundle = CFBundleGetMainBundle(); + if (!bundle) return NULL; + + res_dir_url = (*GetURL)(bundle); + /* we do not own 'bundle' so don't release it */ + if (!res_dir_url) return NULL; + + res = CFURLGetFileSystemRepresentation(res_dir_url, true, (UInt8*)res_dir_str, MAXPATHLEN); + CFRelease(res_dir_url); + + if (res == false) + return NULL; + else + return strdup(res_dir_str); +} + + +char * OSX_GetBundlePath() +{ + return GetDir(CFBundleCopyBundleURL); +} + + +char * OSX_GetBundleResourcesDirectory() +{ + return GetDir(CFBundleCopyResourcesDirectoryURL); +} + + +char * OSX_GetBundleExecutablePath() +{ + return GetDir(CFBundleCopyExecutableURL); +} + + +char * OSX_GetBundleBuiltInPlugInsDirectory() +{ + return GetDir(CFBundleCopyBuiltInPlugInsURL); +} + + +char * OSX_GetBundlePrivateFrameworksDirectory() +{ + return GetDir(CFBundleCopyPrivateFrameworksURL); +} + + +char * OSX_GetBundleSharedFrameworksDirectory() +{ + return GetDir(CFBundleCopySharedFrameworksURL); +} + + +char * OSX_GetBundleSharedSupportDirectory() +{ + return GetDir(CFBundleCopySharedSupportURL); +} + + +char * OSX_GetBundleSupportFilesDirectory() +{ + return GetDir(CFBundleCopySupportFilesDirectoryURL); +} + + +char * OSX_GetBundleAuxillaryExecutablePath(const char *executableName) +{ + CFStringRef exename_str; + CFBundleRef bundle; + CFURLRef res_dir_url; + char res_dir_str[MAXPATHLEN]; + Boolean res; + + exename_str = CFStringCreateWithCString(NULL, executableName, kCFStringEncodingUTF8); + if (!exename_str) return NULL; + + bundle = CFBundleGetMainBundle(); + if (!bundle) return NULL; + + res_dir_url = CFBundleCopyAuxiliaryExecutableURL(bundle, exename_str); + CFRelease(exename_str); + if (!res_dir_url) return NULL; + + res = CFURLGetFileSystemRepresentation(res_dir_url, true, (UInt8*)res_dir_str, MAXPATHLEN); + CFRelease(res_dir_url); + + if (res == false) + return NULL; + else + return strdup(res_dir_str); +} + + +void OSX_OpenLocation (const char *location) { + + CFStringRef CFSlocation = CFStringCreateWithCString(NULL, location, kCFStringEncodingUTF8); + + CFURLRef url = CFURLCreateWithFileSystemPath(NULL, CFSlocation , kCFURLPOSIXPathStyle, false); + OSStatus stat = LSOpenCFURLRef(url, NULL); + printf("libosxutil::OSX_OpenLocation: %s\n", GetMacOSStatusCommentString(stat)); +} + + } // namespace io +} // namespace agi + diff --git a/aegisub/src/Makefile.am b/aegisub/src/Makefile.am index 148130dda..e14b749fd 100644 --- a/aegisub/src/Makefile.am +++ b/aegisub/src/Makefile.am @@ -4,12 +4,6 @@ noinst_LIBRARIES= AM_CXXFLAGS = DISTCLEANFILES = -if BUILD_DARWIN -libosxutil_subdir = libosxutil -libosxutil_lib = libosxutil/libosxutil.a -libosxutil_ldflags = -framework CoreFoundation -endif - if PRECOMPILED_HEADER BUILT_SOURCES = agi_pre.h.gch precompiled_header = agi_pre.h @@ -20,15 +14,14 @@ endif SUBDIRS = \ bitmaps \ - libresrc \ - $(libosxutil_subdir) + libresrc AM_CXXFLAGS += -DAEGISUB -Iinclude -I../libffms/include -I../libaegisub/include @WX_CPPFLAGS@ @OPENMP_CXXFLAGS@ @LIBAVFORMAT_CFLAGS@ @LIBAVCODEC_CFLAGS@ @LIBSWSCALE_CFLAGS@ @LIBAVUTIL_CFLAGS@ bin_PROGRAMS = aegisub-2.2 -aegisub_2_2_LDADD = libresrc/libresrc.a $(libosxutil_lib) -L../libaegisub -laegisub-2.2 +aegisub_2_2_LDADD = libresrc/libresrc.a -L../libaegisub -laegisub-2.2 aegisub_2_2_CPPFLAGS = @FREETYPE_CFLAGS@ -aegisub_2_2_LDFLAGS = @DEBUG_FLAGS@ @PROFILE_FLAGS@ @GL_LIBS@ @PTHREAD_LIBS@ @WX_LIBS@ $(libosxutil_ldflags) @CCMALLOC_LDFLAGS@ @EFENCE_LDFLAGS@ +aegisub_2_2_LDFLAGS = @DEBUG_FLAGS@ @PROFILE_FLAGS@ @GL_LIBS@ @PTHREAD_LIBS@ @WX_LIBS@ @CCMALLOC_LDFLAGS@ @EFENCE_LDFLAGS@ LIBS += @FREETYPE_LIBS@ @FONTCONFIG_LIBS@ @CCMALLOC_LIBS@ if PRECOMPILED_HEADER diff --git a/aegisub/src/frame_main_events.cpp b/aegisub/src/frame_main_events.cpp index c2ea46e58..c7b9624e1 100644 --- a/aegisub/src/frame_main_events.cpp +++ b/aegisub/src/frame_main_events.cpp @@ -95,9 +95,7 @@ #include "video_slider.h" #ifdef __APPLE__ -extern "C" { -#include "libosxutil/libosxutil.h" -} +#include #endif BEGIN_EVENT_TABLE(FrameMain, wxFrame) @@ -588,9 +586,10 @@ void FrameMain::OnContents(wxCommandEvent&) { /// @param event void FrameMain::OnFiles(wxCommandEvent&) { #ifdef __WXMAC__ - char *shared_path = OSX_GetBundleSharedSupportDirectory(); + char *shared_path = agi::util::OSX_GetBundleSharedSupportDirectory(); wxString help_path = wxString::Format(_T("%s/doc"), wxString(shared_path, wxConvUTF8).c_str()); - OSX_OpenLocation(help_path.c_str()); + agi::util::OSX_OpenLocation(help_path.c_str()); + free(shared_path); #endif } diff --git a/aegisub/src/libosxutil/Makefile.am b/aegisub/src/libosxutil/Makefile.am deleted file mode 100644 index c1f21637b..000000000 --- a/aegisub/src/libosxutil/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -noinst_LIBRARIES = libosxutil.a - -libosxutil_a_SOURCES = bundledirs.c launch.c - -libosxutil_a_CFLAGS = -I/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Headers/ -noinst_HEADERS = libosxutil.h - -CLEANFILES = bundledirs-test - -EXTRA_DIST= bundledirs-test.c - -bundledirs-test: libosxutil.a - $(CC) -c bundledirs-test.c - $(CC) -o bundledirs-test -framework CoreFoundation bundledirs-test.c libosxutil.a diff --git a/aegisub/src/libosxutil/bundledirs-test.c b/aegisub/src/libosxutil/bundledirs-test.c deleted file mode 100644 index 172ce87ea..000000000 --- a/aegisub/src/libosxutil/bundledirs-test.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (c) 2009 Niels Martin Hansen - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the Aegisub Group nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include "libosxutil.h" - -void print_path(const char *desc, char *path) -{ - if (!path) path = "(null)"; - printf("%s: %s\n", desc, path); - if (path) free(path); -} - -int main() -{ - char *path; - - printf("Trying to get the various bundle locations:\n"); - - print_path("Bundle path", OSX_GetBundlePath()); - print_path("Resources directory", OSX_GetBundleResourcesDirectory()); - print_path("Built-in plugins directory", OSX_GetBundleBuiltInPlugInsDirectory()); - print_path("Private Frameworks dircetory", OSX_GetBundlePrivateFrameworksDirectory()); - print_path("Shared Frameworks directory", OSX_GetBundleSharedFrameworksDirectory()); - print_path("Shared Support directory", OSX_GetBundleSharedSupportDirectory()); - print_path("Support Files directory", OSX_GetBundleSupportFilesDirectory()); - print_path("Executable path", OSX_GetBundleExecutablePath()); - - printf("All done.\n"); -} diff --git a/aegisub/src/libosxutil/bundledirs.c b/aegisub/src/libosxutil/bundledirs.c deleted file mode 100644 index a0e7999f0..000000000 --- a/aegisub/src/libosxutil/bundledirs.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - Copyright (c) 2008-2009 Niels Martin Hansen - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the Aegisub Group nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - Aegisub Project http://www.aegisub.org/ - - $Id$ -*/ - -/** @file bundledirs.c - * @brief Obtain paths to directories inside Apple OS X bundles - * @ingroup libosxutil - */ - -#include -#include -#include -#include -#include - -#include "libosxutil.h" - -/** @brief Type of functions that return a URL from a bundle. - * @internal - */ -typedef CFURLRef (*GetURLFunc)(CFBundleRef); - -/** @brief Generic implementation to retrieve pathnames inside a bundle. - * - * @internal Provide a generic implementation for most of the logic - * in path-retrieval, since what differs for the various functions is - * only the call used to retrieve the actual path inside the bundle. - */ -static char * GetDir(GetURLFunc GetURL) -{ - CFBundleRef bundle; - CFURLRef res_dir_url; - char res_dir_str[MAXPATHLEN]; - Boolean res; - - bundle = CFBundleGetMainBundle(); - if (!bundle) return NULL; - - res_dir_url = (*GetURL)(bundle); - /* we do not own 'bundle' so don't release it */ - if (!res_dir_url) return NULL; - - res = CFURLGetFileSystemRepresentation(res_dir_url, true, (UInt8*)res_dir_str, MAXPATHLEN); - CFRelease(res_dir_url); - - if (res == false) - return NULL; - else - return strdup(res_dir_str); -} - -char * OSX_GetBundlePath() -{ - return GetDir(CFBundleCopyBundleURL); -} - -char * OSX_GetBundleResourcesDirectory() -{ - return GetDir(CFBundleCopyResourcesDirectoryURL); -} - -char * OSX_GetBundleExecutablePath() -{ - return GetDir(CFBundleCopyExecutableURL); -} - -char * OSX_GetBundleBuiltInPlugInsDirectory() -{ - return GetDir(CFBundleCopyBuiltInPlugInsURL); -} - -char * OSX_GetBundlePrivateFrameworksDirectory() -{ - return GetDir(CFBundleCopyPrivateFrameworksURL); -} - -char * OSX_GetBundleSharedFrameworksDirectory() -{ - return GetDir(CFBundleCopySharedFrameworksURL); -} - -char * OSX_GetBundleSharedSupportDirectory() -{ - return GetDir(CFBundleCopySharedSupportURL); -} - -char * OSX_GetBundleSupportFilesDirectory() -{ - return GetDir(CFBundleCopySupportFilesDirectoryURL); -} - -char * OSX_GetBundleAuxillaryExecutablePath(const char *executableName) -{ - CFStringRef exename_str; - CFBundleRef bundle; - CFURLRef res_dir_url; - char res_dir_str[MAXPATHLEN]; - Boolean res; - - exename_str = CFStringCreateWithCString(NULL, executableName, kCFStringEncodingUTF8); - if (!exename_str) return NULL; - - bundle = CFBundleGetMainBundle(); - if (!bundle) return NULL; - - res_dir_url = CFBundleCopyAuxiliaryExecutableURL(bundle, exename_str); - CFRelease(exename_str); - if (!res_dir_url) return NULL; - - res = CFURLGetFileSystemRepresentation(res_dir_url, true, (UInt8*)res_dir_str, MAXPATHLEN); - CFRelease(res_dir_url); - - if (res == false) - return NULL; - else - return strdup(res_dir_str); -} - - diff --git a/aegisub/src/libosxutil/launch.c b/aegisub/src/libosxutil/launch.c deleted file mode 100644 index 16b979520..000000000 --- a/aegisub/src/libosxutil/launch.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "libosxutil.h" - -void OSX_OpenLocation (const char *location) { - - CFStringRef CFSlocation = CFStringCreateWithCString(NULL, location, kCFStringEncodingUTF8); - - CFURLRef url = CFURLCreateWithFileSystemPath(NULL, CFSlocation , kCFURLPOSIXPathStyle, false); - OSStatus stat = LSOpenCFURLRef(url, NULL); - printf("libosxutil::OSX_OpenLocation: %s\n", GetMacOSStatusCommentString(stat)); -} diff --git a/aegisub/src/libosxutil/libosxutil.h b/aegisub/src/libosxutil/libosxutil.h deleted file mode 100644 index d4612ccbb..000000000 --- a/aegisub/src/libosxutil/libosxutil.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - Copyright (c) 2008-2009 Niels Martin Hansen - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the Aegisub Group nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - Aegisub Project http://www.aegisub.org/ - - $Id$ -*/ - -/** @file libosxutil.h - * @brief Declare all public functions in libosxutil - * @ingroup libosxutil - * - * Utility functions for running regular *NIX libraries inside application - * bundles on Apple Macintosh OS X. - * - * The GetBundle*Directory functions return the paths of directories inside - * the appliaction bundle where the application can store static data and - * shared libraries for its own use. - * (The bundle and its contents should be considered read-only.) - * - * When linking with this library, be sure to add '-framework CoreFoundation' - * to the GCC commandline. - - * @note All strings returned by these functions are allocated by strdup(), it is - * the responsibility of the caller to free() them. - * All of the functions may return NULL on error. - */ - - -/** @brief Get the full name of bundle. - * @return Full name of bundle. - * Get the full name of the bundle itself. - * - * @warning May return NULL if the current executable is not inside a bundle. - */ -char * OSX_GetBundlePath(); - -/** @brief Get the esources directory. - * @return Resources directory. - * - * Mainly for user interface elements such as graphics and strings - */ -char * OSX_GetBundleResourcesDirectory(); - -/** @brief Get the built-in plugins directory. - * @return Built-in plugins directory. - * - * This is generaly only used by native Carbon and Cocoa applications. It is - * not for general shared libraries. - */ -char * OSX_GetBundleBuiltInPlugInsDirectory(); - -/** @brief Get the private Frameworks directory. - * @return Private Framework directory. - * - * These are suitable locations for shared libraries. - */ -char * OSX_GetBundlePrivateFrameworksDirectory(); - -/** @brief Get the shared Frameworks directory. - * @return Shared Framework directory. - * - * @see OSX_GetBundlePrivateFrameworksDirectory() - * @note Does anyone know the difference between private and shared frameworks - * inside a bundle? - */ -char * OSX_GetBundleSharedFrameworksDirectory(); - -/** @brief Get the shared support directory - * @return Shared support directory - * - * This is a suitable location for static configuration files. (Remember, - * bundle is considered read-only.) - */ -char * OSX_GetBundleSharedSupportDirectory(); - -/** @brief Get the support directory - * @return Support directory - * @see OSX_GetBundleSharedSupportDirectory() - * @note Again, what is the difference between Support and SharedSupport? - */ -char * OSX_GetBundleSupportFilesDirectory(); - -/** @brief Get the main executable path. - * @return Main executable path. - * - * The binary run when the user launches the bundle from Finder. - */ -char * OSX_GetBundleExecutablePath(); - -/** @brief Get the auxillary executable path. - * @return Auxillary executable path. - * - * Pass the basename of the executable to get the path. - */ -char * OSX_GetBundleAuxillaryExecutablePath(const char *executableName); - - -/** @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://' - * @return Error code. - */ -void OSX_OpenLocation(const char *location); diff --git a/aegisub/src/subtitles_provider_libass.cpp b/aegisub/src/subtitles_provider_libass.cpp index 6bc0e3a00..62b50b3de 100644 --- a/aegisub/src/subtitles_provider_libass.cpp +++ b/aegisub/src/subtitles_provider_libass.cpp @@ -43,10 +43,8 @@ #endif #ifdef __APPLE__ -extern "C" { #include -#include "libosxutil/libosxutil.h" -} +#include #endif #include @@ -106,7 +104,7 @@ LibassSubtitlesProvider::LibassSubtitlesProvider(std::string) { char config_path[MAXPATHLEN]; char *config_dir; - config_dir = OSX_GetBundleResourcesDirectory(); + config_dir = agi::util::OSX_GetBundleResourcesDirectory(); snprintf(config_path, MAXPATHLEN, "%s/etc/fonts/fonts.conf", config_dir); free(config_dir); #else diff --git a/aegisub/src/utils.cpp b/aegisub/src/utils.cpp index 0ff82c7a1..92b3b9457 100644 --- a/aegisub/src/utils.cpp +++ b/aegisub/src/utils.cpp @@ -56,9 +56,7 @@ #include #ifdef __APPLE__ -extern "C" { -#include "libosxutil/libosxutil.h" -} +#include #endif #include "utils.h" @@ -459,8 +457,8 @@ void RestartAegisub() { wxStandardPaths stand; wxExecute(_T("\"") + stand.GetExecutablePath() + _T("\"")); #elif defined(__WXMAC__) - char *bundle_path = OSX_GetBundlePath(); - char *support_path = OSX_GetBundleSupportFilesDirectory(); + char *bundle_path = agi::util::OSX_GetBundlePath(); + char *support_path = agi::util::OSX_GetBundleSupportFilesDirectory(); if (!bundle_path || !support_path) return; // oops wxString exec = wxString::Format(_T("\"%s/MacOS/restart-helper\" /usr/bin/open -n \"%s\"'"), wxString(support_path, wxConvUTF8).c_str(), wxString(bundle_path, wxConvUTF8).c_str()); LOG_I("util/restart/exec") << exec;