Skip to content

Commit

Permalink
settings(apple): support external read-write drives
Browse files Browse the repository at this point in the history
It is a lot simpler for AVF. All we have to do is save the read-only flag.

Fixes #5170
  • Loading branch information
osy committed Apr 17, 2023
1 parent ff3dcc6 commit 58125b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Configuration/UTMAppleConfigurationDrive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,26 @@ 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)
}

func encode(to encoder: Encoder) throws {
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)
}

Expand Down
2 changes: 2 additions & 0 deletions Platform/macOS/VMConfigAppleDriveCreateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions Platform/macOS/VMConfigAppleDriveDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 58125b9

Please sign in to comment.