Fix native launcher platform setup and executable discovery (by Codex)
This commit is contained in:
1 parent
2552528176
commit
481b525582
7 files changed
+56
-4
No files matched your search
+2
-1
@@ -33,6 +33,7 @@
|
||||
#include "launch/archive.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "content/package.hpp"
|
||||
#include "launch/process.hpp"
|
||||
#include "launch/mods.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
@@ -723,7 +724,7 @@ int main(int argc, char** argv) {
|
||||
args.data = mount->root();
|
||||
if (args.saves.empty()) {
|
||||
bmh::launch::ModLibrary library(
|
||||
std::filesystem::absolute(bmh::launch::path_from_utf8(argv[0])).parent_path());
|
||||
bmh::launch::executable_path(bmh::launch::path_from_utf8(argv[0])).parent_path());
|
||||
bmh::launch::ModEntry mod;
|
||||
mod.content_id = contents->content_id;
|
||||
args.saves = library.user_directory(mod);
|
||||
|
||||
@@ -34,7 +34,6 @@ if(WIN32)
|
||||
target_sources(bmh_launcher PRIVATE ../launch/launcher_win32.cpp)
|
||||
target_link_libraries(bmh_launcher PRIVATE comctl32 ole32 shell32 uuid)
|
||||
elseif(APPLE)
|
||||
enable_language(OBJCXX)
|
||||
set_property(TARGET bmh_launcher PROPERTY OBJCXX_STANDARD 20)
|
||||
target_sources(bmh_launcher PRIVATE ../launch/launcher_cocoa.mm)
|
||||
set_source_files_properties(../launch/launcher_cocoa.mm PROPERTIES COMPILE_OPTIONS "-fobjc-arc")
|
||||
|
||||
@@ -124,9 +124,9 @@ class CocoaLauncher final : public LauncherUI {
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
~CocoaLauncher() override {
|
||||
finish_progress();
|
||||
bridge_->action = {};
|
||||
bridge_->selection = {};
|
||||
finish_progress();
|
||||
window_.delegate = nil;
|
||||
[window_ orderOut:nil];
|
||||
[window_ close];
|
||||
|
||||
@@ -11,9 +11,40 @@
|
||||
#include <spawn.h>
|
||||
#include <sys/wait.h>
|
||||
#include <cerrno>
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
extern char **environ;
|
||||
#endif
|
||||
namespace bmh::launch {
|
||||
std::filesystem::path executable_path(const std::filesystem::path &invocation) {
|
||||
#ifdef _WIN32
|
||||
std::vector<wchar_t> buffer(1024);
|
||||
for (;;) {
|
||||
const auto length = GetModuleFileNameW(nullptr, buffer.data(), DWORD(buffer.size()));
|
||||
if (!length)
|
||||
throw std::runtime_error("Cannot locate OpenBMH executable");
|
||||
if (length < buffer.size())
|
||||
return std::filesystem::path(std::wstring(buffer.data(), length));
|
||||
if (buffer.size() > 32768)
|
||||
throw std::runtime_error("Executable path is too long");
|
||||
buffer.resize(buffer.size() * 2);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
uint32_t size = 0;
|
||||
_NSGetExecutablePath(nullptr, &size);
|
||||
std::vector<char> buffer(size);
|
||||
if (_NSGetExecutablePath(buffer.data(), &size) != 0)
|
||||
throw std::runtime_error("Cannot locate OpenBMH executable");
|
||||
return std::filesystem::canonical(path_from_utf8(buffer.data()));
|
||||
#else
|
||||
std::error_code error;
|
||||
const auto path = std::filesystem::read_symlink("/proc/self/exe", error);
|
||||
if (!error)
|
||||
return path;
|
||||
return std::filesystem::absolute(invocation).lexically_normal();
|
||||
#endif
|
||||
}
|
||||
int run_child(const std::filesystem::path &executable, const std::vector<std::string> &args,
|
||||
const std::function<void()> &pump) {
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace bmh::launch {
|
||||
std::filesystem::path executable_path(const std::filesystem::path &invocation);
|
||||
int run_child(const std::filesystem::path &, const std::vector<std::string> &,
|
||||
const std::function<void()> &pump);
|
||||
} // namespace bmh::launch
|
||||
Reference in new issue
Block a user