From a4a79fea7c34174e6cb5943d0bb1f03b429c7a3f Mon Sep 17 00:00:00 2001 From: Naveenraj M <22456988+naveenrajm7@users.noreply.github.com> Date: Sat, 12 Oct 2024 14:08:49 -0600 Subject: [PATCH 1/3] scripting: add qemu additional arguments read and update qemu additional argument of vm config --- Scripting/UTM.sdef | 13 ++++++++++ Scripting/UTMScriptingConfigImpl.swift | 35 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/Scripting/UTM.sdef b/Scripting/UTM.sdef index 506164656..22144bcc8 100644 --- a/Scripting/UTM.sdef +++ b/Scripting/UTM.sdef @@ -425,6 +425,11 @@ description="List of serial configuration."> + + + + @@ -534,6 +539,14 @@ description="The port number to listen on when the interface is a TCP server."/> + + + + + + diff --git a/Scripting/UTMScriptingConfigImpl.swift b/Scripting/UTMScriptingConfigImpl.swift index 7c83a3ca5..471d0e0f6 100644 --- a/Scripting/UTMScriptingConfigImpl.swift +++ b/Scripting/UTMScriptingConfigImpl.swift @@ -107,6 +107,7 @@ extension UTMScriptingConfigImpl { "drives": config.drives.map({ serializeQemuDriveExisting($0) }), "networkInterfaces": config.networks.enumerated().map({ serializeQemuNetwork($1, index: $0) }), "serialPorts": config.serials.enumerated().map({ serializeQemuSerial($1, index: $0) }), + "qemuAdditionalArguments": config.qemu.additionalArguments.map({ serializeQemuAdditionalArgument($0)}), ] } @@ -188,6 +189,19 @@ extension UTMScriptingConfigImpl { ] } + private func serializeQemuAdditionalArgument(_ argument: QEMUArgument) -> [AnyHashable: Any] { + var serializedArgument: [AnyHashable: Any] = [ + "string": argument.string + ] + + // Only add fileUrls if it is not nil and contains URLs + if let fileUrls = argument.fileUrls, !fileUrls.isEmpty { + serializedArgument["fileUrls"] = fileUrls.map({ $0 as AnyHashable }) + } + + return serializedArgument + } + private func serializeAppleConfiguration(_ config: UTMAppleConfiguration) -> [AnyHashable : Any] { [ "name": config.information.name, @@ -338,6 +352,9 @@ extension UTMScriptingConfigImpl { if let serialPorts = record["serialPorts"] as? [[AnyHashable : Any]] { try updateQemuSerials(from: serialPorts) } + if let qemuAdditionalArguments = record["qemuAdditionalArguments"] as? [[AnyHashable: Any]] { + try updateQemuAdditionalArguments(from: qemuAdditionalArguments) + } } private func parseQemuDriveInterface(_ value: AEKeyword?) -> QEMUDriveInterface? { @@ -500,6 +517,24 @@ extension UTMScriptingConfigImpl { } } + private func updateQemuAdditionalArguments(from records: [[AnyHashable: Any]]) throws { + let config = config as! UTMQemuConfiguration + let additionalArguments = records.compactMap { record -> QEMUArgument? in + guard let argumentString = record["string"] as? String else { return nil } + var argument = QEMUArgument(argumentString) + // Qemu Additional Arguments in UI, only takes strings + // So, fileUrls of arguments will never be used + // This is here if they support in future + if let fileUrls = record["fileUrls"] as? [URL] { + argument.fileUrls = fileUrls + } + return argument + } + // Update entire additional arguments with new one. + config.qemu.additionalArguments = additionalArguments + } + + private func updateAppleConfiguration(from record: [AnyHashable : Any]) throws { let config = config as! UTMAppleConfiguration if let name = record["name"] as? String, !name.isEmpty { From 7c8f65659299450f88b0b90e1906b6abc80fea48 Mon Sep 17 00:00:00 2001 From: Naveenraj M <22456988+naveenrajm7@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:03:57 -0600 Subject: [PATCH 2/3] scripting: change property name Avoid using reserved keyword in AppleScript as property name --- Scripting/UTM.sdef | 2 +- Scripting/UTMScriptingConfigImpl.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Scripting/UTM.sdef b/Scripting/UTM.sdef index 22144bcc8..c466928f3 100644 --- a/Scripting/UTM.sdef +++ b/Scripting/UTM.sdef @@ -540,7 +540,7 @@ - [AnyHashable: Any] { var serializedArgument: [AnyHashable: Any] = [ - "string": argument.string + "argumentString": argument.string ] // Only add fileUrls if it is not nil and contains URLs @@ -520,7 +520,7 @@ extension UTMScriptingConfigImpl { private func updateQemuAdditionalArguments(from records: [[AnyHashable: Any]]) throws { let config = config as! UTMQemuConfiguration let additionalArguments = records.compactMap { record -> QEMUArgument? in - guard let argumentString = record["string"] as? String else { return nil } + guard let argumentString = record["argumentString"] as? String else { return nil } var argument = QEMUArgument(argumentString) // Qemu Additional Arguments in UI, only takes strings // So, fileUrls of arguments will never be used From f101cceca0c26d378d1cdd0791d865941dc2994f Mon Sep 17 00:00:00 2001 From: Naveenraj M <22456988+naveenrajm7@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:29:12 -0700 Subject: [PATCH 3/3] scripting: drop file urls from qemu arguments If file urls were be supported, handle file permissions before use (app sandbox) --- Scripting/UTM.sdef | 3 --- Scripting/UTMScriptingConfigImpl.swift | 12 +----------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/Scripting/UTM.sdef b/Scripting/UTM.sdef index c466928f3..3b7db1749 100644 --- a/Scripting/UTM.sdef +++ b/Scripting/UTM.sdef @@ -542,9 +542,6 @@ - - diff --git a/Scripting/UTMScriptingConfigImpl.swift b/Scripting/UTMScriptingConfigImpl.swift index 2ae8d5224..b00edca15 100644 --- a/Scripting/UTMScriptingConfigImpl.swift +++ b/Scripting/UTMScriptingConfigImpl.swift @@ -194,11 +194,6 @@ extension UTMScriptingConfigImpl { "argumentString": argument.string ] - // Only add fileUrls if it is not nil and contains URLs - if let fileUrls = argument.fileUrls, !fileUrls.isEmpty { - serializedArgument["fileUrls"] = fileUrls.map({ $0 as AnyHashable }) - } - return serializedArgument } @@ -522,12 +517,7 @@ extension UTMScriptingConfigImpl { let additionalArguments = records.compactMap { record -> QEMUArgument? in guard let argumentString = record["argumentString"] as? String else { return nil } var argument = QEMUArgument(argumentString) - // Qemu Additional Arguments in UI, only takes strings - // So, fileUrls of arguments will never be used - // This is here if they support in future - if let fileUrls = record["fileUrls"] as? [URL] { - argument.fileUrls = fileUrls - } + return argument } // Update entire additional arguments with new one.