Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Filesystem.mm 5.0KB

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