macPlatform.mm
Engine/source/platformMac/macPlatform.mm
Public Functions
Detailed Description
Public Functions
osGetTemporaryDirectory()
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#import <Cocoa/Cocoa.h> 25#import <unistd.h> 26#import "platform/platform.h" 27#import "console/console.h" 28#import "core/stringTable.h" 29#import "core/util/str.h" 30#import "platform/platformInput.h" 31#import "platform/threads/thread.h" 32#import "core/util/journal/process.h" 33 34//----------------------------------------------------------------------------- 35// Completely closes and restarts the simulation 36void Platform::restartInstance() 37{ 38 // Returns the NSBundle that corresponds to the directory where the current app executable is located. 39 NSBundle* mainAppBundle = [NSBundle mainBundle]; 40 41 // Returns the file URL of the receiver's executable file. 42 // Not currently used, but left here for reference 43 //NSURL* execURL = [mainAppBundle executableURL]; 44 45 // Returns the full pathname of the receiver's executable file. 46 NSString* execString = [mainAppBundle executablePath]; 47 48 // Create a mutable string we can build into an executable command 49 NSMutableString* mut = [[[NSMutableString alloc] init] autorelease]; 50 51 // Base string is the executable path 52 [mut appendString:execString]; 53 54 // append ampersand so that we can launch without blocking. 55 // encase in quotes so that spaces in the path are accepted. 56 [mut insertString:@"\"" atIndex:0]; 57 [mut appendString:@"\" & "]; 58 [mut appendString:@"\\0"]; 59 60 // Convert to a C string 61 const char* execCString = [mut UTF8String]; 62 63 // Echo the command before we run it 64 Con::printf("---- %s -----", execCString); 65 66 // Run the restart command and hope for the best 67 system(execCString); 68} 69 70void Platform::postQuitMessage(const S32 in_quitVal) 71{ 72 Process::requestShutdown(); 73} 74 75void Platform::forceShutdown(S32 returnValue) 76{ 77 //exit(returnValue); 78 [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0]; 79} 80 81//----------------------------------------------------------------------------- 82void Platform::debugBreak() 83{ 84 raise(SIGTRAP); 85} 86 87#pragma mark ---- Various Directories ---- 88//----------------------------------------------------------------------------- 89const char* Platform::getUserDataDirectory() 90{ 91 // application support directory is most in line with the current usages of this function. 92 // this may change with later usage 93 // perhaps the user data directory should be pref-controlled? 94 NSString *nsDataDir = [@"~/Library/Application Support/" stringByStandardizingPath]; 95 return StringTable->insert([nsDataDir UTF8String]); 96} 97 98//----------------------------------------------------------------------------- 99const char* Platform::getUserHomeDirectory() 100{ 101 return StringTable->insert([[@"~/" stringByStandardizingPath] UTF8String]); 102} 103 104//----------------------------------------------------------------------------- 105StringTableEntry osGetTemporaryDirectory() 106{ 107 NSString *tdir = NSTemporaryDirectory(); 108 const char *path = [tdir UTF8String]; 109 return StringTable->insert(path); 110} 111 112#pragma mark ---- Platform utility funcs ---- 113//----------------------------------------------------------------------------- 114void Platform::outputDebugString( const char *string, ... ) 115{ 116#ifdef TORQUE_DEBUG 117 char buffer[ 2048 ]; 118 119 va_list args; 120 va_start( args, string ); 121 122 dVsprintf( buffer, sizeof( buffer ), string, args ); 123 va_end( args ); 124 125 U32 length = strlen( buffer ); 126 if( length == ( sizeof( buffer ) - 1 ) ) 127 length --; 128 129 buffer[ length ] = '\n'; 130 buffer[ length + 1 ] = '\0'; 131 132 fputs( buffer, stderr ); 133 fflush(stderr); 134#endif 135} 136#ifndef TORQUE_SDL 137//----------------------------------------------------------------------------- 138bool Platform::openWebBrowser( const char* webAddress ) 139{ 140 OSStatus err; 141 CFURLRef url = CFURLCreateWithBytes(NULL,(UInt8*)webAddress,dStrlen(webAddress),kCFStringEncodingASCII,NULL); 142 err = LSOpenCFURLRef(url,NULL); 143 CFRelease(url); 144 145 return(err==noErr); 146} 147#endif 148#pragma mark ---- Administrator ---- 149//----------------------------------------------------------------------------- 150bool Platform::getUserIsAdministrator() 151{ 152 // if we can write to /Library, we're probably an admin 153 // HACK: this is not really very good, because people can chmod Library. 154 return (access("/Library", W_OK) == 0); 155} 156