-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost.cpp
More file actions
47 lines (42 loc) · 1.26 KB
/
Copy pathhost.cpp
File metadata and controls
47 lines (42 loc) · 1.26 KB
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
// Path of Building 2 — macOS host launcher
// Loads libSimpleGraphic.dylib by linking at build time; same role as
// Path of Building-PoE2.exe + SimpleGraphic.dll on Windows.
#include <cstdio>
#include <limits.h>
#include <mach-o/dyld.h>
#include <string>
extern "C" int RunLuaFileAsWin(int argc, char** argv);
// Walk up from the executable looking for src/Launch.lua.
// Works for both .app bundle layout (exe in Contents/MacOS/) and
// flat runtime-macos/ dev layout (exe alongside src/).
static std::string findDefaultScript()
{
char raw[PATH_MAX];
uint32_t size = sizeof(raw);
if (_NSGetExecutablePath(raw, &size) != 0) return {};
char resolved[PATH_MAX];
if (!realpath(raw, resolved)) return {};
std::string dir(resolved);
for (int i = 0; i < 6; ++i) {
auto slash = dir.rfind('/');
if (slash == std::string::npos) break;
dir = dir.substr(0, slash);
std::string candidate = dir + "/src/Launch.lua";
if (FILE* f = fopen(candidate.c_str(), "r")) {
fclose(f);
return candidate;
}
}
return {};
}
int main(int argc, char** argv)
{
if (argc < 2) {
std::string script = findDefaultScript();
if (!script.empty()) {
char* newArgv[] = { argv[0], script.data(), nullptr };
return RunLuaFileAsWin(2, newArgv);
}
}
return RunLuaFileAsWin(argc, argv);
}