GBA001/Delta/Extensions/Bundle+SwizzleBundleID.swift
Riley Testut ebf3fc6c27 Adds support for building Delta Lite (and Delta Lite beta)
Limits Delta Lite to NES games, and Delta Lite beta to NES and GBC games.
2019-09-15 18:57:15 -07:00

57 lines
1.6 KiB
Swift

//
// Bundle+SwizzleBundleID.swift
// Delta
//
// Created by Riley Testut on 8/7/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import Foundation
import ObjectiveC.runtime
extension Bundle
{
@objc private var swizzled_infoDictionary: [String : Any]? {
var infoDictionary = self.swizzled_infoDictionary
#if LITE
#if BETA
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.Lite.Beta"
#else
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.Lite"
#endif
#else
#if BETA
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.AltStore.Beta"
#else
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.AltStore"
#endif
#endif
return infoDictionary
}
public static func swizzleBundleID(handler: () -> Void)
{
let bundleClass: AnyClass = Bundle.self
guard
let originalMethod = class_getInstanceMethod(bundleClass, #selector(getter: Bundle.infoDictionary)),
let swizzledMethod = class_getInstanceMethod(bundleClass, #selector(getter: Bundle.swizzled_infoDictionary))
else {
print("Failed to swizzle Bundle.infoDictionary.")
return
}
method_exchangeImplementations(originalMethod, swizzledMethod)
handler()
method_exchangeImplementations(swizzledMethod, originalMethod)
}
}