diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/common/apple/version.m | |
Add the files
Diffstat (limited to 'src/common/apple/version.m')
| -rw-r--r-- | src/common/apple/version.m | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/apple/version.m b/src/common/apple/version.m new file mode 100644 index 0000000..133ec5b --- /dev/null +++ b/src/common/apple/version.m @@ -0,0 +1,43 @@ +#include "common/apple/version.h" +#include "common/strutil.h" + +#import <Foundation/Foundation.h> + +#define APP_CONTENTS_MACOS ".app/Contents/MacOS" + +bool ffGetAppNameAndVersion(const char* exePath, FFstrbuf* retName, FFstrbuf* retVersion) { + char* lastSlash = strrchr(exePath, '/'); + if (!lastSlash) { + return false; + } + if ((size_t) (lastSlash - exePath) > strlen("X" APP_CONTENTS_MACOS) && memcmp(lastSlash - strlen(APP_CONTENTS_MACOS), APP_CONTENTS_MACOS, strlen(APP_CONTENTS_MACOS)) != 0) { + return false; + } + + lastSlash -= strlen("MacOS"); + char infoPlistPath[PATH_MAX]; + memcpy(infoPlistPath, exePath, lastSlash - exePath); + memcpy(infoPlistPath + (lastSlash - exePath), "Info.plist", sizeof("Info.plist")); // X.app/Contents/Info.plist + NSError* error; + NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL fileURLWithPath:@(infoPlistPath)] + error:&error]; + if (!dict) { + return false; + } + + if (retName) { + NSString* bundleName = dict[@"CFBundleDisplayName"] ?: dict[@"CFBundleName"]; + if (bundleName) { + ffStrbufSetS(retName, bundleName.UTF8String); + } + } + + if (retVersion) { + NSString* bundleVersion = dict[@"CFBundleShortVersionString"]; + if (bundleVersion) { + ffStrbufSetS(retVersion, bundleVersion.UTF8String); + } + } + + return true; +} |