From 480e1292b1020e47ab9486d4a0f3b1f0f2ddec81 Mon Sep 17 00:00:00 2001 From: "mark@chromium.org" Date: Wed, 10 Dec 2008 22:05:40 +0000 Subject: Load the Ahem font from the source tree when not running bundled, for test_shell_tests. Review URL: http://codereview.chromium.org/13719 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6738 0039d316-1c4b-4281-b951-d872f2087c98 --- base/mac_util.h | 3 +++ base/mac_util.mm | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'base') diff --git a/base/mac_util.h b/base/mac_util.h index 47ec6b6..a6c81fa 100644 --- a/base/mac_util.h +++ b/base/mac_util.h @@ -14,6 +14,9 @@ namespace mac_util { std::string PathFromFSRef(const FSRef& ref); bool FSRefFromPath(const std::string& path, FSRef* ref); +// Returns true if the application is running from a bundle +bool AmIBundled(); + } // namespace mac_util #endif // BASE_MAC_UTIL_H_ diff --git a/base/mac_util.mm b/base/mac_util.mm index 1f92e62..462d165 100644 --- a/base/mac_util.mm +++ b/base/mac_util.mm @@ -4,6 +4,7 @@ #include "base/mac_util.h" +#include #import #include "base/scoped_cftyperef.h" @@ -23,4 +24,21 @@ bool FSRefFromPath(const std::string& path, FSRef* ref) { return status == noErr; } +// Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled +bool AmIBundled() { + ProcessSerialNumber psn = {0, kCurrentProcess}; + + FSRef fsref; + if (GetProcessBundleLocation(&psn, &fsref) != noErr) + return false; + + FSCatalogInfo info; + if (FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, + NULL, NULL, NULL) != noErr) { + return false; + } + + return info.nodeFlags & kFSNodeIsDirectoryMask; +} + } // namespace mac_util -- cgit v1.1