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
@@ -1,6 +1,11 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(OpenBMH VERSION 0.2.0 LANGUAGES CXX C)
|
||||
if(APPLE)
|
||||
enable_language(OBJCXX)
|
||||
set(CMAKE_OBJCXX_STANDARD 20)
|
||||
set(CMAKE_OBJCXX_STANDARD_REQUIRED ON)
|
||||
endif()
|
||||
# the one place of the version: --version of both programs and the window title (src/version.hpp)
|
||||
add_compile_definitions(OPENBMH_VERSION="${PROJECT_VERSION}")
|
||||
|
||||
|
||||
+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
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "content/package.hpp"
|
||||
#include "content/save.hpp"
|
||||
#include "launch/mods.hpp"
|
||||
#include "launch/process.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "formats/content.hpp"
|
||||
#include "formats/native_state.hpp"
|
||||
#include "formats/vga.hpp"
|
||||
@@ -22,7 +24,20 @@ template <class F> void rejects(F f, const char *message) {
|
||||
}
|
||||
check(failed, message);
|
||||
}
|
||||
int main() try {
|
||||
int main(int argc, char **argv) try {
|
||||
const auto arguments = launch::utf8_arguments(argc, argv);
|
||||
if (arguments.size() > 1 && arguments[1] == "--child-check") {
|
||||
return arguments == std::vector<std::string>{arguments[0], "--child-check", "Grüße with spaces",
|
||||
"quote\" and trailing\\", ""}
|
||||
? 42
|
||||
: 43;
|
||||
}
|
||||
const auto executable = launch::executable_path("not-the-executable");
|
||||
check(fs::is_regular_file(executable),
|
||||
"portable root uses the actual process path rather than argv or current directory");
|
||||
check(launch::run_child(executable, {"--child-check", "Grüße with spaces", "quote\" and trailing\\", ""},
|
||||
{}) == 42,
|
||||
"child startup preserves Unicode, spaces, quotes, trailing slashes and empty arguments");
|
||||
check(content::sha256("") == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
"SHA256 empty vector");
|
||||
check(content::sha256("abc") == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
|
||||
|
||||
Reference in new issue
Block a user