aboutsummaryrefslogtreecommitdiff
path: root/src/common/io/Resource.cpp
blob: 0ee7f75310ec9c5d18744f1d0c852ec1771f55aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "cru/common/io/Resource.h"
#include "cru/common/Exception.h"

#if defined(CRU_PLATFORM_OSX)
#include <CoreFoundation/CoreFoundation.h>
#elif defined(CRU_PLATFORM_WINDOWS)
#endif

namespace cru::io {
std::filesystem::path GetResourceDir() {
#if defined(CRU_PLATFORM_OSX)
  CFBundleRef main_bundle = CFBundleGetMainBundle();
  CFURLRef bundle_url = CFBundleCopyBundleURL(main_bundle);
  CFStringRef cf_string_ref =
      CFURLCopyFileSystemPath(bundle_url, kCFURLPOSIXPathStyle);
  std::filesystem::path bundle_path(
      CFStringGetCStringPtr(cf_string_ref, kCFStringEncodingUTF8));

  CFRelease(bundle_url);
  CFRelease(cf_string_ref);

  return bundle_path / "Contents/Resources";
#elif defined(CRU_PLATFORM_WINDOWS)
  throw Exception(u"Not implemented.");
#else
  throw Exception(u"Not implemented.");
#endif
}
}  // namespace cru::io