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

@@ -193,7 +193,14 @@ namespace hex::plugin::builtin {
auto string = Token::literalToString(params[0], false);
auto index = Token::literalToSigned(params[1]);
if (std::abs(index) > string.length())
#if defined(OS_MACOS)
const auto signIndex = index >> (sizeof(index) * 8 - 1);
const auto absIndex = (index ^ signIndex) - signIndex;
#else
const auto absIndex = std::abs(index);
#endif
if (absIndex > string.length())
LogConsole::abortEvaluation("character index out of range");
if (index >= 0)

View File

@@ -750,8 +750,9 @@ namespace hex::plugin::builtin {
size_t fileSize = file.getSize();
for (const auto &pattern : overwritePattern) {
for (u64 offset = 0; offset < fileSize; offset += 3) {
file.write(pattern.data(), std::min(pattern.size(), fileSize - offset));
file.write(pattern.data(), std::min<u64>(pattern.size(), fileSize - offset));
}
file.flush();
}

View File

@@ -11,6 +11,7 @@
#define fopen64 fopen
#define fseeko64 fseek
#define ftello64 ftell
#define ftruncate64 ftruncate
#endif
namespace hex {

View File

@@ -4,6 +4,7 @@
#include <hex/helpers/paths.hpp>
namespace hex {
std::string getPathForMac(ImHexPath path);
std::string getMacExecutableDirectoryPath();
std::string getMacApplicationSupportDirectoryPath();
}
#endif

View File

@@ -5,6 +5,7 @@
#include <hex/helpers/concepts.hpp>
#include <array>
#include <bit>
#include <cstring>
#include <cctype>
#include <functional>

View File

@@ -4,12 +4,12 @@
#include <hex/pattern_language/evaluator.hpp>
#include <hex/pattern_language/pattern_data.hpp>
#include <algorithm>
#include <bit>
#include <optional>
#include <map>
#include <variant>
#include <vector>
#include <ranges>
#include <hex/pattern_language/ast_node_base.hpp>
@@ -1534,9 +1534,9 @@ namespace hex::pl {
continue;
} else {
bool found = false;
for (const auto &variable : (searchScope | std::views::reverse)) {
if (variable->getVariableName() == name) {
auto newPattern = variable->clone();
for (auto iter = searchScope.crbegin(); iter != searchScope.crend(); ++iter) {
if ((*iter)->getVariableName() == name) {
auto newPattern = (*iter)->clone();
delete currPattern;
currPattern = newPattern;
found = true;

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" \
)