Parcourir la source

config(apple): move recovery ipsw setting and fixup key names

osy il y a 3 ans
Parent
commit
15bf4357f3

+ 3 - 0
Configuration/UTMAppleConfigurationBoot.swift

@@ -41,6 +41,9 @@ struct UTMAppleConfigurationBoot: Codable {
     var efiVariableStorageURL: URL?
     var efiVariableStorageURL: URL?
     var hasUefiBoot: Bool = false
     var hasUefiBoot: Bool = false
     
     
+    /// IPSW for installing macOS. Not saved.
+    var macRecoveryIpswURL: URL?
+    
     /// Next startup should be in recovery. Not saved.
     /// Next startup should be in recovery. Not saved.
     var startUpFromMacOSRecovery: Bool = false
     var startUpFromMacOSRecovery: Bool = false
     
     

+ 3 - 3
Configuration/UTMAppleConfigurationMacPlatform.swift

@@ -25,9 +25,9 @@ struct UTMAppleConfigurationMacPlatform: Codable {
     var auxiliaryStorageURL: URL?
     var auxiliaryStorageURL: URL?
     
     
     private enum CodingKeys: String, CodingKey {
     private enum CodingKeys: String, CodingKey {
-        case hardwareModel
-        case machineIdentifier
-        case auxiliaryStoragePath
+        case hardwareModel = "HardwareModel"
+        case machineIdentifier = "MachineIdentifier"
+        case auxiliaryStoragePath = "AuxiliaryStoragePath"
     }
     }
     
     
     init(from decoder: Decoder) throws {
     init(from decoder: Decoder) throws {

+ 1 - 1
Configuration/UTMAppleConfigurationSystem.swift

@@ -100,7 +100,7 @@ extension UTMAppleConfigurationSystem {
             if let oldPlatform = oldConfig.macPlatform {
             if let oldPlatform = oldConfig.macPlatform {
                 macPlatform = UTMAppleConfigurationMacPlatform(migrating: oldPlatform)
                 macPlatform = UTMAppleConfigurationMacPlatform(migrating: oldPlatform)
             }
             }
-            macRecoveryIpswURL = oldConfig.macRecoveryIpswURL
+            boot.macRecoveryIpswURL = oldConfig.macRecoveryIpswURL
         }
         }
         #endif
         #endif
     }
     }

+ 1 - 1
Managers/UTMAppleVirtualMachine.swift

@@ -73,7 +73,7 @@ import Virtualization
         // copy non-persistent values over
         // copy non-persistent values over
         newConfig.sharedDirectories = oldConfig.sharedDirectories
         newConfig.sharedDirectories = oldConfig.sharedDirectories
         if #available(macOS 12, *) {
         if #available(macOS 12, *) {
-            newConfig.system.macRecoveryIpswURL = oldConfig.system.macRecoveryIpswURL
+            newConfig.system.boot.macRecoveryIpswURL = oldConfig.system.boot.macRecoveryIpswURL
         }
         }
         config = UTMConfigurationWrapper(wrapping: newConfig)
         config = UTMConfigurationWrapper(wrapping: newConfig)
     }
     }

+ 2 - 2
Platform/Shared/UTMDownloadIPSWTask.swift

@@ -29,7 +29,7 @@ class UTMDownloadIPSWTask: UTMDownloadTask {
     
     
     init(for config: UTMAppleConfiguration) {
     init(for config: UTMAppleConfiguration) {
         self.config = config
         self.config = config
-        super.init(for: config.system.macRecoveryIpswURL!, named: config.information.name)
+        super.init(for: config.system.boot.macRecoveryIpswURL!, named: config.information.name)
     }
     }
     
     
     override func processCompletedDownload(at location: URL) async throws -> UTMVirtualMachine {
     override func processCompletedDownload(at location: URL) async throws -> UTMVirtualMachine {
@@ -38,7 +38,7 @@ class UTMDownloadIPSWTask: UTMDownloadTask {
             try fileManager.removeItem(at: cacheIpsw)
             try fileManager.removeItem(at: cacheIpsw)
         }
         }
         try fileManager.moveItem(at: location, to: cacheIpsw)
         try fileManager.moveItem(at: location, to: cacheIpsw)
-        config.system.macRecoveryIpswURL = cacheIpsw
+        config.system.boot.macRecoveryIpswURL = cacheIpsw
         return UTMVirtualMachine(newConfig: config, destinationURL: UTMData.defaultStorageUrl)
         return UTMVirtualMachine(newConfig: config, destinationURL: UTMData.defaultStorageUrl)
     }
     }
 }
 }

+ 1 - 1
Platform/Shared/VMWizardState.swift

@@ -259,7 +259,7 @@ enum VMWizardOS: String, Identifiable {
             #if os(macOS) && arch(arm64)
             #if os(macOS) && arch(arm64)
             if #available(macOS 12, *) {
             if #available(macOS 12, *) {
                 config.system.boot = try! UTMAppleConfigurationBoot(for: .macOS)
                 config.system.boot = try! UTMAppleConfigurationBoot(for: .macOS)
-                config.system.macRecoveryIpswURL = macRecoveryIpswURL
+                config.system.boot.macRecoveryIpswURL = macRecoveryIpswURL
                 config.system.macPlatform = macPlatform
                 config.system.macPlatform = macPlatform
             }
             }
             #endif
             #endif

+ 3 - 3
Platform/macOS/Display/VMDisplayAppleWindowController.swift

@@ -69,10 +69,10 @@ class VMDisplayAppleWindowController: VMDisplayWindowController {
         appleVM.screenshotDelegate = self
         appleVM.screenshotDelegate = self
         window!.recalculateKeyViewLoop()
         window!.recalculateKeyViewLoop()
         if #available(macOS 12, *) {
         if #available(macOS 12, *) {
-            shouldAutoStartVM = appleConfig.system.macRecoveryIpswURL == nil
+            shouldAutoStartVM = appleConfig.system.boot.macRecoveryIpswURL == nil
         }
         }
         super.windowDidLoad()
         super.windowDidLoad()
-        if #available(macOS 12, *), let ipswUrl = appleConfig.system.macRecoveryIpswURL {
+        if #available(macOS 12, *), let ipswUrl = appleConfig.system.boot.macRecoveryIpswURL {
             showConfirmAlert(NSLocalizedString("Would you like to install macOS? If an existing operating system is already installed on the primary drive of this VM, then it will be erased.", comment: "VMDisplayAppleWindowController")) {
             showConfirmAlert(NSLocalizedString("Would you like to install macOS? If an existing operating system is already installed on the primary drive of this VM, then it will be erased.", comment: "VMDisplayAppleWindowController")) {
                 self.isInstalling = true
                 self.isInstalling = true
                 self.appleVM.requestInstallVM(with: ipswUrl)
                 self.appleVM.requestInstallVM(with: ipswUrl)
@@ -312,7 +312,7 @@ extension VMDisplayAppleWindowController {
             self.isInstalling = false
             self.isInstalling = false
             // delete IPSW setting
             // delete IPSW setting
             self.enterSuspended(isBusy: true)
             self.enterSuspended(isBusy: true)
-            self.appleConfig.system.macRecoveryIpswURL = nil
+            self.appleConfig.system.boot.macRecoveryIpswURL = nil
             // start VM
             // start VM
             self.vm.requestVmStart()
             self.vm.requestVmStart()
         }
         }

+ 3 - 3
Platform/macOS/VMConfigAppleBootView.swift

@@ -107,10 +107,10 @@ struct VMConfigAppleBootView: View {
                 #if arch(arm64)
                 #if arch(arm64)
                 Section(header: Text("macOS Settings")) {
                 Section(header: Text("macOS Settings")) {
                     HStack {
                     HStack {
-                        TextField("IPSW Install Image", text: .constant(config.macRecoveryIpswURL?.lastPathComponent ?? ""))
+                        TextField("IPSW Install Image", text: .constant(config.boot.macRecoveryIpswURL?.lastPathComponent ?? ""))
                             .disabled(true)
                             .disabled(true)
                         Button("Clear") {
                         Button("Clear") {
-                            config.macRecoveryIpswURL = nil
+                            config.boot.macRecoveryIpswURL = nil
                         }
                         }
                         Button("Browse…") {
                         Button("Browse…") {
                             importBootloaderSelection = .ipsw
                             importBootloaderSelection = .ipsw
@@ -143,7 +143,7 @@ struct VMConfigAppleBootView: View {
                         }
                         }
                         config.macPlatform = UTMAppleConfigurationMacPlatform(newHardware: model)
                         config.macPlatform = UTMAppleConfigurationMacPlatform(newHardware: model)
                         config.boot.operatingSystem = .macOS
                         config.boot.operatingSystem = .macOS
-                        config.macRecoveryIpswURL = url
+                        config.boot.macRecoveryIpswURL = url
                         #endif
                         #endif
                     }
                     }
                 case .kernel:
                 case .kernel: