VMConfigDriveCreateView.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // Copyright © 2020 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. import SwiftUI
  17. struct VMConfigDriveCreateView: View {
  18. @Binding var config: UTMQemuConfigurationDrive
  19. var body: some View {
  20. Form {
  21. Toggle(isOn: $config.isExternal.animation(), label: {
  22. Text("Removable")
  23. }).onChange(of: config.isExternal) { removable in
  24. config.imageType = removable && config.interface != .floppy ? .cd : .disk
  25. config.isRawImage = removable
  26. config.isReadOnly = removable
  27. if let defaultInterfaceForImageType = config.defaultInterfaceForImageType {
  28. config.interface = defaultInterfaceForImageType(config.imageType)
  29. }
  30. }.help("If checked, no drive image will be stored with the VM. Instead you can mount/unmount image while the VM is running.")
  31. VMConfigConstantPicker("Interface", selection: $config.interface)
  32. .help("Hardware interface on the guest used to mount this image. Different operating systems support different interfaces. The default will be the most common interface.")
  33. .onChange(of: config.interface) { interface in
  34. config.imageType = config.isExternal && interface != .floppy ? .cd : .disk
  35. }
  36. if !config.isExternal {
  37. SizeTextField($config.sizeMib)
  38. Toggle(isOn: $config.isRawImage) {
  39. Text("Raw Image")
  40. }.help("Advanced. If checked, a raw disk image is used. Raw disk image does not support snapshots and will not dynamically expand in size.")
  41. }
  42. }
  43. }
  44. }
  45. struct VMConfigDriveCreateView_Previews: PreviewProvider {
  46. @State static private var config = UTMQemuConfigurationDrive()
  47. static var previews: some View {
  48. VMConfigDriveCreateView(config: $config)
  49. }
  50. }