mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-13 08:43:27 +01:00
[AltServer] Fetches anisette data without Mail plug-in
Works on all macOS versions supported by AltServer.
This commit is contained in:
51
AltServer/Anisette Data/AnisetteError.swift
Normal file
51
AltServer/Anisette Data/AnisetteError.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// AnisetteError.swift
|
||||
// AltServer
|
||||
//
|
||||
// Created by Riley Testut on 9/13/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension AnisetteError
|
||||
{
|
||||
enum Code: Int, ALTErrorCode
|
||||
{
|
||||
typealias Error = AnisetteError
|
||||
|
||||
case aosKitFailure
|
||||
case missingValue
|
||||
}
|
||||
|
||||
static func aosKitFailure(file: String = #fileID, line: UInt = #line) -> AnisetteError {
|
||||
AnisetteError(code: .aosKitFailure, sourceFile: file, sourceLine: line)
|
||||
}
|
||||
|
||||
static func missingValue(_ value: String?, file: String = #fileID, line: UInt = #line) -> AnisetteError {
|
||||
AnisetteError(code: .missingValue, value: value, sourceFile: file, sourceLine: line)
|
||||
}
|
||||
}
|
||||
|
||||
struct AnisetteError: ALTLocalizedError
|
||||
{
|
||||
var code: Code
|
||||
var errorTitle: String?
|
||||
var errorFailure: String?
|
||||
|
||||
@UserInfoValue
|
||||
var value: String?
|
||||
|
||||
var sourceFile: String?
|
||||
var sourceLine: UInt?
|
||||
|
||||
var errorFailureReason: String {
|
||||
switch self.code
|
||||
{
|
||||
case .aosKitFailure: return NSLocalizedString("AltServer could not retrieve anisette data from AOSKit.", comment: "")
|
||||
case .missingValue:
|
||||
let valueName = self.value.map { "anisette data value “\($0)”" } ?? NSLocalizedString("anisette data values.", comment: "")
|
||||
return String(format: NSLocalizedString("AltServer could not retrieve %@.", comment: ""), valueName)
|
||||
}
|
||||
}
|
||||
}
|
||||
54
AltServer/Extensions/ProcessInfo+Device.swift
Normal file
54
AltServer/Extensions/ProcessInfo+Device.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// ProcessInfo+Device.swift
|
||||
// AltServer
|
||||
//
|
||||
// Created by Riley Testut on 9/13/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RegexBuilder
|
||||
|
||||
extension ProcessInfo
|
||||
{
|
||||
var deviceModel: String? {
|
||||
let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))
|
||||
defer {
|
||||
IOObjectRelease(service)
|
||||
}
|
||||
|
||||
guard
|
||||
let modelData = IORegistryEntryCreateCFProperty(service, "model" as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? Data,
|
||||
let cDeviceModel = String(data: modelData, encoding: .utf8)?.cString(using: .utf8) // Remove trailing NULL character
|
||||
else { return nil }
|
||||
|
||||
let deviceModel = String(cString: cDeviceModel)
|
||||
return deviceModel
|
||||
}
|
||||
|
||||
var operatingSystemBuildVersion: String? {
|
||||
let osVersionString = ProcessInfo.processInfo.operatingSystemVersionString
|
||||
let buildVersion: String?
|
||||
|
||||
if #available(macOS 13, *), let match = osVersionString.firstMatch(of: Regex {
|
||||
"(Build "
|
||||
Capture {
|
||||
OneOrMore(.anyNonNewline)
|
||||
}
|
||||
")"
|
||||
})
|
||||
{
|
||||
buildVersion = String(match.1)
|
||||
}
|
||||
else if let build = osVersionString.split(separator: " ").last?.dropLast()
|
||||
{
|
||||
buildVersion = String(build)
|
||||
}
|
||||
else
|
||||
{
|
||||
buildVersion = nil
|
||||
}
|
||||
|
||||
return buildVersion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user