mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-08 22:33:26 +01:00
[Settings]: Fix: DisableAppLimit switch reverting back to off state even if on iOS where sparseRestore is not patched yet
This commit is contained in:
96
AltStoreCore/Extensions/ProcessInfo+AltStore.swift
Normal file
96
AltStoreCore/Extensions/ProcessInfo+AltStore.swift
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// ProcessInfo+SideStore.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by ny on 10/23/24.
|
||||
// Copyright © 2024 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
fileprivate struct BuildVersion: Comparable {
|
||||
let prefix: String
|
||||
let numericPart: Int
|
||||
let suffix: Character?
|
||||
|
||||
init?(_ buildString: String) {
|
||||
// Initialize indices
|
||||
var index = buildString.startIndex
|
||||
|
||||
// Extract prefix (letters before the numeric part)
|
||||
while index < buildString.endIndex, !buildString[index].isNumber {
|
||||
index = buildString.index(after: index)
|
||||
}
|
||||
guard index > buildString.startIndex else { return nil }
|
||||
self.prefix = String(buildString[buildString.startIndex..<index])
|
||||
|
||||
// Extract numeric part
|
||||
let startOfNumeric = index
|
||||
while index < buildString.endIndex, buildString[index].isNumber {
|
||||
index = buildString.index(after: index)
|
||||
}
|
||||
guard let numericValue = Int(buildString[startOfNumeric..<index]) else { return nil }
|
||||
self.numericPart = numericValue
|
||||
|
||||
// Extract suffix (if any)
|
||||
if index < buildString.endIndex {
|
||||
self.suffix = buildString[index]
|
||||
} else {
|
||||
self.suffix = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Implement Comparable protocol
|
||||
static func < (lhs: BuildVersion, rhs: BuildVersion) -> Bool {
|
||||
// Compare prefixes
|
||||
if lhs.prefix != rhs.prefix {
|
||||
return lhs.prefix < rhs.prefix
|
||||
}
|
||||
// Compare numeric parts
|
||||
if lhs.numericPart != rhs.numericPart {
|
||||
return lhs.numericPart < rhs.numericPart
|
||||
}
|
||||
// Compare suffixes
|
||||
switch (lhs.suffix, rhs.suffix) {
|
||||
case let (l?, r?):
|
||||
return l < r
|
||||
case (nil, _?):
|
||||
return true // nil is considered less than any character
|
||||
case (_?, nil):
|
||||
return false
|
||||
default:
|
||||
return false // Both are nil and equal
|
||||
}
|
||||
}
|
||||
|
||||
static func == (lhs: BuildVersion, rhs: BuildVersion) -> Bool {
|
||||
return lhs.prefix == rhs.prefix &&
|
||||
lhs.numericPart == rhs.numericPart &&
|
||||
lhs.suffix == rhs.suffix
|
||||
}
|
||||
}
|
||||
|
||||
extension ProcessInfo {
|
||||
public var shortVersion: String {
|
||||
operatingSystemVersionString
|
||||
.replacingOccurrences(of: "Version ", with: "")
|
||||
.replacingOccurrences(of: "Build ", with: "")
|
||||
}
|
||||
|
||||
public var operatingSystemBuild: String {
|
||||
if let start = shortVersion.range(of: "(")?.upperBound,
|
||||
let end = shortVersion.range(of: ")")?.lowerBound {
|
||||
shortVersion[start..<end].replacingOccurrences(of: "Build ", with: "")
|
||||
} else { "???" }
|
||||
}
|
||||
|
||||
public var sparseRestorePatched: Bool {
|
||||
if operatingSystemVersion < OperatingSystemVersion(majorVersion: 18, minorVersion: 1, patchVersion: 0) { false }
|
||||
else if operatingSystemVersion > OperatingSystemVersion(majorVersion: 18, minorVersion: 1, patchVersion: 1) { true }
|
||||
else if operatingSystemVersion >= OperatingSystemVersion(majorVersion: 18, minorVersion: 1, patchVersion: 0),
|
||||
let currentBuild = BuildVersion(operatingSystemBuild),
|
||||
let targetBuild = BuildVersion("22B5054e") {
|
||||
currentBuild >= targetBuild
|
||||
} else { false }
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,8 @@ public extension UserDefaults
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
UserDefaults.shared.register(defaults: defaults)
|
||||
|
||||
if !isMacDirtyCowSupported
|
||||
// MDC is unsupported and spareRestore is patched
|
||||
if !isMacDirtyCowSupported && ProcessInfo().sparseRestorePatched
|
||||
{
|
||||
// Disable isAppLimitDisabled if running iOS version that doesn't support MacDirtyCow.
|
||||
UserDefaults.standard.isAppLimitDisabled = false
|
||||
|
||||
Reference in New Issue
Block a user