Advertisement
jpenguin

osx.patch

Jul 8th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.87 KB | None | 0 0
  1. --- /src/lincity-ng/getBundleSharePath.cpp  2014-04-30 14:02:12.000000000 -0000
  2. +++ /src/lincity-ng/getBundleSharePath.cpp  2014-04-30 12:46:09.000000000 -0700
  3. @@ -0,0 +1,59 @@
  4. + /*
  5. + Function : getBundleSharePath()
  6. + Role : localisation shared datas in a bundle
  7. + Parameter : Name to add at the end of return path
  8. + Return : path to th data of the bundle
  9. + Author : Thierry Maillard - thierry dot maillard500 at orange dot fr
  10. + Date : 25/3/2007
  11. + */
  12. +
  13. + #include <CoreFoundation/CFBundle.h>
  14. + #include <string.h>
  15. + #include <sstream>
  16. + #include <stdexcept>
  17. +
  18. + char *getBundleSharePath(char *packageName)
  19. + {
  20. +   CFBundleRef bundle;
  21. +   CFURLRef bundle_url;
  22. +   CFStringRef sr;
  23. +   static char path[FILENAME_MAX];
  24. +
  25. +   if( !(bundle = CFBundleGetMainBundle()) )
  26. +   {
  27. +           std::stringstream msg;
  28. +           msg << "Can't get application name : CFBundleGetMainBundle()";
  29. +           throw std::runtime_error(msg.str());
  30. +   }
  31. +
  32. +   if( !(bundle_url = CFBundleCopyBundleURL( bundle )) )
  33. +   {
  34. +           std::stringstream msg;
  35. +           msg << "Can't get application name : CFBundleCopyBundleURL()";
  36. +           throw std::runtime_error(msg.str());
  37. +   }
  38. +
  39. +   if( !(sr = CFURLCopyFileSystemPath( bundle_url, kCFURLPOSIXPathStyle )) )
  40. +   {
  41. +       CFRelease( bundle_url );
  42. +           std::stringstream msg;
  43. +           msg << "Can't get application name : CFURLCopyFileSystemPath()";
  44. +           throw std::runtime_error(msg.str());
  45. +   }
  46. +
  47. +   if( !CFStringGetCString( sr, path, FILENAME_MAX, kCFStringEncodingASCII ) )
  48. +   {
  49. +       CFRelease( bundle_url );
  50. +       CFRelease( sr );
  51. +           std::stringstream msg;
  52. +           msg << "Can't get application name : CFStringGetCString()";
  53. +           throw std::runtime_error(msg.str());
  54. +   }
  55. +
  56. +   CFRelease( bundle_url );
  57. +   CFRelease( sr );
  58. +
  59. +   (void)strcat(path, "/Contents/Resources/share/");
  60. +   (void)strcat(path, packageName);
  61. +   return path;
  62. + } /* char *getBundleSharePath() */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement