sys: Fix macOS compilation (as of 2dc1886) (#317)

* sys: Updated curl to latest version

* sys: Fix macOS compilation

* ui: Fix splash screen OpenGL init for macOS

* sys: Fix std::min compile errors

* git: Re-enabled macos workflow

* sys: Remove includes of the range library

* build: Find OpenGL using CMake

* sys/build: Fix bundled plugins on macOS

* build: Copy plugins to bundle when creating a bundle

* build: Fixup bundled plugins

* sys: Search for plugins in the bundle instead of in Application Support

* sys: Allow resources to be placed in multiple directories on macOS

* build: Output built plugins to the plugins/ directory when not creating a bundle on macOS

* sys: Fix Application Support paths on macOS

* sys: Define ftruncate64 on macOS

* sys: Fix absolute value computation for std::string::at on macOS

Co-authored-by: WerWolv <werwolv98@gmail.com>
This commit is contained in:
Kuruyia
2021-10-09 23:07:58 +02:00
committed by GitHub
parent 21769886fc
commit 72ec6baf79
17 changed files with 100 additions and 75 deletions

View File

@@ -83,7 +83,39 @@ namespace hex {
return results;
#elif defined(OS_MACOS)
return { getPathForMac(path) };
// Get path to special directories
const std::filesystem::path exeDir(getMacExecutableDirectoryPath());
const std::filesystem::path applicationSupportDir(getMacApplicationSupportDirectoryPath());
std::vector<std::filesystem::path> paths = { exeDir, applicationSupportDir };
std::vector<std::string> results;
switch (path) {
case ImHexPath::Patterns:
return { (applicationSupportDir / "patterns").string() };
case ImHexPath::PatternsInclude:
return { (applicationSupportDir / "includes").string() };
case ImHexPath::Magic:
return { (applicationSupportDir / "magic").string() };
case ImHexPath::Python:
return { (applicationSupportDir / "python").string() };
case ImHexPath::Plugins:
std::transform(paths.begin(), paths.end(), std::back_inserter(results), [](auto &path){
return (path / "plugins").string();
});
break;
case ImHexPath::Yara:
return { (applicationSupportDir / "yara").string() };
case ImHexPath::Config:
return { (applicationSupportDir / "config").string() };
case ImHexPath::Resources:
return { (applicationSupportDir / "resources").string() };
case ImHexPath::Constants:
return { (applicationSupportDir / "constants").string() };
default: __builtin_unreachable();
}
return results;
#else
std::vector<std::filesystem::path> configDirs = xdg::ConfigDirs();
std::vector<std::filesystem::path> dataDirs = xdg::DataDirs();

View File

@@ -1,58 +1,29 @@
#if defined(OS_MACOS)
#include <hex/helpers/utils_mac.h>
#include <hex/helpers/paths_mac.h>
#include <Foundation/Foundation.h>
namespace hex {
std::string getPathForMac(ImHexPath path) {
std::string getMacExecutableDirectoryPath() {
@autoreleasepool {
NSError * error = nil;
NSURL * appSupportDir = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:YES
error:&error];
return {[[[[[NSBundle mainBundle] executableURL] URLByDeletingLastPathComponent] path] UTF8String]};
}
}
std::string getMacApplicationSupportDirectoryPath() {
@autoreleasepool {
NSError* error = nil;
NSURL* dirUrl = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:YES
error:&error];
if (error != nil) {
__builtin_unreachable();
}
NSURL * result = nil;
switch (path) {
case ImHexPath::Patterns:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/patterns"];
break;
case ImHexPath::PatternsInclude:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/patterns"];
break;
case ImHexPath::Magic:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/magic"];
break;
case ImHexPath::Python:
result = [appSupportDir URLByAppendingPathComponent:@"imhex"];
break;
case ImHexPath::Plugins:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/plugins"];
break;
case ImHexPath::Yara:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/yara"];
break;
case ImHexPath::Config:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/config"];
break;
case ImHexPath::Resources:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/resources"];
break;
case ImHexPath::Constants:
result = [appSupportDir URLByAppendingPathComponent:@"imhex/constants"];
break;
}
if (result == nil) {
__builtin_unreachable();
}
return std::string([[result path] UTF8String]);
return {[[[dirUrl URLByAppendingPathComponent:(@"imhex")] path] UTF8String]};
}
}
}

View File

@@ -27,26 +27,28 @@
#elif defined(OS_MACOS)
#define RESOURCE_NULL_TERMINATED(name, path) \
#define RESOURCE(name, path) \
__asm__ ( \
".global " #name ";\n" \
".global " #name "_size;\n" \
#name ":\n" \
".global _" #name ";\n" \
".global _" #name "_size;\n" \
"_" #name ":\n" \
".incbin \"" path "\";\n" \
#name "_size:\n" \
".int " #name "_size - " #name ";\n" \
".align 8;\n" \
"_" #name "_size:\n" \
".int _" #name "_size - _" #name ";\n" \
".align 8;\n" \
)
#define RESOURCE_NULL_TERMINATED(name, path) \
__asm__ ( \
".global " #name ";\n" \
".global " #name "_size;\n" \
#name ":\n" \
".global _" #name ";\n" \
".global _" #name "_size;\n" \
"_" #name ":\n" \
".incbin \"" path "\";\n" \
".byte 0\n" \
#name "_size:\n" \
".int " #name "_size - " #name ";\n" \
".align 8;\n" \
"_" #name "_size:\n" \
".int _" #name "_size - _" #name ";\n" \
".align 8;\n" \
)