forked from mia/Aegisub
Remove libosxutil and fold it into libaegisub.
Originally committed to SVN as r4743.
This commit is contained in:
parent
0d12775f4b
commit
d4ba1f48ca
13 changed files with 323 additions and 381 deletions
|
@ -1241,7 +1241,6 @@ po/Makefile.in
|
|||
reporter/Makefile
|
||||
src/Makefile
|
||||
src/bitmaps/Makefile
|
||||
src/libosxutil/Makefile
|
||||
src/libresrc/Makefile
|
||||
tools/Makefile
|
||||
universalchardet/Makefile
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
131
aegisub/libaegisub/include/libaegisub/util_osx.h
Normal file
131
aegisub/libaegisub/include/libaegisub/util_osx.h
Normal file
|
@ -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
|
170
aegisub/libaegisub/osx/util.cpp
Normal file
170
aegisub/libaegisub/osx/util.cpp
Normal file
|
@ -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 <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <CoreFoundation/CFBundle.h>
|
||||
#include <CoreFoundation/CFURL.h>
|
||||
#include <CoreFoundation/CFString.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#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
|
||||
|
|
@ -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
|
||||
|
|
|
@ -95,9 +95,7 @@
|
|||
#include "video_slider.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern "C" {
|
||||
#include "libosxutil/libosxutil.h"
|
||||
}
|
||||
#include <libaegisub/util_osx.h>
|
||||
#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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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 <stdio.h>
|
||||
#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");
|
||||
}
|
|
@ -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 <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <CoreFoundation/CFBundle.h>
|
||||
#include <CoreFoundation/CFURL.h>
|
||||
#include <CoreFoundation/CFString.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#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));
|
||||
}
|
|
@ -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);
|
|
@ -43,10 +43,8 @@
|
|||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern "C" {
|
||||
#include <sys/param.h>
|
||||
#include "libosxutil/libosxutil.h"
|
||||
}
|
||||
#include <libaegisub/util_osx.h>
|
||||
#endif
|
||||
|
||||
#include <libaegisub/log.h>
|
||||
|
@ -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
|
||||
|
|
|
@ -56,9 +56,7 @@
|
|||
#include <libaegisub/log.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern "C" {
|
||||
#include "libosxutil/libosxutil.h"
|
||||
}
|
||||
#include <libaegisub/util_osx.h>
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue