util.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <Foundation/Foundation.h>
  2. #include <UIKit/UIKit.h>
  3. #include "common.h"
  4. #include "SDL_filesystem.h"
  5. LPCSTR
  6. UTIL_BasePath(
  7. VOID
  8. )
  9. {
  10. static char buf[4096] = "";
  11. if (buf[0] == '\0')
  12. {
  13. #ifdef CYDIA
  14. char *p = SDL_GetBasePath();
  15. if (p != NULL)
  16. {
  17. strcpy(buf, p);
  18. free(p);
  19. }
  20. #else
  21. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  22. NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/"];
  23. strcpy(buf, [documentsDirectory UTF8String]);
  24. #endif
  25. }
  26. return buf;
  27. }
  28. LPCSTR
  29. UTIL_SavePath(
  30. VOID
  31. )
  32. {
  33. static char buf[4096] = "";
  34. if (buf[0] == '\0')
  35. {
  36. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  37. NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/"];
  38. strcpy(buf, [documentsDirectory UTF8String]);
  39. }
  40. return buf;
  41. }
  42. BOOL
  43. UTIL_GetScreenSize(
  44. DWORD *pdwScreenWidth,
  45. DWORD *pdwScreenHeight
  46. )
  47. {
  48. if (!pdwScreenWidth || !pdwScreenHeight) return FALSE;
  49. CGRect rect = [UIScreen mainScreen].nativeBounds;
  50. *pdwScreenWidth = rect.size.height;
  51. *pdwScreenHeight = rect.size.width;
  52. return TRUE;
  53. }