Skip to content

Commit 7f1a5e1

Browse files
committed
Make EmuGUI accept spaces in file paths (Start VM)
1 parent 7139782 commit 7f1a5e1

File tree

2 files changed

+66
-57
lines changed

2 files changed

+66
-57
lines changed

dialogExecution/startVirtualMachine.py

Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -390,32 +390,31 @@ def start_virtual_machine(self):
390390

391391
else:
392392
if self.vmSpecs[26] == "Let QEMU decide":
393-
if platform.system() == "Windows":
394-
qemu_cmd = qemu_cmd + f" -hda \"{self.vmSpecs[5]}\""
395-
396-
else:
397-
qemu_cmd = qemu_cmd + f" -hda {self.vmSpecs[5]}"
393+
qemu_cmd = qemu_cmd + f" -hda \"{self.vmSpecs[5]}\""
394+
qemu_cmd_list.append("-hda")
395+
qemu_cmd_list.append(self.vmSpecs[5])
398396

399-
elif self.vmSpecs[26] == "IDE":
400-
if platform.system() == "Windows":
401-
qemu_cmd = qemu_cmd + f" -drive file=\"{self.vmSpecs[5]}\",if=ide,media=disk"
397+
""" if platform.system() == "Windows":
398+
qemu_cmd = qemu_cmd + f" -hda \"{self.vmSpecs[5]}\""
402399
403400
else:
404-
qemu_cmd = qemu_cmd + f" -drive file={self.vmSpecs[5]},if=ide,media=disk"
401+
qemu_cmd = qemu_cmd + f" -hda {self.vmSpecs[5]}" """
405402

406-
elif self.vmSpecs[26] == "VirtIO SCSI":
407-
if platform.system() == "Windows":
408-
qemu_cmd = qemu_cmd + f" -device virtio-scsi-pci,id=scsi0 -drive file=\"{self.vmSpecs[5]}\",if=none,discard=unmap,aio=native,cache=none,id=hd1 -device scsi-hd,drive=hd1,bus=scsi0.0"
403+
else:
404+
qemu_cmd = qemu_cmd + " -drive"
405+
qemu_cmd_list.append("-drive")
409406

410-
else:
411-
qemu_cmd = qemu_cmd + f" -device virtio-scsi-pci,id=scsi0 -drive file={self.vmSpecs[5]},if=none,discard=unmap,aio=native,cache=none,id=hd1 -device scsi-hd,drive=hd1,bus=scsi0.0"
407+
if self.vmSpecs[26] == "IDE":
408+
qemu_cmd = qemu_cmd + f" file=\"{self.vmSpecs[5]}\",if=ide,media=disk"
409+
qemu_cmd_list.append(f"file=\"{self.vmSpecs[5]}\",if=ide,media=disk")
412410

413-
elif self.vmSpecs[26] == "AHCI":
414-
if platform.system() == "Windows":
415-
qemu_cmd = qemu_cmd + f" -drive id=disk,file=\"{self.vmSpecs[5]}\",if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0"
411+
elif self.vmSpecs[26] == "VirtIO SCSI":
412+
qemu_cmd = qemu_cmd + f" file=\"{self.vmSpecs[5]}\",if=none,discard=unmap,aio=native,cache=none,id=hd1 -device scsi-hd,drive=hd1,bus=scsi0.0"
413+
qemu_cmd_list.append(f"file=\"{self.vmSpecs[5]}\",if=none,discard=unmap,aio=native,cache=none,id=hd1 -device scsi-hd,drive=hd1,bus=scsi0.0")
416414

417-
else:
418-
qemu_cmd = qemu_cmd + f" -drive id=disk,file={self.vmSpecs[5]},if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0"
415+
elif self.vmSpecs[26] == "AHCI":
416+
qemu_cmd = qemu_cmd + f" file=\"{self.vmSpecs[5]}\",if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0"
417+
qemu_cmd_list.append(f"file=\"{self.vmSpecs[5]}\",if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0")
419418

420419
if self.vmSpecs[2] != "Let QEMU decide":
421420
qemu_cmd = qemu_cmd + f" -M {self.vmSpecs[2]}"
@@ -483,140 +482,150 @@ def start_virtual_machine(self):
483482
qemu_cmd = qemu_cmd + " -win2k-hack"
484483

485484
if fda_file != "":
486-
if platform.system() == "Windows":
485+
qemu_cmd = qemu_cmd + f" -drive format=raw,file=\"{fda_file}\",index=0,if=floppy"
486+
qemu_cmd_list.append("-drive")
487+
qemu_cmd_list.append(f"format=raw,file=\"{fda_file}\",index=0,if=floppy")
488+
489+
""" if platform.system() == "Windows":
487490
qemu_cmd = qemu_cmd + f" -drive format=raw,file=\"{fda_file}\",index=0,if=floppy"
488491
489492
else:
490-
qemu_cmd = qemu_cmd + f" -drive format=raw,file={fda_file},index=0,if=floppy"
493+
qemu_cmd = qemu_cmd + f" -drive format=raw,file={fda_file},index=0,if=floppy" """
491494

492495
if cdrom_file != "":
493-
if platform.system() == "Windows":
494-
if self.vmSpecs[24] == "Let QEMU decide":
495-
qemu_cmd = qemu_cmd + f" -cdrom \"{cdrom_file}\""
496+
if self.vmSpecs[24] == "Let QEMU decide":
497+
qemu_cmd = qemu_cmd + f" -cdrom \"{cdrom_file}\""
498+
qemu_cmd_list.append(f"-cdrom \"{cdrom_file}\"")
496499

497-
elif self.vmSpecs[24] == "IDE":
500+
else:
501+
if self.vmSpecs[24] == "IDE":
498502
qemu_cmd = qemu_cmd + f" -drive file=\"{cdrom_file}\",if=ide,media=cdrom"
503+
qemu_cmd_list.append(f"-drive file=\"{cdrom_file}\",if=ide,media=cdrom")
499504

500505
elif self.vmSpecs[24] == "SCSI":
501506
qemu_cmd = qemu_cmd + f" -drive file=\"{cdrom_file}\",if=scsi,media=cdrom"
507+
qemu_cmd_list.append(f"-drive file=\"{cdrom_file}\",if=scsi,media=cdrom")
502508

503509
elif self.vmSpecs[24] == "Virtio":
504510
qemu_cmd = qemu_cmd + f" -drive file=\"{cdrom_file}\",if=virtio,media=cdrom"
505-
506-
else:
507-
if self.vmSpecs[24] == "Let QEMU decide":
508-
qemu_cmd = qemu_cmd + f" -cdrom {cdrom_file}"
509-
510-
elif self.vmSpecs[24] == "IDE":
511-
qemu_cmd = qemu_cmd + f" -drive file={cdrom_file},if=ide,media=cdrom"
512-
513-
elif self.vmSpecs[24] == "SCSI":
514-
qemu_cmd = qemu_cmd + f" -drive file={cdrom_file},if=scsi,media=cdrom"
515-
516-
elif self.vmSpecs[24] == "Virtio":
517-
qemu_cmd = qemu_cmd + f" -drive file={cdrom_file},if=virtio,media=cdrom"
511+
qemu_cmd_list.append(f"-drive file=\"{cdrom_file}\",if=virtio,media=cdrom")
518512

519513
if cdrom_file2 != "":
520-
if platform.system() == "Windows":
521-
if self.vmSpecs[25] == "Let QEMU decide":
522-
qemu_cmd = qemu_cmd + f" -cdrom \"{cdrom_file2}\""
523-
524-
elif self.vmSpecs[25] == "IDE":
525-
qemu_cmd = qemu_cmd + f" -drive file=\"{cdrom_file2}\",if=ide,media=cdrom"
526-
527-
elif self.vmSpecs[25] == "SCSI":
528-
qemu_cmd = qemu_cmd + f" -drive file=\"{cdrom_file2}\",if=scsi,media=cdrom"
529-
530-
elif self.vmSpecs[25] == "Virtio":
531-
qemu_cmd = qemu_cmd + f" -drive file=\"{cdrom_file2}\",if=virtio,media=cdrom"
514+
if self.vmSpecs[25] == "Let QEMU decide":
515+
qemu_cmd = qemu_cmd + f" -cdrom \"{cdrom_file2}\""
516+
qemu_cmd_list.append(f"-cdrom \"{cdrom_file2}\"")
532517

533518
else:
534-
if self.vmSpecs[25] == "Let QEMU decide":
535-
qemu_cmd = qemu_cmd + f" -cdrom {cdrom_file2}"
536-
537-
elif self.vmSpecs[25] == "IDE":
519+
if self.vmSpecs[25] == "IDE":
538520
qemu_cmd = qemu_cmd + f" -drive file={cdrom_file2},if=ide,media=cdrom"
521+
qemu_cmd_list.append(f"-drive file=\"{cdrom_file2}\",if=ide,media=cdrom")
539522

540523
elif self.vmSpecs[25] == "SCSI":
541524
qemu_cmd = qemu_cmd + f" -drive file={cdrom_file2},if=scsi,media=cdrom"
525+
qemu_cmd_list.append(f"-drive file=\"{cdrom_file2}\",if=scsi,media=cdrom")
542526

543527
elif self.vmSpecs[25] == "Virtio":
544528
qemu_cmd = qemu_cmd + f" -drive file={cdrom_file2},if=virtio,media=cdrom"
529+
qemu_cmd_list.append(f"-drive file=\"{cdrom_file2}\",if=virtio,media=cdrom")
545530

546531
if bootfrom == "c" or bootfrom == "a" and fda_file == "" or bootfrom == "d" and cdrom_file == "":
547532
qemu_cmd = qemu_cmd + " -boot c"
533+
qemu_cmd_list.append("-boot c")
548534

549535
elif bootfrom == "a" and fda_file != "":
550536
qemu_cmd = qemu_cmd + " -boot a"
537+
qemu_cmd_list.append("-boot a")
551538

552539
elif bootfrom == "d" and cdrom_file != "":
553540
qemu_cmd = qemu_cmd + " -boot d"
541+
qemu_cmd_list.append("-boot d")
554542

555543
if self.vmSpecs[10] != "":
556544
qemu_cmd = qemu_cmd + f" -L {self.vmSpecs[10]}"
545+
qemu_cmd_list.append(f"-L {self.vmSpecs[10]}")
557546

558547
if self.vmSpecs[12] != "none":
559548
qemu_cmd = qemu_cmd + f" -device {self.vmSpecs[12]}"
549+
qemu_cmd_list.append(f"-device {self.vmSpecs[12]}")
560550

561551
if self.vmSpecs[12] == "intel-hda":
562552
qemu_cmd = qemu_cmd + " -device hda-duplex"
553+
qemu_cmd_list.append(f"-device hda-duplex")
563554

564555
if self.vmSpecs[13] != "":
565556
qemu_cmd = qemu_cmd + f" -kernel \"{self.vmSpecs[13]}\""
557+
qemu_cmd_list.append(f"-kernel \"{self.vmSpecs[13]}\"")
566558

567559
if self.vmSpecs[14] != "":
568560
qemu_cmd = qemu_cmd + f" -initrd \"{self.vmSpecs[14]}\""
561+
qemu_cmd_list.append(f"-initrd \"{self.vmSpecs[14]}\"")
569562

570563
if self.vmSpecs[15] != "":
571564
qemu_cmd = qemu_cmd + f" -append \"{self.vmSpecs[15]}\""
565+
qemu_cmd_list.append(f"-append \"{self.vmSpecs[15]}\"")
572566

573567
if self.vmSpecs[16] == "USB Mouse" and self.vmSpecs[7] == "0":
574568
if self.vmSpecs[1] == "aarch64" or self.vmSpecs[1] == "arm":
575569
qemu_cmd = qemu_cmd + " -device usb-mouse"
570+
qemu_cmd_list.append("-device usb-mouse")
576571

577572
else:
578573
qemu_cmd = qemu_cmd + " -usbdevice mouse"
574+
qemu_cmd_list.append("-usbdevice mouse")
579575

580576
if self.vmSpecs[16] == "USB Tablet Device" and self.vmSpecs[7] == "0":
581577
if self.vmSpecs[1] == "aarch64" or self.vmSpecs[1] == "arm":
582578
qemu_cmd = qemu_cmd + " -device usb-tablet"
579+
qemu_cmd_list.append("-device usb-tablet")
583580

584581
else:
585582
qemu_cmd = qemu_cmd + " -usbdevice tablet"
583+
qemu_cmd_list.append("-usbdevice tablet")
586584

587585
if self.vmSpecs[18] != "" and self.vmSpecs[18] != None and self.vmSpecs[18] != "None":
588586
qemu_cmd = qemu_cmd + f" -bios \"{self.vmSpecs[18]}\""
587+
qemu_cmd_list.append(f"-bios \"{self.vmSpecs[18]}\"")
589588

590589
if self.vmSpecs[19] == "USB Keyboard":
591590
qemu_cmd = qemu_cmd + " -device usb-kbd"
591+
qemu_cmd_list.append("-device usb-kbd")
592592

593593
if self.vmSpecs[11] != "":
594594
qemu_cmd = qemu_cmd + f" {self.vmSpecs[11]}"
595+
qemu_cmd_list.append(self.vmSpecs[11])
595596

596597
if self.vmSpecs[23] == "TCG":
597598
qemu_cmd = qemu_cmd + " -accel tcg"
599+
qemu_cmd_list.append("-accel tcg")
598600

599601
elif self.vmSpecs[23] == "HAXM":
600602
qemu_cmd = qemu_cmd + " -accel hax"
603+
qemu_cmd_list.append("-accel hax")
601604

602605
elif self.vmSpecs[23] == "WHPX":
603606
qemu_cmd = qemu_cmd + " -accel whpx"
607+
qemu_cmd_list.append("-accel whpx")
604608

605609
elif self.vmSpecs[23] == "WHPX (kernel-irqchip off)":
606610
qemu_cmd = qemu_cmd + " -accel whpx,kernel-irqchip=off"
611+
qemu_cmd_list.append("-accel whpx,kernel-irqchip=off")
607612

608613
elif self.vmSpecs[23] == "KVM":
609614
qemu_cmd = qemu_cmd + " -enable-kvm"
615+
qemu_cmd_list.append("-enable-kvm")
610616

611617
if self.lineEdit_3.text() != "":
612618
if self.vmSpecs[1] == "x86_64":
613619
qemu_cmd = qemu_cmd + f" -chardev socket,id=chrtpm,path={self.lineEdit_3.text()}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0"
620+
qemu_cmd_list.append(f"-chardev socket,id=chrtpm,path={self.lineEdit_3.text()}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0")
614621

615622
elif self.vmSpecs[1] == "aarch64":
616623
qemu_cmd = qemu_cmd + f" -chardev socket,id=chrtpm,path={self.lineEdit_3.text()}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis-device,tpmdev=tpm0"
624+
qemu_cmd_list.append(f"-chardev socket,id=chrtpm,path={self.lineEdit_3.text()}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis-device,tpmdev=tpm0")
617625

618626
elif self.vmSpecs[1] == "ppc64":
619627
qemu_cmd = qemu_cmd + f" -chardev socket,id=chrtpm,path={self.lineEdit_3.text()}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-spapr,tpmdev=tpm0"
628+
qemu_cmd_list.append(f"-chardev socket,id=chrtpm,path={self.lineEdit_3.text()}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-spapr,tpmdev=tpm0")
620629

621630
subprocess.Popen(qemu_cmd)
622631

@@ -627,7 +636,7 @@ def start_virtual_machine(self):
627636
print("Qemu couldn't be executed. Trying subprocess.run")
628637

629638
try:
630-
qemu_cmd_split = qemu_cmd.split(" ")
639+
""" qemu_cmd_split = qemu_cmd.split(" ")
631640
# Potentially insert fix for datetime issue here
632641
633642
i = 0
@@ -640,7 +649,7 @@ def start_virtual_machine(self):
640649
del qemu_cmd_split[i + 1]
641650
break
642651
643-
i += 1
652+
i += 1 """
644653

645654
subprocess.run(shlex.split(qemu_cmd))
646655

emugui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Importing required modules
1+
# Importing required modules
22
import os
33

44
try:

0 commit comments

Comments
 (0)