CIOSUtils.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * CIOSUtils.m, 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. #import "CIOSUtils.h"
  11. #import <Foundation/Foundation.h>
  12. static NSString *standardPathNative(NSSearchPathDirectory directory)
  13. {
  14. return [NSFileManager.defaultManager URLForDirectory:directory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:NULL].path;
  15. }
  16. static const char *standardPath(NSSearchPathDirectory directory) { return standardPathNative(directory).fileSystemRepresentation; }
  17. const char *ios_documentsPath() { return standardPath(NSDocumentDirectory); }
  18. const char *ios_cachesPath() { return standardPath(NSCachesDirectory); }
  19. #if TARGET_OS_SIMULATOR
  20. const char *ios_hostApplicationSupportPath()
  21. {
  22. static NSString *applicationSupportPath;
  23. static dispatch_once_t onceToken;
  24. dispatch_once(&onceToken, ^{
  25. __auto_type cachesPath = standardPathNative(NSCachesDirectory);
  26. __auto_type afterMacOsHomeDirPos = [cachesPath rangeOfString:@"Library/Developer"].location;
  27. NSCAssert(afterMacOsHomeDirPos != NSNotFound, @"simulator directory location is not under user's home directory: %@", cachesPath);
  28. applicationSupportPath = [[cachesPath substringToIndex:afterMacOsHomeDirPos] stringByAppendingPathComponent:@"Library/Application Support/vcmi"].stringByResolvingSymlinksInPath;
  29. });
  30. return applicationSupportPath.fileSystemRepresentation;
  31. }
  32. #endif
  33. const char *ios_bundlePath() { return NSBundle.mainBundle.bundlePath.fileSystemRepresentation; }
  34. const char *ios_frameworksPath() { return NSBundle.mainBundle.privateFrameworksPath.fileSystemRepresentation; }
  35. const char *ios_bundleIdentifier() { return NSBundle.mainBundle.bundleIdentifier.UTF8String; }