This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/source/lib/sysdep/os/osx/osx_paths.mm

Last change on this file was 19899, checked in by elexis, 7 years ago

Make all Wildfire Games copyright headers consistent by always ending with a period and using (C) instead of (c).

Differential Revision: https://code.wildfiregames.com/D716
Refs rP19503
Reviewed By: bb
Change in agreement with leper.

  • Property svn:eol-style set to native
File size: 2.6 KB
RevLine 
[19899]1/* Copyright (C) 2013 Wildfire Games.
[11389]2 *
3 * Permission is hereby granted, free of charge, to any person obtaining
4 * a copy of this software and associated documentation files (the
5 * "Software"), to deal in the Software without restriction, including
6 * without limitation the rights to use, copy, modify, merge, publish,
7 * distribute, sublicense, and/or sell copies of the Software, and to
8 * permit persons to whom the Software is furnished to do so, subject to
9 * the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
[11757]23#import <AvailabilityMacros.h> // MAC_OS_X_VERSION_MIN_REQUIRED
[11389]24#import <Foundation/Foundation.h>
25#import <string>
26
27#import "osx_paths.h"
28
29// Helper function
30static std::string getUserDirectoryPath(NSSearchPathDirectory directory)
31{
32 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
33 std::string result;
34
[14140]35 NSArray* paths;
[11757]36#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
[11389]37 // Returns array of NSURL objects which are preferred for file paths
[14140]38 if ([NSFileManager instancesRespondToSelector:@selector(URLsForDirectory)])
39 paths = [[NSFileManager defaultManager] URLsForDirectory:directory inDomains:NSUserDomainMask];
40 else
41#endif // fallback to 10.5 API
42 paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, true);
43
[11389]44 if ([paths count] > 0)
45 {
[14140]46 NSString* pathStr;
[11757]47#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
[11389]48 // Retrieve first NSURL and convert to POSIX path, then get C-string
49 // encoded as UTF-8, and use it to construct std::string
50 // NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
[14140]51 if ([NSFileManager instancesRespondToSelector:@selector(URLsForDirectory)])
52 pathStr = [[paths objectAtIndex:0] path];
53 else
54#endif // fallback to 10.5 API
55 pathStr = [paths objectAtIndex:0];
56
[11389]57 if (pathStr != nil)
58 result = std::string([pathStr UTF8String]);
59 }
60
61 [pool drain];
62 return result;
63}
64
65std::string osx_GetAppSupportPath()
66{
67 return getUserDirectoryPath(NSApplicationSupportDirectory);
68}
69
70std::string osx_GetCachesPath()
71{
72 return getUserDirectoryPath(NSCachesDirectory);
73}
Note: See TracBrowser for help on using the repository browser.