Updates cached AltStore bundle when app has been updated

This commit is contained in:
Riley Testut
2019-09-21 16:35:08 -07:00
parent 883e8cfbed
commit f506988296

View File

@@ -170,30 +170,31 @@ private extension DatabaseManager
installedApp.storeApp = storeApp installedApp.storeApp = storeApp
} }
installedApp.version = localApp.version
let fileURL = installedApp.fileURL let fileURL = installedApp.fileURL
if !FileManager.default.fileExists(atPath: fileURL.path) || installedApp.version != localApp.version
if !FileManager.default.fileExists(atPath: fileURL.path)
{ {
FileManager.default.prepareTemporaryURL() { (temporaryFileURL) in
do do
{ {
try FileManager.default.copyItem(at: Bundle.main.bundleURL, to: fileURL) try FileManager.default.copyItem(at: Bundle.main.bundleURL, to: temporaryFileURL)
let infoPlistURL = fileURL.appendingPathComponent("Info.plist") let infoPlistURL = temporaryFileURL.appendingPathComponent("Info.plist")
// TODO: Copy to temporary location, modify it, _then_ copy to final destination.
guard var infoDictionary = Bundle.main.infoDictionary else { throw ALTError(.missingInfoPlist) } guard var infoDictionary = Bundle.main.infoDictionary else { throw ALTError(.missingInfoPlist) }
infoDictionary[kCFBundleIdentifierKey as String] = StoreApp.altstoreAppID infoDictionary[kCFBundleIdentifierKey as String] = StoreApp.altstoreAppID
try (infoDictionary as NSDictionary).write(to: infoPlistURL) try (infoDictionary as NSDictionary).write(to: infoPlistURL)
try FileManager.default.copyItem(at: temporaryFileURL, to: fileURL, shouldReplace: true)
} }
catch catch
{ {
print("Failed to copy AltStore app bundle to its proper location.", error) print("Failed to copy AltStore app bundle to its proper location.", error)
}
}
}
try? FileManager.default.removeItem(at: fileURL) // Must go after comparing versions to see if we need to update our cached AltStore app bundle.
} installedApp.version = localApp.version
}
if let provisioningProfile = localApp.provisioningProfile if let provisioningProfile = localApp.provisioningProfile
{ {