BundleLib.cxx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. int fileExists(char* filename)
  6. {
  7. #ifndef R_OK
  8. # define R_OK 04
  9. #endif
  10. if ( access(filename, R_OK) != 0 )
  11. {
  12. printf("Cannot find file: %s\n", filename);
  13. return 0;
  14. }
  15. return 1;
  16. }
  17. int findBundleFile(char* exec, const char* file)
  18. {
  19. int res;
  20. char* nexec = strdup(exec);
  21. char* fpath = (char*)malloc(strlen(exec) + 100);
  22. int cc;
  23. int cnt = 0;
  24. printf("Process executable name: %s\n", exec);
  25. // Remove the executable name and directory name
  26. for ( cc = strlen(nexec)-1; cc > 0; cc -- )
  27. {
  28. if ( nexec[cc] == '/' )
  29. {
  30. nexec[cc] = 0;
  31. if ( cnt == 1 )
  32. {
  33. break;
  34. }
  35. cnt ++;
  36. }
  37. }
  38. printf("Process executable path: %s\n", nexec);
  39. sprintf(fpath, "%s/%s", nexec, file);
  40. printf("Check for file: %s\n", fpath);
  41. res = fileExists(fpath);
  42. free(nexec);
  43. free(fpath);
  44. return res;
  45. }
  46. int foo(char *exec)
  47. {
  48. int res1 = findBundleFile(exec, "Resources/randomResourceFile.plist");
  49. int res2 = findBundleFile(exec, "MacOS/SomeRandomFile.txt");
  50. int res3 = findBundleFile(exec, "MacOS/ChangeLog.txt");
  51. if ( !res1 ||
  52. !res2 ||
  53. !res3 )
  54. {
  55. return 1;
  56. }
  57. return 0;
  58. }