Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/rosetta detection #57

Merged
merged 4 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions XIV on Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,26 @@ import AppMover
}

func checkForRosetta() {
#if arch(arm64)
// No need to do any of this on Intel.
if (!Util.rosettaIsInstalled())
{
let alert: NSAlert = NSAlert()
alert.messageText = NSLocalizedString("ROSETTA_REQUIRED", comment: "")
alert.informativeText = NSLocalizedString("ROSETTA_REQUIRED_INFORMATIVE", comment: "")
alert.alertStyle = .warning
alert.addButton(withTitle:NSLocalizedString("ROSETTA_REQUIRED_INSTALL_BUTTON", comment: ""))
alert.addButton(withTitle:NSLocalizedString("ROSETTA_REQUIRED_CANCEL_BUTTON", comment: ""))
let result = alert.runModal()
if result == .alertFirstButtonReturn {
let rosettaCommand = Bundle.main.url(forResource: "installRosetta", withExtension: "command")
if (rosettaCommand != nil) {
// We could launch Terminal directly, but this should work more nicely for people who use 3rd party
// terminal apps.
Util.launch(exec: URL(fileURLWithPath: "/usr/bin/open"), args: [rosettaCommand!.path])
if (Util.getXOMRuntimeEnvironment() == .appleSiliconNative) { // No need to do any of this on Intel, and if we're already in Rosetta the answer is self-evident
if (!Util.rosettaIsInstalled())
{
let alert: NSAlert = NSAlert()
alert.messageText = NSLocalizedString("ROSETTA_REQUIRED", comment: "")
alert.informativeText = NSLocalizedString("ROSETTA_REQUIRED_INFORMATIVE", comment: "")
alert.alertStyle = .warning
alert.addButton(withTitle:NSLocalizedString("ROSETTA_REQUIRED_INSTALL_BUTTON", comment: ""))
alert.addButton(withTitle:NSLocalizedString("ROSETTA_REQUIRED_CANCEL_BUTTON", comment: ""))
let result = alert.runModal()
if result == .alertFirstButtonReturn {
let rosettaCommand = Bundle.main.url(forResource: "installRosetta", withExtension: "command")
if (rosettaCommand != nil) {
// We could launch Terminal directly, but this should work more nicely for people who use 3rd party
// terminal apps.
Util.launch(exec: URL(fileURLWithPath: "/usr/bin/open"), args: [rosettaCommand!.path])
}
}
}
}
#endif
}

func checkGPUSupported() {
Expand Down
18 changes: 9 additions & 9 deletions XIV on Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1466,14 +1466,14 @@ Gw
</textFieldCell>
</textField>
<slider wantsLayer="YES" horizontalHuggingPriority="249" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Bvv-yo-MZ0">
<rect key="frame" x="63" y="190" width="423" height="28"/>
<rect key="frame" x="63" y="190" width="424" height="28"/>
<sliderCell key="cell" state="on" alignment="left" maxValue="4" doubleValue="1" tickMarkPosition="above" numberOfTickMarks="5" sliderType="linear" id="Ya9-RG-5gd"/>
<connections>
<action selector="saveState:" target="iZP-JQ-P1x" id="aC0-gT-XAQ"/>
</connections>
</slider>
<button wantsLayer="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="c5y-dB-OzW">
<rect key="frame" x="485" y="189" width="70" height="32"/>
<rect key="frame" x="486" y="189" width="69" height="32"/>
<buttonCell key="cell" type="push" title="Reset" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="BHo-QR-6f8">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -1583,7 +1583,7 @@ Gw
</connections>
</button>
<button wantsLayer="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gvh-xg-ZgM">
<rect key="frame" x="330" y="59" width="92" height="32"/>
<rect key="frame" x="330" y="59" width="91" height="32"/>
<buttonCell key="cell" type="push" title="Select All" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="fgq-sv-nxT">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -1823,7 +1823,7 @@ Gw
</connections>
</textField>
<button wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fhv-Eb-PmW">
<rect key="frame" x="679" y="200" width="127" height="21"/>
<rect key="frame" x="679" y="199.5" width="127" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Auto-Login" bezelStyle="regularSquare" imagePosition="left" controlSize="large" inset="2" id="J8n-OX-VtC">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -1834,7 +1834,7 @@ Gw
</connections>
</button>
<button wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xhX-md-4MR">
<rect key="frame" x="819" y="200" width="127" height="21"/>
<rect key="frame" x="819" y="199.5" width="127" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Auto-OTP" bezelStyle="regularSquare" imagePosition="left" controlSize="large" inset="2" id="hjS-RC-X85">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand Down Expand Up @@ -1949,7 +1949,7 @@ Gw
</scroller>
</scrollView>
<button wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="R5T-I0-Kje" userLabel="Disclose Button">
<rect key="frame" x="922" y="358" width="26" height="24"/>
<rect key="frame" x="922" y="358" width="25.5" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="bevel" bezelStyle="rounded" image="NSTouchBarGoDownTemplate" imagePosition="only" alignment="center" refusesFirstResponder="YES" state="on" inset="2" id="gCP-mx-jfr">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -2016,7 +2016,7 @@ Gw
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" imageFrameStyle="groove" image="SecPrefpane" id="t0R-au-2Uj"/>
</imageView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="d38-by-aiQ">
<rect key="frame" x="622" y="83" width="198" height="32"/>
<rect key="frame" x="622" y="83" width="197" height="32"/>
<buttonCell key="cell" type="push" title="Open Security Preferences" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="bE2-RL-ucx">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -2372,7 +2372,7 @@ Gw
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vi7-zh-Dkz">
<rect key="frame" x="33" y="601" width="156" height="32"/>
<rect key="frame" x="33" y="601" width="155" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="jSD-bX-Lap"/>
</constraints>
Expand Down Expand Up @@ -2818,7 +2818,7 @@ https://github.com/goatcorp/Dalamud</string>
<resources>
<image name="CfgCheckGood" width="96" height="96"/>
<image name="CfgCheckProbFailed" width="96" height="96"/>
<image name="NSTouchBarGoDownTemplate" width="16" height="9"/>
<image name="NSTouchBarGoDownTemplate" width="15" height="9"/>
<image name="PrefsGeneral" width="96" height="96"/>
<image name="PrefsGraphics" width="150.75" height="96"/>
<image name="SecPrefpane" width="517.5" height="261"/>
Expand Down
11 changes: 6 additions & 5 deletions XIV on Mac/FirstAid/FirstAidController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ class FirstAidController: NSViewController, NSTableViewDelegate, NSTableViewData

func cfgCheckConditions() -> [FFXIVCfgCheckCondition] {
var allConditions: [FFXIVCfgCheckCondition] = FFXIVCheckupConditions
#if arch(arm64)
allConditions = allConditions + FFXIVCheckupConditions_AS
#else
allConditions = allConditions + FFXIVCheckupConditions_X64
#endif
if (Util.getXOMRuntimeEnvironment() != .x64Native) {
allConditions = allConditions + FFXIVCheckupConditions_AS
}
else {
allConditions = allConditions + FFXIVCheckupConditions_X64
}
return allConditions
}

Expand Down
100 changes: 66 additions & 34 deletions XIV on Mac/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ struct Util {
}

static func rosettaIsInstalled() -> Bool {
#if arch(arm64)
// Rosetta's package ID is fixed, so it's safer to check for its receipt than to look for any individual file it's known to install.
let rosettaReceiptPath = appleReceiptsPath.appendingPathComponent("com.apple.pkg.RosettaUpdateAuto.plist");
do{
let receiptExists : Bool = try rosettaReceiptPath.checkResourceIsReachable()
return receiptExists
}catch{
if (Util.getXOMRuntimeEnvironment() == .appleSiliconNative) {
// Rosetta's package ID is fixed, so it's safer to check for its receipt than to look for any individual file it's known to install.
let rosettaReceiptPath = appleReceiptsPath.appendingPathComponent("com.apple.pkg.RosettaUpdateAuto.plist");
do{
let receiptExists : Bool = try rosettaReceiptPath.checkResourceIsReachable()
return receiptExists
}catch{
}
}
#endif
return false
}

Expand Down Expand Up @@ -248,40 +248,72 @@ struct Util {
return configFileContents
}

static func supportedGPU() -> Bool {
var foundSupportedGPU : Bool = false
public enum XOMRuntimeEnvironment: UInt32 {
case x64Native = 0
case appleSiliconRosetta = 1
case appleSiliconNative = 2
}

static func getXOMRuntimeEnvironment() -> XOMRuntimeEnvironment {
#if arch(arm64)
// On Apple Silicon to date, there is always a built-in GPU, and it is always supported. So we don't need to check anything.
foundSupportedGPU = true
return .appleSiliconNative
#else
// On Intel, we need to find an AMD GPU. Intel iGPUs are not supported, and neither is nVidia or other oddities (USB video).
var deviceIterator : io_iterator_t = io_iterator_t()

if IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(kIOAcceleratorClassName),&deviceIterator) == kIOReturnSuccess {
var entry : io_registry_entry_t = IOIteratorNext(deviceIterator)
while (entry != 0) && (!foundSupportedGPU) {
var properties : Unmanaged<CFMutableDictionary>? = nil
if IORegistryEntryCreateCFProperties(entry, &properties, kCFAllocatorDefault, 0) == kIOReturnSuccess {
guard let propertiesDict = properties?.takeUnretainedValue() as? [String : AnyObject] else { continue }
properties?.release()

let ioClass = propertiesDict["IOClass"]
if ioClass is String {
let ioClassString = ioClass as! String
if ioClassString.hasPrefix("AMDRadeon") {
foundSupportedGPU = true
let key = "sysctl.proc_translated"
var ret = Int32(0)
var size: Int = 0
sysctlbyname(key, nil, &size, nil, 0)
let result = sysctlbyname(key, &ret, &size, nil, 0)
if result == -1 {
if errno == ENOENT {
// Native process
return .x64Native
}
// An error occured... Assume native?
print("Error determining execution environment", to: &logger)
return .x64Native
}
if (ret == 1) {
return .appleSiliconRosetta
}
return .x64Native
#endif
}

static func supportedGPU() -> Bool {
var foundSupportedGPU : Bool = false
if (Util.getXOMRuntimeEnvironment() != .x64Native) {
// On Apple Silicon to date, there is always a built-in GPU, and it is always supported. So we don't need to check anything.
foundSupportedGPU = true
}
else
{
// On Intel, we need to find an AMD GPU. Intel iGPUs are not supported, and neither is nVidia or other oddities (USB video).
var deviceIterator : io_iterator_t = io_iterator_t()

if IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(kIOAcceleratorClassName),&deviceIterator) == kIOReturnSuccess {
var entry : io_registry_entry_t = IOIteratorNext(deviceIterator)
while (entry != 0) && (!foundSupportedGPU) {
var properties : Unmanaged<CFMutableDictionary>? = nil
if IORegistryEntryCreateCFProperties(entry, &properties, kCFAllocatorDefault, 0) == kIOReturnSuccess {
guard let propertiesDict = properties?.takeUnretainedValue() as? [String : AnyObject] else { continue }
properties?.release()

let ioClass = propertiesDict["IOClass"]
if ioClass is String {
let ioClassString = ioClass as! String
if ioClassString.hasPrefix("AMDRadeon") {
foundSupportedGPU = true
}
}
}

IOObjectRelease(entry)
entry = IOIteratorNext(deviceIterator)
}

IOObjectRelease(entry)
entry = IOIteratorNext(deviceIterator)
IOObjectRelease(deviceIterator)
}

IOObjectRelease(deviceIterator)
}

#endif
return foundSupportedGPU
}

Expand Down