-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathresource_util_mac.mm
52 lines (40 loc) · 1.32 KB
/
resource_util_mac.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2017 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "examples/shared/resource_util.h"
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
#include <stdio.h>
#include "include/base/cef_logging.h"
namespace shared {
namespace {
// Implementation adapted from Chromium's base/mac/foundation_util.mm
bool UncachedAmIBundled() {
return [[[NSBundle mainBundle] bundlePath] hasSuffix:@".app"];
}
bool AmIBundled() {
static bool am_i_bundled = UncachedAmIBundled();
return am_i_bundled;
}
} // namespace
// Implementation adapted from Chromium's base/base_path_mac.mm
bool GetResourceDir(std::string& dir) {
// Retrieve the executable directory.
uint32_t pathSize = 0;
_NSGetExecutablePath(nullptr, &pathSize);
if (pathSize > 0) {
dir.resize(pathSize);
_NSGetExecutablePath(const_cast<char*>(dir.c_str()), &pathSize);
}
if (AmIBundled()) {
// Trim executable name up to the last separator.
std::string::size_type last_separator = dir.find_last_of("/");
dir.resize(last_separator);
dir.append("/../Resources");
return true;
}
dir.append("/Resources");
return true;
}
} // namespace shared