From db622c93bab065e7f089227fe17c68d424176644 Mon Sep 17 00:00:00 2001
From: gfdgd_xi <3025613752@qq.com>
Date: Thu, 10 Aug 2023 14:36:41 +0800
Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=99=A8=E5=9B=BE=E6=A0=87?=
=?UTF-8?q?=E6=94=AF=E6=8C=81=E5=90=AF=E5=8A=A8UEFI?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
StartVM.sh | 15 +-
VM-source/.qtc_clangd/compile_commands.json | 172 ++++++++++----------
VM-source/mainwindow.cpp | 18 +-
VM-source/mainwindow.ui | 4 +-
VM-source/qemu.cpp | 14 +-
VM/StartQemu.py | 7 +-
6 files changed, 135 insertions(+), 95 deletions(-)
diff --git a/StartVM.sh b/StartVM.sh
index fce2c53..035a4f3 100755
--- a/StartVM.sh
+++ b/StartVM.sh
@@ -22,6 +22,17 @@ if [[ $? == 0 ]] && [[ -f "$HOME/Qemu/Windows/Windows.qcow2" ]]; then
python3 ./VM/StartQemu.py
exit
fi
+ if [[ -f $HOME/.config/deepin-wine-runner/QEMU-EFI ]]; then
+ echo 使用 UEFI 启动
+ if [[ -f /usr/share/qemu/OVMF.fd ]]; then
+ qemuUEFI="--bios /usr/share/qemu/OVMF.fd"
+ else
+ if [[ -f `dirname $0`/VM/OVMF.fd ]]; then
+ qemuUEFI="--bios `dirname $0`/VM/OVMF.fd"
+ fi
+ fi
+ echo $qemuUEFI
+ fi
# 查看CPU个数
CpuSocketNum=`cat /proc/cpuinfo | grep "cpu cores" | uniq | wc -l`
# 查看CPU核心数
@@ -34,11 +45,11 @@ if [[ $? == 0 ]] && [[ -f "$HOME/Qemu/Windows/Windows.qcow2" ]]; then
use=$(echo "scale=4; $MemTotal / 3" | bc)
if [[ `arch` == "x86_64" ]]; then
echo X86 架构,使用 kvm 加速
- kvm -cpu host --hda "$HOME/Qemu/Windows/Windows.qcow2" -soundhw all -smp $CpuCount,sockets=$CpuSocketNum,cores=$(($CpuCoreNum / $CpuSocketNum)),threads=$(($CpuCount / $CpuCoreNum / $CpuSocketNum)) -m ${use}G -net user,hostfwd=tcp::3389-:3389 -display vnc=:5 -display gtk -usb -nic model=rtl8139
+ kvm -cpu host --hda "$HOME/Qemu/Windows/Windows.qcow2" -soundhw all -smp $CpuCount,sockets=$CpuSocketNum,cores=$(($CpuCoreNum / $CpuSocketNum)),threads=$(($CpuCount / $CpuCoreNum / $CpuSocketNum)) -m ${use}G -net user,hostfwd=tcp::3389-:3389 -display vnc=:5 -display gtk -usb -nic model=rtl8139 $qemuUEFI
exit
fi
echo 非 X86 架构,不使用 kvm 加速
- qemu-system-x86_64 --hda "$HOME/Qemu/Windows/Windows.qcow2" -soundhw all -smp $CpuCount,sockets=$CpuSocketNum,cores=$(($CpuCoreNum / $CpuSocketNum)),threads=$(($CpuCount / $CpuCoreNum / $CpuSocketNum)) -m ${use}G -net user,hostfwd=tcp::3389-:3389 -display vnc=:5 -display gtk -usb -nic model=rtl8139
+ qemu-system-x86_64 --hda "$HOME/Qemu/Windows/Windows.qcow2" -soundhw all -smp $CpuCount,sockets=$CpuSocketNum,cores=$(($CpuCoreNum / $CpuSocketNum)),threads=$(($CpuCount / $CpuCoreNum / $CpuSocketNum)) -m ${use}G -net user,hostfwd=tcp::3389-:3389 -display vnc=:5 -display gtk -usb -nic model=rtl8139 $qemuUEFI
exit
fi
zenity --question --no-wrap --text="检查到您未创建所指定的虚拟机,是否创建虚拟机并继续?\n如果不创建将无法使用"
diff --git a/VM-source/.qtc_clangd/compile_commands.json b/VM-source/.qtc_clangd/compile_commands.json
index 3292efd..458bd83 100644
--- a/VM-source/.qtc_clangd/compile_commands.json
+++ b/VM-source/.qtc_clangd/compile_commands.json
@@ -7,7 +7,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -77,7 +77,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -147,7 +147,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -217,7 +217,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -287,7 +287,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -357,7 +357,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -427,7 +427,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -497,7 +497,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -567,7 +567,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -637,7 +637,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -707,7 +707,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -777,7 +777,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -847,7 +847,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -917,7 +917,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -987,7 +987,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -1057,77 +1057,7 @@
"-I",
"/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
"-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
- "-nostdinc",
- "-nostdinc++",
- "-pipe",
- "-std=gnu++11",
- "-Wall",
- "-Wextra",
- "-D_REENTRANT",
- "-fPIC",
- "-fsyntax-only",
- "-m64",
- "--target=x86_64-linux-gnu",
- "-DQ_CREATOR_RUN",
- "-DQT_DEPRECATED_WARNINGS",
- "-DQT_NO_DEBUG",
- "-DQT_WIDGETS_LIB",
- "-DQT_GUI_LIB",
- "-DQT_NETWORK_LIB",
- "-DQT_CORE_LIB",
- "-I",
- "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source",
- "-I",
- "/usr/include/x86_64-linux-gnu/qt5",
- "-I",
- "/usr/include/x86_64-linux-gnu/qt5/QtWidgets",
- "-I",
- "/usr/include/x86_64-linux-gnu/qt5/QtGui",
- "-I",
- "/usr/include/x86_64-linux-gnu/qt5/QtNetwork",
- "-I",
- "/usr/include/x86_64-linux-gnu/qt5/QtCore",
- "-I",
- "/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++",
- "-isystem",
- "/usr/include/c++/11",
- "-isystem",
- "/usr/include/x86_64-linux-gnu/c++/11",
- "-isystem",
- "/usr/include/c++/11/backward",
- "-isystem",
- "/usr/local/include",
- "-isystem",
- "/usr/lib/llvm-13/lib/clang/13.0.1/include",
- "-isystem",
- "/usr/include/x86_64-linux-gnu",
- "-isystem",
- "/usr/include",
- "-fmessage-length=0",
- "-fdiagnostics-show-note-include-stack",
- "-fretain-comments-from-system-headers",
- "-fmacro-backtrace-limit=0",
- "-ferror-limit=1000",
- "-x",
- "c++-header",
- "-Wno-unknown-pragmas",
- "-Wno-unknown-warning-option",
- "-Wno-documentation-unknown-command",
- "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/ui_qemusetting.h"
- ],
- "directory": "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/.qtc_clangd",
- "file": "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/ui_qemusetting.h"
-},
-{
- "arguments": [
- "clang",
- "-I",
- "/usr/share/qtcreator/cplusplus/wrappedQtHeaders",
- "-I",
- "/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
- "-I",
- "/tmp/QtCreator-xhHVIb/clang-uiheader-riAtqg",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
"-nostdinc",
"-nostdinc++",
"-pipe",
@@ -1188,5 +1118,75 @@
],
"directory": "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/.qtc_clangd",
"file": "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/ui_mainwindow.h"
+},
+{
+ "arguments": [
+ "clang",
+ "-I",
+ "/usr/share/qtcreator/cplusplus/wrappedQtHeaders",
+ "-I",
+ "/usr/share/qtcreator/cplusplus/wrappedQtHeaders/QtCore",
+ "-I",
+ "/tmp/QtCreator-qyPOGG/clang-uiheader-fvNAaR",
+ "-nostdinc",
+ "-nostdinc++",
+ "-pipe",
+ "-std=gnu++11",
+ "-Wall",
+ "-Wextra",
+ "-D_REENTRANT",
+ "-fPIC",
+ "-fsyntax-only",
+ "-m64",
+ "--target=x86_64-linux-gnu",
+ "-DQ_CREATOR_RUN",
+ "-DQT_DEPRECATED_WARNINGS",
+ "-DQT_NO_DEBUG",
+ "-DQT_WIDGETS_LIB",
+ "-DQT_GUI_LIB",
+ "-DQT_NETWORK_LIB",
+ "-DQT_CORE_LIB",
+ "-I",
+ "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source",
+ "-I",
+ "/usr/include/x86_64-linux-gnu/qt5",
+ "-I",
+ "/usr/include/x86_64-linux-gnu/qt5/QtWidgets",
+ "-I",
+ "/usr/include/x86_64-linux-gnu/qt5/QtGui",
+ "-I",
+ "/usr/include/x86_64-linux-gnu/qt5/QtNetwork",
+ "-I",
+ "/usr/include/x86_64-linux-gnu/qt5/QtCore",
+ "-I",
+ "/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++",
+ "-isystem",
+ "/usr/include/c++/11",
+ "-isystem",
+ "/usr/include/x86_64-linux-gnu/c++/11",
+ "-isystem",
+ "/usr/include/c++/11/backward",
+ "-isystem",
+ "/usr/local/include",
+ "-isystem",
+ "/usr/lib/llvm-13/lib/clang/13.0.1/include",
+ "-isystem",
+ "/usr/include/x86_64-linux-gnu",
+ "-isystem",
+ "/usr/include",
+ "-fmessage-length=0",
+ "-fdiagnostics-show-note-include-stack",
+ "-fretain-comments-from-system-headers",
+ "-fmacro-backtrace-limit=0",
+ "-ferror-limit=1000",
+ "-x",
+ "c++-header",
+ "-Wno-unknown-pragmas",
+ "-Wno-unknown-warning-option",
+ "-Wno-documentation-unknown-command",
+ "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/ui_qemusetting.h"
+ ],
+ "directory": "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/.qtc_clangd",
+ "file": "/home/gfdgd_xi/Desktop/deep-wine-runner/VM-source/ui_qemusetting.h"
}
]
\ No newline at end of file
diff --git a/VM-source/mainwindow.cpp b/VM-source/mainwindow.cpp
index 23d72fd..be4eeea 100755
--- a/VM-source/mainwindow.cpp
+++ b/VM-source/mainwindow.cpp
@@ -177,13 +177,29 @@ void MainWindow::on_install_clicked()
}
break;
}
+ QFile file(QDir::homePath() + "/.config/deepin-wine-runner/QEMU-EFI");
+ QDir dir(QDir::homePath() + "/.config/deepin-wine-runner");
switch (ui->systemVersion->currentIndex()) {
case 3:
- if(QFile::exists("/usr/share/qemu/OVMF.fd")){
+ if(!QFile::exists("/usr/share/qemu/OVMF.fd") && !QFile::exists(QCoreApplication::applicationDirPath() + "/OVMF.fd") && ui->vmChooser->currentIndex() == 0){
if(QMessageBox::question(this, "提示", "似乎无法找到 UEFI 固件,是否继续创建虚拟机?\nQemu 固件可以在“安装 Qemu”处安装") == QMessageBox::No){
return;
}
}
+ if(!dir.exists()){
+ dir.mkpath(QDir::homePath() + "/.config/deepin-wine-runner");
+ }
+ if(!QFile::exists(QDir::homePath() + "/.config/deepin-wine-runner/QEMU-EFI")){
+ // 写入用于识别的空文件
+ file.open(QIODevice::WriteOnly);
+ file.write("1");
+ file.close();
+ }
+ break;
+ default:
+ if(ui->vmChooser->currentIndex() == 0 && QFile::exists(QDir::homePath() + "/.config/deepin-wine-runner/QEMU-EFI")){
+ QFile::remove(QDir::homePath() + "/.config/deepin-wine-runner/QEMU-EFI");
+ }
}
buildvbox(ui->isoPath->text(), ui->systemVersion->currentIndex(), ui->vmChooser->currentIndex());
return;
diff --git a/VM-source/mainwindow.ui b/VM-source/mainwindow.ui
index ed51ff9..1adc960 100755
--- a/VM-source/mainwindow.ui
+++ b/VM-source/mainwindow.ui
@@ -86,12 +86,12 @@
-
- 其它 Windows 系统(不支持自动安装,传统启动)
+ 其它 Windows 系统(不支持自动安装,传统启动,推荐 Windows 7 及以下)
-
- 其他 Windows 系统(不支持自动安装,UEFI 启动)
+ 其他 Windows 系统(不支持自动安装,UEFI 启动,推荐 Windows 8 及以上)
diff --git a/VM-source/qemu.cpp b/VM-source/qemu.cpp
index aba4d13..8a903e2 100644
--- a/VM-source/qemu.cpp
+++ b/VM-source/qemu.cpp
@@ -120,8 +120,16 @@ int qemu::OpenUSB(){
return 0;
}
int qemu::EnabledUEFI(bool status){
- if(status){
- commandOption += "--bios /usr/share/qemu/OVMF.fd ";
+ if(!status){
+ return 0;
}
- return 0;
+ if(QFile::exists("/usr/share/qemu/OVMF.fd")){
+ commandOption += "--bios /usr/share/qemu/OVMF.fd ";
+ return 0;
+ }
+ if(QFile::exists(QCoreApplication::applicationDirPath() + "/OVMF.fd")){
+ commandOption += "--bios '" + QCoreApplication::applicationDirPath() + "/OVMF.fd' ";
+ return 0;
+ }
+ return 1;
}
diff --git a/VM/StartQemu.py b/VM/StartQemu.py
index a6a2d81..85676a2 100644
--- a/VM/StartQemu.py
+++ b/VM/StartQemu.py
@@ -13,7 +13,7 @@ def ReadTXT(file: str):
command = "qemu-system-x86_64"
#if "--kvm" in sys.argv:
# command = "kvm"
-
+programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
homePath = os.path.expanduser('~')
try:
setting = json.loads(ReadTXT(f"{homePath}/.config/deepin-wine-runner/QemuSetting.json"))
@@ -30,4 +30,9 @@ if setting["EnableVNC"]:
option += f"-display gtk -display vnc=:{setting['VNC']} "
if setting["EnableSound"]:
option += "-soundhw all "
+if os.path.exists(f"{homePath}/.config/deepin-wine-runner/QEMU-EFI"):
+ if os.path.exists("/usr/share/qemu/OVMF.fd"):
+ option += "--bios /usr/share/qemu/OVMF.fd "
+ elif os.path.exists(f"{programPath}/OVMF.fd"):
+ option += f"--bios {programPath}/OVMF.fd "
os.system(f"{command} {option}")