From f17690b98b1b35a9a1052ef895ba1ff96d835946 Mon Sep 17 00:00:00 2001 From: Nindi Gill Date: Sat, 28 Oct 2023 22:47:08 +1100 Subject: [PATCH] Add macOS Sierra 10.12 createinstallmedia workaround (#100) --- Mist.xcodeproj/project.pbxproj | 4 +++ Mist/Helpers/PropertyListUpdater.swift | 45 ++++++++++++++++++++++++++ Mist/Helpers/TaskManager.swift | 7 ++++ 3 files changed, 56 insertions(+) create mode 100644 Mist/Helpers/PropertyListUpdater.swift diff --git a/Mist.xcodeproj/project.pbxproj b/Mist.xcodeproj/project.pbxproj index 73a0605..e7937f4 100644 --- a/Mist.xcodeproj/project.pbxproj +++ b/Mist.xcodeproj/project.pbxproj @@ -131,6 +131,7 @@ 39FF05FA285985DD00A86670 /* SettingsAboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39FF05F9285985DD00A86670 /* SettingsAboutView.swift */; }; 573A23622A28711C00EC9470 /* Architecture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 573A23612A28711C00EC9470 /* Architecture.swift */; }; 573A23642A28791F00EC9470 /* Scene+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 573A23632A28791F00EC9470 /* Scene+Extension.swift */; }; + 574199D22AED15420086493F /* PropertyListUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574199D12AED15420086493F /* PropertyListUpdater.swift */; }; 575812BA2A373A4F00425BAF /* FirmwareAlertType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 575812B92A373A4F00425BAF /* FirmwareAlertType.swift */; }; 575812BC2A37406300425BAF /* ListRowDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 575812BB2A37406300425BAF /* ListRowDetail.swift */; }; 575812BE2A3743E300425BAF /* InstallerSheetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 575812BD2A3743E300425BAF /* InstallerSheetType.swift */; }; @@ -283,6 +284,7 @@ 39FF05F9285985DD00A86670 /* SettingsAboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAboutView.swift; sourceTree = ""; }; 573A23612A28711C00EC9470 /* Architecture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Architecture.swift; sourceTree = ""; }; 573A23632A28791F00EC9470 /* Scene+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Scene+Extension.swift"; sourceTree = ""; }; + 574199D12AED15420086493F /* PropertyListUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyListUpdater.swift; sourceTree = ""; }; 575812B92A373A4F00425BAF /* FirmwareAlertType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirmwareAlertType.swift; sourceTree = ""; }; 575812BB2A37406300425BAF /* ListRowDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListRowDetail.swift; sourceTree = ""; }; 575812BD2A3743E300425BAF /* InstallerSheetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstallerSheetType.swift; sourceTree = ""; }; @@ -406,6 +408,7 @@ 39CF56322862B7A2006FB5D2 /* PackageCreator.swift */, 393F35BD2864197F005B7165 /* PrivilegedHelperTool.swift */, 3935F4CC286C6A5D00760AB0 /* ProcessKiller.swift */, + 574199D12AED15420086493F /* PropertyListUpdater.swift */, 3935F4C6286B54E200760AB0 /* SparkleUpdater.swift */, 398734C328600E6E00B4C357 /* TaskManager.swift */, 398734C5286011C300B4C357 /* Validator.swift */, @@ -842,6 +845,7 @@ 390451D02856F63700E0B563 /* Installer.swift in Sources */, 3935F47628643AF000760AB0 /* UNNotificationAction+Extension.swift in Sources */, 39252AB3285C5D7700956C74 /* SettingsGeneralUpdatesView.swift in Sources */, + 574199D22AED15420086493F /* PropertyListUpdater.swift in Sources */, 39CA25E32941D8BB0030711E /* FileAttributesUpdater.swift in Sources */, 575812C42A3821A900425BAF /* InstallerVolumeSelectionInformationView.swift in Sources */, 3935F4AB286B04BC00760AB0 /* HelperToolInfoPropertyList.swift in Sources */, diff --git a/Mist/Helpers/PropertyListUpdater.swift b/Mist/Helpers/PropertyListUpdater.swift new file mode 100644 index 0000000..a3d151b --- /dev/null +++ b/Mist/Helpers/PropertyListUpdater.swift @@ -0,0 +1,45 @@ +// +// PropertyListUpdater.swift +// Mist +// +// Created by Nindi Gill on 28/10/2023. +// + +import Foundation + +/// Helper struct to update a Property List key-pair value. +struct PropertyListUpdater { + + /// Edit a key-pair value in a Property List. + /// + /// - Parameters: + /// - url: The URL of the property list to be updated. + /// - key: The key in the property list to be updated. + /// - value: The value to update within the property list. + /// + /// - Throws: An `Error` if the command failed to execute. + static func update(_ url: URL, key: String, value: AnyHashable) throws { + + let input: String = try String(contentsOf: url, encoding: .utf8) + + guard var data: Data = input.data(using: .utf8) else { + throw MistError.invalidData + } + + var format: PropertyListSerialization.PropertyListFormat = .xml + + guard var propertyList: [String: Any] = try PropertyListSerialization.propertyList(from: data, options: [.mutableContainers], format: &format) as? [String: Any] else { + throw MistError.invalidData + } + + propertyList[key] = value + + data = try PropertyListSerialization.data(fromPropertyList: propertyList, format: .xml, options: .bitWidth) + + guard let output = String(data: data, encoding: .utf8) else { + throw MistError.invalidData + } + + try output.write(to: url, atomically: true, encoding: .utf8) + } +} diff --git a/Mist/Helpers/TaskManager.swift b/Mist/Helpers/TaskManager.swift index 2e150ee..809bc93 100644 --- a/Mist/Helpers/TaskManager.swift +++ b/Mist/Helpers/TaskManager.swift @@ -441,6 +441,13 @@ class TaskManager: ObservableObject { try await DiskImageMounter.mount(temporaryImageURL, mountPoint: installer.temporaryISOMountPointURL) }, MistTask(type: .create, description: "macOS Installer in temporary Disk Image") { + + // Workaround to make macOS Sierra 10.12 createinstallmedia work + if installer.version.hasPrefix("10.12") { + let infoPlistURL: URL = installer.temporaryInstallerURL.appendingPathComponent("/Contents/Info.plist") + try PropertyListUpdater.update(infoPlistURL, key: "CFBundleShortVersionString", value: "12.6.03") + } + try await InstallMediaCreator.create(createInstallMediaURL, mountPoint: installer.temporaryISOMountPointURL, sierraOrOlder: installer.sierraOrOlder) }, MistTask(type: .unmount, description: "temporary Disk Image") {