lldir_macos_objc.mm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @file lldir_macos_objc.cpp
  3. * @brief Cocoa implementation of directory utilities for Mac OS X
  4. *
  5. * $LicenseInfo:firstyear=2010&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #if LL_DARWIN
  33. // WARNING: This file CANNOT use standard linden includes due to conflicts
  34. // between definitions of BOOL
  35. #include "lldir_macos_objc.h"
  36. #import <Cocoa/Cocoa.h>
  37. std::string* getSystemTempFolder()
  38. {
  39. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  40. NSString* tempDir = NSTemporaryDirectory();
  41. if (tempDir == nil)
  42. {
  43. tempDir = @"/tmp";
  44. }
  45. std::string* result = (new std::string([tempDir UTF8String]));
  46. [pool release];
  47. return result;
  48. }
  49. // findSystemDirectory scoped exclusively to this file.
  50. std::string* findSystemDirectory(NSSearchPathDirectory searchPathDirectory,
  51. NSSearchPathDomainMask domainMask)
  52. {
  53. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  54. std::string* result = NULL;
  55. NSString* path = nil;
  56. // Search for the path
  57. NSArray* paths = NSSearchPathForDirectoriesInDomains(searchPathDirectory,
  58. domainMask, YES);
  59. if ([paths count])
  60. {
  61. path = [paths objectAtIndex:0];
  62. // *HACK: always attempt to create directory, ignore errors.
  63. NSError* error = nil;
  64. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  65. result = new std::string([path UTF8String]);
  66. }
  67. [pool release];
  68. return result;
  69. }
  70. std::string* getSystemExecutableFolder()
  71. {
  72. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  73. NSString* bundlePath = [[NSBundle mainBundle] executablePath];
  74. std::string* result = (new std::string([bundlePath UTF8String]));
  75. [pool release];
  76. return result;
  77. }
  78. std::string* getSystemResourceFolder()
  79. {
  80. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  81. NSString* bundlePath = [[NSBundle mainBundle] resourcePath];
  82. std::string* result = (new std::string([bundlePath UTF8String]));
  83. [pool release];
  84. return result;
  85. }
  86. std::string* getSystemCacheFolder()
  87. {
  88. return findSystemDirectory(NSCachesDirectory, NSUserDomainMask);
  89. }
  90. std::string* getSystemApplicationSupportFolder()
  91. {
  92. return findSystemDirectory(NSApplicationSupportDirectory,
  93. NSUserDomainMask);
  94. }
  95. #endif // LL_DARWIN