//
//  Paths.mm
//  MacOSX-Framework
//
//  Created by John Ryland on 3/10/17.
//  Copyright © 2017 John Ryland. All rights reserved.
//

#import <Foundation/Foundation.h>
#include "Paths.h"


std::string GetPathForResource(const char* a_resource)
{
  std::string filePath;
  CFStringRef res = CFStringCreateWithCString(kCFAllocatorDefault, a_resource, kCFStringEncodingUTF8);
  CFURLRef appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), res, NULL, NULL);
  if (appUrlRef)
  {
    CFStringRef filePathRef = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle);
    if (filePathRef)
    {
      filePath = CFStringGetCStringPtr(filePathRef , CFStringGetSystemEncoding());
      CFRelease(filePathRef);
    }
    CFRelease(appUrlRef);
  }
  CFRelease(res);
  return filePath;
}

