iOS_utils.mm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * iOS_utils.mm, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "iOS_utils.h"
  11. #import <Foundation/Foundation.h>
  12. namespace
  13. {
  14. NSString *standardPathNative(NSSearchPathDirectory directory)
  15. {
  16. return [NSFileManager.defaultManager URLForDirectory:directory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:NULL].path;
  17. }
  18. const char *standardPath(NSSearchPathDirectory directory) { return standardPathNative(directory).fileSystemRepresentation; }
  19. }
  20. namespace iOS_utils
  21. {
  22. const char *documentsPath() { return standardPath(NSDocumentDirectory); }
  23. const char *cachesPath() { return standardPath(NSCachesDirectory); }
  24. #if TARGET_OS_SIMULATOR
  25. const char *hostApplicationSupportPath()
  26. {
  27. static NSString *applicationSupportPath;
  28. static dispatch_once_t onceToken;
  29. dispatch_once(&onceToken, ^{
  30. auto cachesPath = standardPathNative(NSCachesDirectory);
  31. auto afterMacOsHomeDirPos = [cachesPath rangeOfString:@"Library/Developer"].location;
  32. NSCAssert(afterMacOsHomeDirPos != NSNotFound, @"simulator directory location is not under user's home directory: %@", cachesPath);
  33. applicationSupportPath = [[cachesPath substringToIndex:afterMacOsHomeDirPos] stringByAppendingPathComponent:@"Library/Application Support/vcmi"].stringByResolvingSymlinksInPath;
  34. });
  35. return applicationSupportPath.fileSystemRepresentation;
  36. }
  37. #endif
  38. const char *bundlePath() { return NSBundle.mainBundle.bundlePath.fileSystemRepresentation; }
  39. const char *frameworksPath() { return NSBundle.mainBundle.privateFrameworksPath.fileSystemRepresentation; }
  40. const char *bundleIdentifier() { return NSBundle.mainBundle.bundleIdentifier.UTF8String; }
  41. bool isOsVersionAtLeast(unsigned int osMajorVersion)
  42. {
  43. return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion >= osMajorVersion;
  44. }
  45. }