Advertisement
jpenguin

Untitled

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