settings(apple): support external read-write drives

It is a lot simpler for AVF. All we have to do is save the read-only flag.

Fixes #5170
This commit is contained in:
osy 2023-04-16 19:54:26 -07:00
parent ff3dcc66c3
commit 58125b96c9
3 changed files with 7 additions and 4 deletions

View File

@ -72,19 +72,17 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
self.imageName = imageName
imageURL = dataURL.appendingPathComponent(imageName)
isExternal = false
isReadOnly = try container.decodeIfPresent(Bool.self, forKey: .isReadOnly) ?? false
} else if let bookmark = try container.decodeIfPresent(Data.self, forKey: .bookmark) {
var stale: Bool = false
imageURL = try? URL(resolvingBookmarkData: bookmark, options: .withSecurityScope, bookmarkDataIsStale: &stale)
imageName = imageURL?.lastPathComponent
isExternal = true
isReadOnly = true
} else {
imageURL = nil
imageName = nil
isExternal = true
isReadOnly = true
}
isReadOnly = try container.decodeIfPresent(Bool.self, forKey: .isReadOnly) ?? isExternal
id = try container.decode(String.self, forKey: .identifier)
}
@ -92,8 +90,8 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
var container = encoder.container(keyedBy: CodingKeys.self)
if !isExternal {
try container.encodeIfPresent(imageName, forKey: .imageName)
try container.encode(isReadOnly, forKey: .isReadOnly)
}
try container.encode(isReadOnly, forKey: .isReadOnly)
try container.encode(id, forKey: .identifier)
}

View File

@ -32,8 +32,10 @@ struct VMConfigAppleDriveCreateView: View {
.onChange(of: config.isExternal) { newValue in
if newValue {
config.sizeMib = 0
config.isReadOnly = true
} else {
config.sizeMib = 10240
config.isReadOnly = false
}
}
if !config.isExternal {

View File

@ -22,6 +22,9 @@ struct VMConfigAppleDriveDetailsView: View {
var body: some View {
Form {
Toggle(isOn: $config.isExternal, label: {
Text("Removable Drive")
}).disabled(true)
TextField("Name", text: .constant(config.imageURL?.lastPathComponent ?? NSLocalizedString("(New Drive)", comment: "VMConfigAppleDriveDetailsView")))
.disabled(true)
Toggle("Read Only?", isOn: $config.isReadOnly)