Filesystem.mm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <sys/xattr.h>
  2. #include "UnityInterface.h"
  3. #include <cstring>
  4. extern "C" const char* UnityApplicationDir()
  5. {
  6. static const char* dir = NULL;
  7. if (dir == NULL)
  8. dir = AllocCString([NSBundle mainBundle].bundlePath);
  9. return dir;
  10. }
  11. #define RETURN_SPECIAL_DIR(dir) \
  12. do { \
  13. static const char* var = NULL; \
  14. if (var == NULL) \
  15. var = AllocCString(NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES)[0]); \
  16. return var; \
  17. } while (0)
  18. extern "C" const char* UnityDocumentsDir() {
  19. RETURN_SPECIAL_DIR(NSDocumentDirectory);
  20. }
  21. extern "C" const char* UnityLibraryDir() {
  22. RETURN_SPECIAL_DIR(NSLibraryDirectory);
  23. }
  24. extern "C" const char* UnityCachesDir() {
  25. RETURN_SPECIAL_DIR(NSCachesDirectory);
  26. }
  27. #undef RETURN_SPECIAL_DIR
  28. extern "C" int UnityUpdateNoBackupFlag(const char* path, int setFlag)
  29. {
  30. int result;
  31. if (setFlag)
  32. {
  33. u_int8_t b = 1;
  34. result = ::setxattr(path, "com.apple.MobileBackup", &b, 1, 0, 0);
  35. }
  36. else
  37. {
  38. result = ::removexattr(path, "com.apple.MobileBackup", 0);
  39. }
  40. return result == 0 ? 1 : 0;
  41. }
  42. extern "C" const char* const* UnityFontFallbacks()
  43. {
  44. /* The following is the family names of fonts that are used as fallbacks
  45. for characters that were not fount in user-specified fonts. Add more
  46. fonts and/or reorder the list to fit your needs. For certain character
  47. NOTE: Some similar Chinese, Japanese and Korean characters share the
  48. character number in Unicode, but are written differently. To display
  49. such characters properly, correct font must be selected. We reorder
  50. the fonts list on the first run of this function.
  51. */
  52. static const char** cachedFonts = NULL;
  53. if (cachedFonts == NULL)
  54. {
  55. const int fontsToReorderCount = 4;
  56. static const char* defaultFonts[] =
  57. {
  58. // first fontsToReorderCount items will be reordered if needed.
  59. "Hiragino Kaku Gothic ProN", // Japanese characters
  60. "Heiti TC", // Traditional Chinese characters (on 9.0 OS substitutes this with "PingFang TC")
  61. "Heiti SC", // Simplified Chinese characters (on 9.0 OS substitutes this with "PingFang SC")
  62. "Apple SD Gothic Neo", // Korean characters
  63. ".Sukhumvit Set UI", // Thai characters since 8.2 until 9.x
  64. "AppleGothic",
  65. "Noto Sans Yi", // Yi characters on 9.0 (not available on tvOS)
  66. "Helvetica",
  67. "Helvetica Neue",
  68. "Arial Hebrew", // Hebrew since 9.0
  69. "Kohinoor Devanagari", // Hindi since 9.0
  70. "Kohinoor Bangla", // Bengali since 9.0
  71. "Kohinoor Telugu", // Telugu since 9.0
  72. "Lao Sangam MN", // Lao
  73. "Geeza Pro", // Arabic
  74. "Kailasa", // Tibetan since iOS 10.0
  75. ".PhoneFallback", // Armenian, Braille, Georgian, Thai, various symbols since iOS 10.0
  76. // Note that iOS itself prefers Thonburi font for the Thai characters, but our font subsystem
  77. // can't display combining characters for some reason
  78. ".LastResort",
  79. NULL
  80. };
  81. // The default works for Japanese, we won't reorder in that case
  82. static const char* koFontOrder[] =
  83. {
  84. "Apple SD Gothic Neo", // Korean characters
  85. "Hiragino Kaku Gothic ProN", // Japanese characters
  86. "Heiti TC", // Traditional Chinese characters (on 9.0 OS substitutes this with "PingFang TC")
  87. "Heiti SC", // Simplified Chinese characters (on 9.0 OS substitutes this with "PingFang SC")
  88. };
  89. static const char* zhFontOrder[] =
  90. {
  91. "Heiti TC", // Traditional Chinese characters (on 9.0 OS substitutes this with "PingFang TC")
  92. "Heiti SC", // Simplified Chinese characters (on 9.0 OS substitutes this with "PingFang SC")
  93. "Hiragino Kaku Gothic ProN", // Japanese characters
  94. "Apple SD Gothic Neo", // Korean characters
  95. };
  96. const char* lang = UnitySystemLanguage();
  97. const char** fontOrderOverride = NULL;
  98. if (std::strncmp(lang, "ko", 2) == 0)
  99. fontOrderOverride = koFontOrder;
  100. if (std::strncmp(lang, "zh", 2) == 0)
  101. fontOrderOverride = zhFontOrder;
  102. if (fontOrderOverride)
  103. {
  104. for (int i = 0; i < fontsToReorderCount; ++i)
  105. defaultFonts[i] = fontOrderOverride[i];
  106. }
  107. cachedFonts = defaultFonts;
  108. }
  109. return cachedFonts;
  110. }