From 3eb239ad3bd03d16c379019c4eb7950d17247907 Mon Sep 17 00:00:00 2001 From: Martin Natano Date: Tue, 31 May 2022 13:51:15 -0700 Subject: [PATCH] Replace deprecated macOS APIs with modern equivalents --- Xcode/Hardware.in.plist | 86 ----------- Xcode/Hardware.plist | Bin 3578 -> 0 bytes src/CMakeData-arch.cmake | 4 +- src/CMakeData-os.cmake | 4 +- src/CMakeLists.txt | 3 - src/arch/ArchHooks/ArchHooks_MacOSX.mm | 145 ++++++------------ ...OSX_HID.cpp => InputHandler_MacOSX_HID.mm} | 13 +- .../LoadingWindow/LoadingWindow_MacOSX.mm | 6 +- .../LowLevelWindow/LowLevelWindow_MacOSX.mm | 5 +- ...undDriver_AU.cpp => RageSoundDriver_AU.mm} | 64 +++----- src/archutils/Darwin/{Crash.cpp => Crash.mm} | 15 +- src/archutils/Darwin/HIDDevice.cpp | 4 +- src/archutils/Darwin/HIDDevice.h | 4 +- src/archutils/Darwin/PreferredLanguage.m | 2 +- src/archutils/Darwin/SMMain.mm | 6 +- .../{SpecialDirs.cpp => SpecialDirs.mm} | 22 +-- 16 files changed, 110 insertions(+), 273 deletions(-) delete mode 100644 Xcode/Hardware.in.plist delete mode 100644 Xcode/Hardware.plist rename src/arch/InputHandler/{InputHandler_MacOSX_HID.cpp => InputHandler_MacOSX_HID.mm} (97%) rename src/arch/Sound/{RageSoundDriver_AU.cpp => RageSoundDriver_AU.mm} (85%) rename src/archutils/Darwin/{Crash.cpp => Crash.mm} (93%) rename src/archutils/Darwin/{SpecialDirs.cpp => SpecialDirs.mm} (73%) diff --git a/Xcode/Hardware.in.plist b/Xcode/Hardware.in.plist deleted file mode 100644 index a7f168ed8f..0000000000 --- a/Xcode/Hardware.in.plist +++ /dev/null @@ -1,86 +0,0 @@ -/* http://www.cocoadev.com/index.pl?MacintoshModels */ -{ - "ADP2,1" = "Developer Transition Kit"; - "iMac,1" = iMac; - "iMac4,1" = "iMac (Core Duo)"; - "iMac5,1" = "iMac (Core 2 Duo)"; - "iMac6,1" = "iMac (24-inch Core 2 Duo)"; - "iMac7,1" = "iMac (Aluminum Core 2 Duo)"; - "iMac8,1" = "iMac (Aluminum Core 2 Duo)"; - "M43ADP1,1" = "Development Mac Pro"; - "MacBook1,1" = "MacBook (Core Duo)"; - "MacBook2,1" = "MacBook (Core 2 Duo)"; - "MacBook3,1" = "MacBook (Core 2 Duo)"; - "MacBook4,1" = "MacBook (Early 2008)"; - "MacBookAir1,1" = "MacBook Air"; - "MacBookPro1,1" = "MacBook Pro (15-inch Core Duo)"; - "MacBookPro1,2" = "MacBook Pro (17-inch Core Duo)"; - "MacBookPro2,1" = "MacBook Pro (17-inch Core 2 Duo)"; - "MacBookPro2,2" = "MacBook Pro (15-inch Core 2 Duo)"; - "MacBookPro3,1" = "MacBook Pro (15-inch or 17-inch LED, Core 2 Duo)"; - "MacBookPro4,1" = "MacBook Pro (15-inch or 17-inch LED, Early 2008)"; - "MacBookPro5,1" = "MacBook Pro (15-inch LED Unibody, Late 2008)"; - "Macmini1,1" = "Mac mini (Core Duo/Solo)"; - "MacPro1,1" = "Mac Pro (Quad Xeon)"; - "MacPro2,1" = "Mac Pro (Octal Xeon)"; - "MacPro3,1" = "Mac Pro (Early 2008)"; - "PowerBook1,1" = "PowerBook G3"; - "PowerBook2,1" = iBook; - "PowerBook2,2" = "iBook (FireWire)"; - "PowerBook3,1" = "PowerBook G3 (FireWire)"; - "PowerBook3,2" = "PowerBook G4"; - "PowerBook3,3" = "PowerBook G4 (Gigabit Ethernet)"; - "PowerBook3,4" = "PowerBook G4 (DVI)"; - "PowerBook3,5" = "PowerBook G4 (867, 1 GHz)"; - "PowerBook4,1" = "iBook G3"; - "PowerBook4,2" = "iBook G3"; - "PowerBook4,3" = "iBook G3"; - "PowerBook5,1" = "PowerBook G4 (17-inch)"; - "PowerBook5,2" = "PowerBook G4 (15-inch FW800)"; - "PowerBook5,3" = "PowerBook G4 (17-inch 1.33 GHz)"; - "PowerBook5,4" = "PowerBook G4 (15-inch 1.5/1.33 GHz)"; - "PowerBook5,5" = "PowerBook G4 (17-inch 1.5 GHz)"; - "PowerBook5,6" = "PowerBook G4 (15-inch 1.67/1.5 GHz)"; - "PowerBook5,7" = "PowerBook G4 (17-inch 1.67 GHz)"; - "PowerBook5,8" = "PowerBook G4 (Double-Layer SD, 15-inch)"; - "PowerBook5,9" = "PowerBook G4 (Double-Layer SD, 17-inch)"; - "PowerBook6,1" = "PowerBook G4 (12-inch)"; - "PowerBook6,2" = "PowerBook G4 (12-inch DVI)"; - "PowerBook6,3" = "iBook G4"; - "PowerBook6,4" = "PowerBook G4 (12-inch 1.33 GHz)"; - "PowerBook6,5" = "iBook G4"; - "PowerBook6,7" = "iBook G4"; - "PowerBook6,8" = "PowerBook G4 (12-inch 1.5 GHz)"; - "PowerMac1,1" = "Power Macintosh G3 (B&W)"; - "PowerMac1,2" = "Power Macintosh G4 (PCI-Graphics)"; - "PowerMac10,1" = "Mac mini"; - "PowerMac10,2" = "Mac mini"; - "PowerMac11,2" = "Power Macintosh G5 (PCIe)"; - "PowerMac12,1" = "iMac G5 (iSight)"; - "PowerMac2,1" = "iMac (Slot-Loading)"; - "PowerMac2,2" = "iMac (2000)"; - "PowerMac3,1" = "Power Macintosh G4 (AGP-Graphics)"; - "PowerMac3,2" = "Power Macintosh G4 (AGP-Graphics)"; - "PowerMac3,3" = "Power Macintosh G4 (Gigabit Ethernet)"; - "PowerMac3,4" = "Power Macintosh G4 (Digital Audio)"; - "PowerMac3,5" = "Power Macintosh G4 (Quick Silver)"; - "PowerMac3,6" = "Power Macintosh G4 (Mirrored Drive Doors)"; - "PowerMac4,1" = "iMac (2001)"; - "PowerMac4,2" = "iMac (Flat Panel)"; - "PowerMac4,4" = "eMac G3"; - "PowerMac4,5" = "iMac (17-inch Flat Panel)"; - "PowerMac5,1" = "Power Macintosh G4 Cube"; - "PowerMac6,1" = "iMac (USB 2.0)"; - "PowerMac6,3" = "iMac (20-inch Flat Panel)"; - "PowerMac6,4" = "eMac (USB 2.0)"; - "PowerMac7,2" = "Power Macintosh G5"; - "PowerMac7,3" = "Power Macintosh G5"; - "PowerMac8,1" = "iMac G5"; - "PowerMac8,2" = "iMac G5 (Ambient Light Sensor)"; - "PowerMac9,1" = "Power Macintosh G5 (Late 2004)"; - "RackMac1,1" = "Xserve G4"; - "RackMac1,2" = "Xserve G4 (Slot-Loading)"; - "RackMac3,1" = "Xserve G5"; - "Xserve1,1" = "Xserve Xeon"; - "Xserve2,1" = "Xserve Xeon"; -} diff --git a/Xcode/Hardware.plist b/Xcode/Hardware.plist deleted file mode 100644 index 5a48c93d56adbdebf66688451ee77d44655951b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3578 zcma)8X>1gA6yG`aUS&DtKK>kqU7VJkot@nxcoeo>jur|FJ)z5PJG4W$J9WBSESDkz zB8Y&ZC~|m0h<@OMiHS-ge9)MP3DFQ^;zdm41BoF~5q z2!$6u%v4q_im*{G#>W%Yiyv9C^wGy2f1+mD@?>pYYQ@S`tLq!qtZiJkKD}XMQ*%pe zTl=QX9hoiJTxXZCwYx{$)|>AuNc~UB1I5zd_NRt+?A*0`&(qKBeRkh-`wtv^{?H4D zkGy#FrDMlWy!^_^S6@5z`WvU;JahKk`M2JF=iT?--_$5=7vyD<)XOu~?dpeyY-f~V z+u+eB7DSd|Egz2Inrf1bV7A`H8Ln9b=LExUhKB;xC`&QBOTvT(ck677iJFEe6SWKw zK?SYW5>Y^Hh&;oZ2NO)R6#_$0TV6cFYj|K|Su7A|OBCuek>X6uN`Yq4 zc?@TsWpN*0OzJN$iS!-FpSUu4hAblURP+@%LL{R`mp?=8D<2i$TGw+ z0~Du|27Nc(V}>BgWn-fWYQti~d7ToIFs){d2smlNb4=Xe43CPdJBBCBGqFr?fjQzR z6+@w7CL*vnc#S(K`4~YOU251DcdC$y5a3)<)yL;P-wX% z3n*EV7Nw=U1g2Sb=#2ZrCxt;FFZDyL4RW?HAQnZbfL4pe7Ez%H zGRg#}YGG^gC5Te$Lu!<$5(fYx5MA|zuA-2hE0ScyCe*Z1eJ#{bo0aoJC>n`WhcVzO z8gMkCdDi8#Mbwxr2zk?qYd2gXk?=+}rTgSF!N@0s#modJ+L_RkgZ#&-1_YSBdKrpVMZo{Q($RVVp5qK;QzKz@jMZ{A4)lJ50-ILC ziJ;1Sibo+aEq3=PVkwgo8`b*8R&kt8z<6CweL|tAaH^0v3diMSnqUT*_b1Gd5|;@o z!G_Dwrqr2cK{b6jQAw~~sSBlr!hj@)^=$!)w=~D9JgB&#I#Cvy;TK*_*0!-au4ThG zy-Xt7?4r8nY7nrYAe-7ys6Ja1l-Y=Z!~Yv6tgd!F7e%6(;M|eJvsLlLB1@(fBS~?D zmm~zqrEdnr9}}RtSd1SoHJ6jNwHg0CcCE8B`Rx7D-~}{3@tC^1XC5T6&Rxe+jPQy zLmLZXPU;$BkkQI&fGnRDeIH`eq8DN-Zq!rpgg#?sOG1Y=E4Qvgb$O3CMe9mpXD>>N z`9VR3Os8UfhNWc8wYCQ)52FvHuxx&F7*}4ix|vegmk^ZVI<%e`>&j^Q@M*RyOV^5*v{AO0&^cuQ}&e47J5WSy1L4Qi$pzk=xI2SrOXQOkU^N91J^Rn|Z=QZcg&U>z)tHQO^ zwb?b~I^(+H`r38R9dJ)@huurv9qyw0ko%JRy8EX4Z_hMOg@^SdJsHm)&pFQx&yQZ( z%XsU&8ShT-LGLl|N$&^VYu=mQ+upmrNj}!M#JA0N#CP6z)pyJHhkt^f_1F7b{9F8e m{$2k4{)_%A{xAHu0%HR61FHgC9qJEBXivul{i#0!NB#rzTTbo( diff --git a/src/CMakeData-arch.cmake b/src/CMakeData-arch.cmake index a4b4823be9..2422a268e8 100644 --- a/src/CMakeData-arch.cmake +++ b/src/CMakeData-arch.cmake @@ -44,7 +44,7 @@ if(WIN32) "arch/Sound/RageSoundDriver_WaveOut.h" "arch/Sound/RageSoundDriver_WDMKS.h") elseif(APPLE) - list(APPEND SMDATA_ARCH_SOUND_SRC "arch/Sound/RageSoundDriver_AU.cpp") + list(APPEND SMDATA_ARCH_SOUND_SRC "arch/Sound/RageSoundDriver_AU.mm") list(APPEND SMDATA_ARCH_SOUND_HPP "arch/Sound/RageSoundDriver_AU.h") else() # Unix if(HAS_PULSE) @@ -273,7 +273,7 @@ if(WIN32) endif() elseif(APPLE) list(APPEND SMDATA_ARCH_INPUT_SRC - "arch/InputHandler/InputHandler_MacOSX_HID.cpp") + "arch/InputHandler/InputHandler_MacOSX_HID.mm") list(APPEND SMDATA_ARCH_INPUT_HPP "arch/InputHandler/InputHandler_MacOSX_HID.h") else() # Unix/Linux diff --git a/src/CMakeData-os.cmake b/src/CMakeData-os.cmake index 63ef1a064b..93c3fc0700 100644 --- a/src/CMakeData-os.cmake +++ b/src/CMakeData-os.cmake @@ -1,6 +1,6 @@ if(APPLE) list(APPEND SMDATA_OS_DARWIN_SRC - "archutils/Darwin/Crash.cpp" + "archutils/Darwin/Crash.mm" "archutils/Darwin/DarwinThreadHelpers.cpp" "archutils/Darwin/HIDDevice.cpp" "archutils/Darwin/JoystickDevice.cpp" @@ -8,7 +8,7 @@ if(APPLE) "archutils/Darwin/MouseDevice.cpp" "archutils/Darwin/PumpDevice.cpp" "archutils/Darwin/SMMain.mm" - "archutils/Darwin/SpecialDirs.cpp" + "archutils/Darwin/SpecialDirs.mm" "archutils/Darwin/VectorHelper.cpp") list(APPEND SMDATA_OS_DARWIN_HPP "archutils/Darwin/arch_setup.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d17c74da6..4a16f1fd2f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -230,9 +230,6 @@ elseif(APPLE) "$/../Resources" COMMAND ${CMAKE_COMMAND} -E copy "${SM_XCODE_DIR}/logo.icns" - "$/../Resources/" - COMMAND ${CMAKE_COMMAND} -E copy - "${SM_XCODE_DIR}/Hardware.plist" "$/../Resources/") else() # Linux set_target_properties("${SM_EXE_NAME}" diff --git a/src/arch/ArchHooks/ArchHooks_MacOSX.mm b/src/arch/ArchHooks/ArchHooks_MacOSX.mm index d6f4754e94..53de4c4424 100644 --- a/src/arch/ArchHooks/ArchHooks_MacOSX.mm +++ b/src/arch/ArchHooks/ArchHooks_MacOSX.mm @@ -20,6 +20,7 @@ extern "C" { #include #include +#import #import static bool IsFatalSignal( int signal ) @@ -146,7 +147,7 @@ void ArchHooks_MacOSX::DumpDebugInfo() { // http://stackoverflow.com/a/891336 NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; - NSString *productVersion = [version objectForKey:@"ProductVersion"]; + NSString *productVersion = version[@"ProductVersion"]; SystemVersion = ssprintf("macOS %s", [productVersion cStringUsingEncoding:[NSString defaultCStringEncoding]]); } @@ -158,16 +159,9 @@ void ArchHooks_MacOSX::DumpDebugInfo() { uint64_t iRam = 0; GET_PARAM( "hw.memsize", iRam ); - if( iRam >= 1073741824 ) - { - fRam = float( double(iRam) / 1073741824.0 ); - ramPower = 'G'; - } - else - { - fRam = float( double(iRam) / 1048576.0 ); - ramPower = 'M'; - } + + fRam = float( double(iRam) / 1073741824.0 ); + ramPower = 'G'; } // Get processor information @@ -175,7 +169,7 @@ void ArchHooks_MacOSX::DumpDebugInfo() int iCPUs = 0; float fFreq; char freqPower; - RString sModel; + RString sModel("Unknown"); do { char szModel[128]; uint64_t iFreq; @@ -184,49 +178,23 @@ void ArchHooks_MacOSX::DumpDebugInfo() GET_PARAM( "hw.logicalcpu", iCPUs ); GET_PARAM( "hw.cpufrequency", iFreq ); - if( iFreq >= 1000000000 ) - { - fFreq = float( double(iFreq) / 1000000000.0 ); - freqPower = 'G'; - } - else - { - fFreq = float( double(iFreq) / 1000000.0 ); - freqPower = 'M'; - } + fFreq = float( double(iFreq) / 1000000000.0 ); + freqPower = 'G'; - if( GET_PARAM("hw.model", szModel) ) - { - sModel = "Unknown"; + if( GET_PARAM("hw.model", szModel) != 0 ) break; - } + sModel = szModel; - CFURLRef urlRef = CFBundleCopyResourceURL( CFBundleGetMainBundle(), CFSTR("Hardware.plist"), nil, nil); - if( urlRef == nil) + NSURL* url = [NSURL fileURLWithPath:@"//System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/en.lproj/SIMachineAttributes.plist"]; + NSDictionary* machineAttributes = [NSDictionary dictionaryWithContentsOfURL:url]; + if (machineAttributes == nil) break; - CFDataRef dataRef = nil; - SInt32 error; - CFURLCreateDataAndPropertiesFromResource( nil, urlRef, &dataRef, nil, nil, &error ); - CFRelease( urlRef ); - if( dataRef == nil) - break; - // This also works with binary property lists for some reason. - CFPropertyListRef plRef = CFPropertyListCreateFromXMLData( nil, dataRef, kCFPropertyListImmutable, nil); - CFRelease( dataRef ); - if( plRef == nil) - break; - if( CFGetTypeID(plRef) != CFDictionaryGetTypeID() ) - { - CFRelease( plRef ); - break; - } - CFStringRef keyRef = CFStringCreateWithCStringNoCopy( nil, szModel, kCFStringEncodingMacRoman, kCFAllocatorNull ); - CFStringRef modelRef = (CFStringRef)CFDictionaryGetValue( (CFDictionaryRef)plRef, keyRef ); - if( modelRef ) - sModel = CFStringGetCStringPtr( modelRef, kCFStringEncodingMacRoman ); - CFRelease( keyRef ); - CFRelease( plRef ); + + NSString* key = [NSString stringWithUTF8String:szModel]; + NSString* val = machineAttributes[key][@"_LOCALIZABLE_"][@"marketingModel"]; + if (val != nil) + sModel = [val UTF8String]; } while( false ); #undef GET_PARAM @@ -303,16 +271,6 @@ int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) #include "RageFileManager.h" -static void PathForFolderType( char dir[PATH_MAX], OSType folderType ) -{ - FSRef fs; - - if( FSFindFolder(kUserDomain, folderType, kDontCreateFolder, &fs) ) - FAIL_M( ssprintf("FSFindFolder(%lu) failed.", folderType) ); - if( FSRefMakePath(&fs, (UInt8 *)dir, PATH_MAX) ) - FAIL_M( "FSRefMakePath() failed." ); -} - void ArchHooks::MountInitialFilesystems( const RString &sDirOfExecutable ) { FILEMAN->Mount("dirro", sDirOfExecutable, "/"); @@ -374,41 +332,48 @@ void ArchHooks::MountInitialFilesystems( const RString &sDirOfExecutable ) } } +static std::string PathForDirectory( NSSearchPathDirectory directory ) +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSURL *url = [fileManager URLForDirectory:directory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; + if (url == nil) + FAIL_M( "URLForDirectory() failed." ); + + return [url fileSystemRepresentation]; +} + void ArchHooks::MountUserFilesystems( const RString &sDirOfExecutable ) { - char dir[PATH_MAX]; - // /Save -> ~/Library/Preferences/PRODUCT_ID - PathForFolderType( dir, kPreferencesFolderType ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID, dir), "/Save" ); + std::string libraryDir = PathForDirectory(NSLibraryDirectory); + FILEMAN->Mount( "dir", libraryDir + "/Preferences/" PRODUCT_ID, "/Save" ); // Other stuff -> ~/Library/Application Support/PRODUCT_ID/* - PathForFolderType( dir, kApplicationSupportFolderType ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/Announcers", dir), "/Announcers" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/BGAnimations", dir), "/BGAnimations" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/BackgroundEffects", dir), "/BackgroundEffects" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/BackgroundTransitions", dir), "/BackgroundTransitions" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/CDTitles", dir), "/CDTitles" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/Characters", dir), "/Characters" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/Courses", dir), "/Courses" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/Downloads", dir), "/Downloads" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/NoteSkins", dir), "/NoteSkins" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/Packages", dir), "/Packages" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/Songs", dir), "/Songs" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/RandomMovies", dir), "/RandomMovies" ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID "/Themes", dir), "/Themes" ); + std::string appSupportDir = PathForDirectory(NSApplicationSupportDirectory); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/Announcers", "/Announcers" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/BGAnimations", "/BGAnimations" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/BackgroundEffects", "/BackgroundEffects" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/BackgroundTransitions", "/BackgroundTransitions" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/CDTitles", "/CDTitles" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/Characters", "/Characters" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/Courses", "/Courses" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/Downloads", "/Downloads" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/NoteSkins", "/NoteSkins" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/Packages", "/Packages" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/Songs", "/Songs" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/RandomMovies", "/RandomMovies" ); + FILEMAN->Mount( "dir", appSupportDir + "/" PRODUCT_ID "/Themes", "/Themes" ); // /Screenshots -> ~/Pictures/PRODUCT_ID Screenshots - PathForFolderType( dir, kPictureDocumentsFolderType ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID " Screenshots", dir), "/Screenshots" ); + std::string picturesDir = PathForDirectory(NSCachesDirectory); + FILEMAN->Mount( "dir", picturesDir + "/" PRODUCT_ID " Screenshots", "/Screenshots" ); // /Cache -> ~/Library/Caches/PRODUCT_ID - PathForFolderType( dir, kCachedDataFolderType ); - FILEMAN->Mount( "dir", ssprintf("%s/" PRODUCT_ID, dir), "/Cache" ); + std::string cachesDir = PathForDirectory(NSCachesDirectory); + FILEMAN->Mount( "dir", cachesDir + "/" PRODUCT_ID, "/Cache" ); // /Logs -> ~/Library/Logs/PRODUCT_ID - PathForFolderType( dir, kDomainLibraryFolderType ); - FILEMAN->Mount( "dir", ssprintf("%s/Logs/" PRODUCT_ID, dir), "/Logs" ); + FILEMAN->Mount( "dir", libraryDir + "/Logs/" PRODUCT_ID, "/Logs" ); } static inline int GetIntValue( CFTypeRef r ) @@ -423,16 +388,8 @@ static inline int GetIntValue( CFTypeRef r ) float ArchHooks_MacOSX::GetDisplayAspectRatio() { - io_connect_t displayPort = CGDisplayIOServicePort( CGMainDisplayID() ); - CFDictionaryRef dict = IODisplayCreateInfoDictionary( displayPort, 0 ); - int width = GetIntValue( CFDictionaryGetValue(dict, CFSTR(kDisplayHorizontalImageSize)) ); - int height = GetIntValue( CFDictionaryGetValue(dict, CFSTR(kDisplayVerticalImageSize)) ); - - CFRelease( dict ); - - if( width && height ) - return float(width)/height; - return 4/3.f; + NSScreen *screen = [NSScreen mainScreen]; + return screen.frame.size.width / screen.frame.size.height; } /* diff --git a/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp b/src/arch/InputHandler/InputHandler_MacOSX_HID.mm similarity index 97% rename from src/arch/InputHandler/InputHandler_MacOSX_HID.cpp rename to src/arch/InputHandler/InputHandler_MacOSX_HID.mm index 442c1450d0..56dc1f6c72 100644 --- a/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp +++ b/src/arch/InputHandler/InputHandler_MacOSX_HID.mm @@ -17,14 +17,13 @@ REGISTER_INPUT_HANDLER_CLASS2( HID, MacOSX_HID ); void InputHandler_MacOSX_HID::QueueCallback( void *target, int result, void *refcon, void *sender ) { // The result seems useless as you can't actually return anything... - // refcon is the Device number RageTimer now; InputHandler_MacOSX_HID *This = (InputHandler_MacOSX_HID *)target; IOHIDQueueInterface **queue = (IOHIDQueueInterface **)sender; IOHIDEventStruct event; AbsoluteTime zeroTime = { 0, 0 }; - HIDDevice *dev = This->m_vDevices[size_t( refcon )]; + HIDDevice *dev = static_cast(refcon); vector vPresses; while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess ) @@ -116,11 +115,9 @@ void InputHandler_MacOSX_HID::DeviceChanged( void *refCon, io_service_t service, // m_LoopRef needs to be set before this is called void InputHandler_MacOSX_HID::StartDevices() { - int n = 0; - ASSERT( m_LoopRef ); for (HIDDevice *i : m_vDevices) - i->StartQueue( m_LoopRef, InputHandler_MacOSX_HID::QueueCallback, this, n++ ); + i->StartQueue( m_LoopRef, InputHandler_MacOSX_HID::QueueCallback, this ); CFRunLoopSourceRef runLoopSource = IONotificationPortGetRunLoopSource( m_NotifyPort ); @@ -397,8 +394,10 @@ static wchar_t KeyCodeToChar(CGKeyCode keyCode, unsigned int modifierFlags) if( status != noErr ) { - fprintf(stderr, "There was an %s error translating from the '%d' key code to a human readable string: %s\n", - GetMacOSStatusErrorString(status), (int)status, GetMacOSStatusCommentString(status)); + NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil]; + const char* errorDescription = [error.localizedDescription UTF8String]; + fprintf(stderr, "There was an error translating from the '%d' key code to a human readable string: %s\n", + keyCode, errorDescription); } else if( actualStringLength == 0 ) { diff --git a/src/arch/LoadingWindow/LoadingWindow_MacOSX.mm b/src/arch/LoadingWindow/LoadingWindow_MacOSX.mm index 352bf86c4a..ec735f5c62 100644 --- a/src/arch/LoadingWindow/LoadingWindow_MacOSX.mm +++ b/src/arch/LoadingWindow/LoadingWindow_MacOSX.mm @@ -52,7 +52,7 @@ [m_Text setSelectable:NO]; [m_Text setDrawsBackground:NO]; [m_Text setBackgroundColor:[NSColor lightGrayColor]]; - [m_Text setAlignment:NSCenterTextAlignment]; + [m_Text setAlignment:NSTextAlignmentCenter]; [m_Text setHorizontallyResizable:NO]; [m_Text setVerticallyResizable:NO]; [m_Text setString:@"Initializing Hardware..."]; @@ -64,17 +64,15 @@ windowRect = NSMakeRect( 0, 0, size.width, size.height + height + progressHeight + padding); m_Window = [[NSWindow alloc] initWithContentRect:windowRect - styleMask:NSTitledWindowMask + styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES]; NSView *view = [m_Window contentView]; // Set some properties. - [m_Window setOneShot:YES]; [m_Window setReleasedWhenClosed:YES]; [m_Window setExcludedFromWindowsMenu:YES]; - [m_Window useOptimizedDrawing:YES]; [m_Window setTitle:@PRODUCT_FAMILY]; [m_Window center]; diff --git a/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.mm b/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.mm index e871612d0b..f7e2dee4ff 100644 --- a/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.mm +++ b/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.mm @@ -17,8 +17,8 @@ extern "C" { } -static const unsigned int g_iStyleMask = NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask | NSResizableWindowMask; +static const unsigned int g_iStyleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | + NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; static bool g_bResized; static int g_iWidth; static int g_iHeight; @@ -94,7 +94,6 @@ public: defer:YES]; [m_Window setExcludedFromWindowsMenu:YES]; - [m_Window useOptimizedDrawing:YES]; [m_Window setReleasedWhenClosed:NO]; [m_Window setDelegate:static_cast >(self)]; } diff --git a/src/arch/Sound/RageSoundDriver_AU.cpp b/src/arch/Sound/RageSoundDriver_AU.mm similarity index 85% rename from src/arch/Sound/RageSoundDriver_AU.cpp rename to src/arch/Sound/RageSoundDriver_AU.mm index 665f77a5c1..51c1154091 100644 --- a/src/arch/Sound/RageSoundDriver_AU.cpp +++ b/src/arch/Sound/RageSoundDriver_AU.mm @@ -16,28 +16,10 @@ static const UInt32 kBytesPerPacket = kChannelsPerFrame * kBitsPerChannel / 8; static const UInt32 kBytesPerFrame = kBytesPerPacket; static const UInt32 kFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsFloat; -#define WERROR(str, num, extra...) str ": '%s' (%lu).", ## extra, FourCCToString(num).c_str(), (num) -#define ERROR(str, num, extra...) (ssprintf(WERROR(str, (num), ## extra))) - -static inline RString FourCCToString( uint32_t num ) +static const char *FormatOSError(OSStatus status) { - RString s( 4, '?' ); - char c; - - c = (num >> 24) & 0xFF; - if( c >='\x20' && c <= '\x7e' ) - s[0] = c; - c = (num >> 16) & 0xFF; - if( c >='\x20' && c <= '\x7e' ) - s[1] = c; - c = (num >> 8) & 0xFF; - if( c >='\x20' && c <= '\x7e' ) - s[2] = c; - c = num & 0xFF; - if( c >= '\x20' && c <= '\x7e' ) - s[3] = c; - - return s; + NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil]; + return [error.localizedDescription UTF8String]; } RageSoundDriver_AU::RageSoundDriver_AU() : m_OutputUnit(nullptr), m_iSampleRate(0), m_bDone(false), m_bStarted(false), @@ -54,7 +36,7 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate ) if( (error = AudioUnitGetProperty(au, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &OutputDevice, &size)) ) { - LOG->Warn( WERROR("No output device", error) ); + LOG->Warn("No output device: %s", FormatOSError(error)); return; } @@ -68,7 +50,7 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate ) size = sizeof( Float64 ); if( (error = AudioObjectGetPropertyData(OutputDevice, &RateAddr, 0, NULL, &size, &rate)) ) { - LOG->Warn( WERROR("Couldn't get the device's sample rate", error) ); + LOG->Warn("Couldn't get the device's sample rate: %s", FormatOSError(error)); return; } if( rate == desiredRate ) @@ -82,7 +64,7 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate ) if( (error = AudioObjectGetPropertyData(OutputDevice, &AvailableRatesAddr, 0, nullptr, &size, nullptr)) ) { - LOG->Warn( WERROR("Couldn't get available nominal sample rates info", error) ); + LOG->Warn("Couldn't get available nominal sample rates info: %s", FormatOSError(error)); return; } @@ -91,7 +73,7 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate ) if( (error = AudioObjectGetPropertyData(OutputDevice, &AvailableRatesAddr, 0, NULL, &size, ranges)) ) { - LOG->Warn( WERROR("Couldn't get available nominal sample rates", error) ); + LOG->Warn("Couldn't get available nominal sample rates: %s", FormatOSError(error)); delete[] ranges; return; } @@ -115,7 +97,7 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate ) if( (error = AudioObjectSetPropertyData(OutputDevice, &RateAddr, 0, nullptr, sizeof(Float64), &bestRate)) ) { - LOG->Warn( WERROR("Couldn't set the device's sample rate", error) ); + LOG->Warn("Couldn't set the device's sample rate: %s", FormatOSError(error)); } } @@ -138,7 +120,7 @@ RString RageSoundDriver_AU::Init() OSStatus error = AudioComponentInstanceNew( comp, &m_OutputUnit ); if( error != noErr || m_OutputUnit == nullptr ) - return ERROR( "Could not open the default output unit", error ); + return ssprintf("Could not open the default output unit: %s", FormatOSError(error)); // Set up a callback function to generate output to the output unit AURenderCallbackStruct input; @@ -152,7 +134,7 @@ RString RageSoundDriver_AU::Init() &input, sizeof(input) ); if( error != noErr ) - return ERROR( "Failed to set render callback", error ); + return ssprintf("Failed to set render callback: %s", FormatOSError(error)); AudioStreamBasicDescription streamFormat; @@ -181,7 +163,7 @@ RString RageSoundDriver_AU::Init() &streamFormat, sizeof(AudioStreamBasicDescription) ); if( error != noErr ) - return ERROR( "Failed to set AU stream format", error ); + return ssprintf("Failed to set AU stream format: %s", FormatOSError(error)); UInt32 renderQuality = kRenderQuality_Max; error = AudioUnitSetProperty( m_OutputUnit, @@ -191,16 +173,16 @@ RString RageSoundDriver_AU::Init() &renderQuality, sizeof(renderQuality) ); if( error != noErr ) - LOG->Warn( WERROR("Failed to set the maximum render quality", error) ); + LOG->Warn("Failed to set the maximum render quality: %s", FormatOSError(error)); // Initialize the AU. if( (error = AudioUnitInitialize(m_OutputUnit)) ) - return ERROR( "Could not initialize the AudioUnit", error ); + return ssprintf("Could not initialize the AudioUnit: %s", FormatOSError(error)); StartDecodeThread(); if( (error = AudioOutputUnitStart(m_OutputUnit)) ) - return ERROR( "Could not start the AudioUnit", error ); + return ssprintf("Could not start the AudioUnit: %s", FormatOSError(error)); m_bStarted = true; return RString(); } @@ -215,7 +197,7 @@ RageSoundDriver_AU::~RageSoundDriver_AU() m_Semaphore.Wait(); } AudioUnitUninitialize( m_OutputUnit ); - CloseComponent( m_OutputUnit ); + AudioComponentInstanceDispose( m_OutputUnit ); delete m_pIOThread; delete m_pNotificationThread; } @@ -245,7 +227,7 @@ float RageSoundDriver_AU::GetPlayLatency() const if( (error = AudioUnitGetProperty(m_OutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &OutputDevice, &size)) ) { - LOG->Warn( WERROR("No output device", error) ); + LOG->Warn("No output device: %s", FormatOSError(error)); return 0.0f; } @@ -258,7 +240,7 @@ float RageSoundDriver_AU::GetPlayLatency() const size = sizeof( Float64 ); if( (error = AudioObjectGetPropertyData(OutputDevice, &RateAddr, 0, nullptr, &size, &sampleRate)) ) { - LOG->Warn( WERROR("Couldn't get the device sample rate", error) ); + LOG->Warn("Couldn't get the device sample rate: %s", FormatOSError(error)); return 0.0f; } @@ -271,7 +253,7 @@ float RageSoundDriver_AU::GetPlayLatency() const size = sizeof( UInt32 ); if( (error = AudioObjectGetPropertyData(OutputDevice, &BufferAddr, 0, nullptr, &size, &bufferSize)) ) { - LOG->Warn( WERROR("Couldn't determine buffer size", error) ); + LOG->Warn("Couldn't determine buffer size: %s", FormatOSError(error)); bufferSize = 0; } @@ -286,7 +268,7 @@ float RageSoundDriver_AU::GetPlayLatency() const size = sizeof( UInt32 ); if( (error = AudioObjectGetPropertyData(OutputDevice, &LatencyAddr, 0, nullptr, &size, &frames)) ) { - LOG->Warn( WERROR( "Couldn't get device latency", error) ); + LOG->Warn("Couldn't get device latency: %s", FormatOSError(error)); frames = 0; } @@ -300,7 +282,7 @@ float RageSoundDriver_AU::GetPlayLatency() const size = sizeof( UInt32 ); if( (error = AudioObjectGetPropertyData(OutputDevice, &SafetyAddr, 0, nullptr, &size, &frames)) ) { - LOG->Warn( WERROR("Couldn't get device safety offset", error) ); + LOG->Warn("Couldn't get device safety offset: %s", FormatOSError(error)); frames = 0; } bufferSize += frames; @@ -315,7 +297,7 @@ float RageSoundDriver_AU::GetPlayLatency() const if( (error = AudioObjectGetPropertyData(OutputDevice, &StreamsAddr, 0, nullptr, &size, nullptr)) ) { - LOG->Warn( WERROR("Device has no streams", error) ); + LOG->Warn("Device has no streams: %s", FormatOSError(error)); break; } int num = size / sizeof( AudioStreamID ); @@ -328,7 +310,7 @@ float RageSoundDriver_AU::GetPlayLatency() const if( (error = AudioObjectGetPropertyData(OutputDevice, &StreamsAddr, 0, nullptr, &size, streams)) ) { - LOG->Warn( WERROR("Cannot get device's streams", error) ); + LOG->Warn("Cannot get device's streams: %s", FormatOSError(error)); delete[] streams; break; } @@ -341,7 +323,7 @@ float RageSoundDriver_AU::GetPlayLatency() const if( (error = AudioObjectGetPropertyData(streams[0], &LatencyAddr, 0, nullptr, &size, &frames)) ) { - LOG->Warn( WERROR("Stream does not report latency", error) ); + LOG->Warn("Stream does not report latency: %s", FormatOSError(error)); frames = 0; } delete[] streams; diff --git a/src/archutils/Darwin/Crash.cpp b/src/archutils/Darwin/Crash.mm similarity index 93% rename from src/archutils/Darwin/Crash.cpp rename to src/archutils/Darwin/Crash.mm index a8ba3a04bc..31e3ddd307 100644 --- a/src/archutils/Darwin/Crash.cpp +++ b/src/archutils/Darwin/Crash.mm @@ -10,17 +10,16 @@ #endif #include +#import + RString CrashHandler::GetLogsDirectory() { - FSRef fs; - char dir[PATH_MAX]; - - if( FSFindFolder(kUserDomain, kDomainLibraryFolderType, kDontCreateFolder, &fs) || - FSRefMakePath(&fs, (UInt8 *)dir, PATH_MAX) ) - { + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSURL *url = [fileManager URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; + if (url == nil) return "/tmp"; - } - return RString( dir ) + "/Logs/" PRODUCT_ID; + + return RString([url fileSystemRepresentation]) + "/Logs/" PRODUCT_ID; } // XXX Can we use LocalizedString here instead? diff --git a/src/archutils/Darwin/HIDDevice.cpp b/src/archutils/Darwin/HIDDevice.cpp index a3629d86ca..30f3e4be77 100644 --- a/src/archutils/Darwin/HIDDevice.cpp +++ b/src/archutils/Darwin/HIDDevice.cpp @@ -144,7 +144,7 @@ bool HIDDevice::Open( io_object_t device ) return true; } -void HIDDevice::StartQueue( CFRunLoopRef loopRef, IOHIDCallbackFunction callback, void *target, int refCon ) +void HIDDevice::StartQueue( CFRunLoopRef loopRef, IOHIDCallbackFunction callback, void *target ) { CFRunLoopSourceRef runLoopSource; // This creates a run loop source. It is released in the dtor. @@ -159,7 +159,7 @@ void HIDDevice::StartQueue( CFRunLoopRef loopRef, IOHIDCallbackFunction callback if( !CFRunLoopContainsSource(loopRef, runLoopSource, kCFRunLoopDefaultMode) ) CFRunLoopAddSource( loopRef, runLoopSource, kCFRunLoopDefaultMode ); - ret = CALL( m_Queue, setEventCallout, callback, target, (void *)refCon ); + ret = CALL( m_Queue, setEventCallout, callback, target, this ); if( ret != kIOReturnSuccess ) { diff --git a/src/archutils/Darwin/HIDDevice.h b/src/archutils/Darwin/HIDDevice.h index da97ca4a0e..52d4c1de95 100644 --- a/src/archutils/Darwin/HIDDevice.h +++ b/src/archutils/Darwin/HIDDevice.h @@ -95,7 +95,7 @@ protected: { IOReturn ret = CALL( m_Queue, addElement, cookie, 0 ); if( ret != KERN_SUCCESS ) - LOG->Warn( "Failed to add HID element with cookie %p to queue: %u", cookie, ret ); + LOG->Warn( "Failed to add HID element with cookie %u to queue: %u", cookie, ret ); } // Perform a synchronous set report on the HID interface. @@ -108,7 +108,7 @@ public: virtual ~HIDDevice(); bool Open( io_object_t device ); - void StartQueue( CFRunLoopRef loopRef, IOHIDCallbackFunction callback, void *target, int refCon ); + void StartQueue( CFRunLoopRef loopRef, IOHIDCallbackFunction callback, void *target ); inline const RString& GetDescription() const { return m_sDescription; } /* Add button presses (or releases) to vPresses for the given cookie. More diff --git a/src/archutils/Darwin/PreferredLanguage.m b/src/archutils/Darwin/PreferredLanguage.m index bdd8e8f266..1bb894797b 100644 --- a/src/archutils/Darwin/PreferredLanguage.m +++ b/src/archutils/Darwin/PreferredLanguage.m @@ -2,7 +2,7 @@ char *GetPreferredLanguage() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSUserDefaults *def = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [def objectForKey:@"AppleLanguages"]; + NSArray *languages = def[@"AppleLanguages"]; const char *lang = [[languages objectAtIndex:0] UTF8String]; char *ret = (char *)malloc( strlen(lang) + 1 ); diff --git a/src/archutils/Darwin/SMMain.mm b/src/archutils/Darwin/SMMain.mm index 9bb44b9b37..f26ac2316f 100644 --- a/src/archutils/Darwin/SMMain.mm +++ b/src/archutils/Darwin/SMMain.mm @@ -30,7 +30,7 @@ - (void)sendEvent:(NSEvent *)event { - if( [event type] == NSKeyDown ) + if( [event type] == NSEventTypeKeyDown ) [[self mainMenu] performKeyEquivalent:event]; else [super sendEvent:event]; @@ -172,7 +172,7 @@ static void SetupMenus( void ) NSMenu *windowMenu = [[[NSMenu alloc] initWithTitle:sWindow] autorelease]; NSMenuItem *hideOthers = MenuItem( sHideOthers, @selector(hideOtherApplications:), @"h" ); - [hideOthers setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask ]; + [hideOthers setKeyEquivalentModifierMask:NSEventModifierFlagOption | NSEventModifierFlagCommand ]; [appMenu addItem:MenuItem( sAbout, @selector(orderFrontStandardAboutPanel:), @"" )]; [appMenu addItem:[NSMenuItem separatorItem]]; @@ -188,7 +188,7 @@ static void SetupMenus( void ) // Add a Full Screen item. NSMenuItem *item = MenuItem( sEnterFullScreen, @selector(fullscreen:), @"\n" ); - [item setKeyEquivalentModifierMask:NSAlternateKeyMask]; // opt-enter + [item setKeyEquivalentModifierMask:NSEventModifierFlagOption]; // opt-enter [windowMenu addItem:item]; [[mainMenu addItemWithTitle:[appMenu title] action:nil keyEquivalent:@""] setSubmenu:appMenu]; diff --git a/src/archutils/Darwin/SpecialDirs.cpp b/src/archutils/Darwin/SpecialDirs.mm similarity index 73% rename from src/archutils/Darwin/SpecialDirs.cpp rename to src/archutils/Darwin/SpecialDirs.mm index 61705ff04f..f013747cac 100644 --- a/src/archutils/Darwin/SpecialDirs.cpp +++ b/src/archutils/Darwin/SpecialDirs.mm @@ -1,25 +1,17 @@ #include "global.h" #include "SpecialDirs.h" #include "ProductInfo.h" -#include -#include -#include "RageUtil.h" -static void PathForFolderType( char dir[PATH_MAX], OSType folderType ) -{ - FSRef fs; - - if( FSFindFolder(kUserDomain, folderType, kDontCreateFolder, &fs) ) - FAIL_M( ssprintf("FSFindFolder(%lu) failed.", folderType) ); - if( FSRefMakePath(&fs, (UInt8 *)dir, PATH_MAX) ) - FAIL_M( "FSRefMakePath() failed." ); -} +#import RString SpecialDirs::GetDesktopDir() { - char dir[PATH_MAX]; - PathForFolderType( dir, kDesktopFolderType ); - return RString( ssprintf("%s/" PRODUCT_ID, dir) ); + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSURL *url = [fileManager URLForDirectory:NSDesktopDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; + if (url == nil) + return "/tmp"; + + return RString([url fileSystemRepresentation]) + "/" PRODUCT_ID; }