summary refs log tree commit diff stats
path: root/src/runtime_macos.mm
blob: b46e6f890edb5a9b4a7e71c38e60ed583dd4e7fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "runtime.h"
#import <Foundation/Foundation.h>

std::string Runtime::getResourcePath(std::string_view filename) {
  CFStringRef fileNameRef = CFStringCreateWithCString(kCFAllocatorDefault, filename.data(), kCFStringEncodingUTF8);
  CFURLRef appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), fileNameRef, NULL, NULL);
  CFStringRef filePathRef = CFURLCopyPath(appUrlRef);
  const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8);
  std::string result(filePath);

  CFRelease(filePathRef);
  CFRelease(appUrlRef);
  CFRelease(fileNameRef);

  return result;
}