From fd78edd2f76a3745a50a7fda5ce45683ed915ec5 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Sat, 8 Apr 2023 11:57:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=89=E8=A3=85qemu/vbox?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 ++ Model/__init__.py | 1 + QemuSystemInstall.sh | 4 ++++ RunCommandWithTerminal.py | 10 ++++++++++ VM-source/Makefile | 3 +++ VM-source/mainwindow.cpp | 19 ++++++++++++++++--- VM-source/mainwindow.h | 4 ++++ VM-source/mainwindow.ui | 16 +++++++++++++++- VM-source/vbox.cpp | 6 +++++- 9 files changed, 60 insertions(+), 5 deletions(-) create mode 100755 QemuSystemInstall.sh create mode 100644 RunCommandWithTerminal.py diff --git a/Makefile b/Makefile index 3b21041..ac2d3c1 100755 --- a/Makefile +++ b/Makefile @@ -38,6 +38,8 @@ package: cp -rv IconList.json deb/opt/apps/deepin-wine-runner cp -rv GetEXEVersion.exe deb/opt/apps/deepin-wine-runner cp -rv MountWithoutHome.sh deb/opt/apps/deepin-wine-runner + cp -rv RunCommandWithTerminal.py deb/opt/apps/deepin-wine-runner + cp -rv QemuSystemInstall.sh deb/opt/apps/deepin-wine-runner echo "[]" > deb/opt/apps/deepin-wine-runner/wine/winelist.json rm -rfv deb/opt/apps/deepin-wine-runner/wine/winelist.json cp -rv req deb/opt/apps/deepin-wine-runner diff --git a/Model/__init__.py b/Model/__init__.py index eee72d3..eac623a 100755 --- a/Model/__init__.py +++ b/Model/__init__.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import os import sys import PyQt5.QtWidgets as QtWidgets diff --git a/QemuSystemInstall.sh b/QemuSystemInstall.sh new file mode 100755 index 0000000..0426c48 --- /dev/null +++ b/QemuSystemInstall.sh @@ -0,0 +1,4 @@ +#!/bin/bash +pkexec apt install qemu-system -y +echo 安装完成!按回车键退出 +read \ No newline at end of file diff --git a/RunCommandWithTerminal.py b/RunCommandWithTerminal.py new file mode 100644 index 0000000..d988f6a --- /dev/null +++ b/RunCommandWithTerminal.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +import sys +from Model import * +if len(sys.argv) < 2: + print("请加入需要的命令") + sys.exit(1) +o = "" +for i in sys.argv[1:]: + o += f"'{i}' " +OpenTerminal(o) \ No newline at end of file diff --git a/VM-source/Makefile b/VM-source/Makefile index 7b212a9..21f37b8 100755 --- a/VM-source/Makefile +++ b/VM-source/Makefile @@ -95,6 +95,7 @@ DIST = /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/spec_pre.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KGuiAddons.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KI18n.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIconThemes.pri \ + /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIdleTime.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOCore.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOFileWidgets.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOGui.pri \ @@ -287,6 +288,7 @@ Makefile: VirtualMachine.pro /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qma /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KGuiAddons.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KI18n.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIconThemes.pri \ + /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIdleTime.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOCore.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOFileWidgets.pri \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOGui.pri \ @@ -459,6 +461,7 @@ Makefile: VirtualMachine.pro /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qma /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KGuiAddons.pri: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KI18n.pri: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIconThemes.pri: +/usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIdleTime.pri: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOCore.pri: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOFileWidgets.pri: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/qt_KIOGui.pri: diff --git a/VM-source/mainwindow.cpp b/VM-source/mainwindow.cpp index 75ab079..2db6254 100755 --- a/VM-source/mainwindow.cpp +++ b/VM-source/mainwindow.cpp @@ -28,12 +28,15 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); ui->tabWidget->setTabPosition(QTabWidget::West); // 标签靠左 // 选择最优虚拟机 - if(!system("which qemu-x86_64")){ + if(!system("which qemu-system-x86_64")){ ui->vmChooser->setCurrentIndex(0); } if(!system("which vboxmanage")){ ui->vmChooser->setCurrentIndex(1); } + if(!QFile::exists(QCoreApplication::applicationDirPath() + "/../RunCommandWithTerminal.py")){ + ui->getQemu->setDisabled(true); + } // 允许输出 qDebug 信息 QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, true); // 判断是否安装 vbox(无需判断) @@ -76,7 +79,7 @@ MainWindow::MainWindow(QWidget *parent) : // 设置程序标题 this->setWindowTitle("Windows 应用适配工具 " + versionValue.toString()); // 读取谢明列表 - ui->textBrowser_2->setHtml("

程序版本号:" + versionValue.toString() + "

" + ui->textBrowser_2->toHtml() + + ui->textBrowser_2->setHtml("

程序版本号:" + versionValue.toString() + ", " + GetRunCommand("arch") + "

" + ui->textBrowser_2->toHtml() + "

谢明列表

" + thankText); connect(ui->textBrowser_2, &QTextBrowser::anchorClicked, this, [=](const QUrl &link){ QDesktopServices::openUrl(link); @@ -156,7 +159,7 @@ void MainWindow::on_install_clicked() { switch (ui->vmChooser->currentIndex()) { case 0: - if(system("which qemu-x86_64")){ + if(system("which qemu-system-x86_64")){ if(QMessageBox::question(this, "提示", "您似乎没有安装 Qemu,是否继续创建虚拟机?") == QMessageBox::No){ return; } @@ -173,3 +176,13 @@ void MainWindow::on_install_clicked() buildvbox(ui->isoPath->text(), ui->systemVersion->currentIndex(), ui->vmChooser->currentIndex()); return; } + +void MainWindow::on_getvbox_clicked() +{ + QDesktopServices::openUrl(QUrl("https://www.virtualbox.org/wiki/Linux_Downloads")); +} + +void MainWindow::on_getQemu_clicked() +{ + system(("python3 '" + QCoreApplication::applicationDirPath() + "/../RunCommandWithTerminal.py' '" + QCoreApplication::applicationDirPath() + "/../QemuSystemInstall.sh'").toLatin1()); +} diff --git a/VM-source/mainwindow.h b/VM-source/mainwindow.h index 063c0c1..13d3dfe 100755 --- a/VM-source/mainwindow.h +++ b/VM-source/mainwindow.h @@ -26,6 +26,10 @@ private slots: void on_install_clicked(); + void on_getvbox_clicked(); + + void on_getQemu_clicked(); + private: Ui::MainWindow *ui; long m_cpuAll; diff --git a/VM-source/mainwindow.ui b/VM-source/mainwindow.ui index 51f79fe..68906d9 100755 --- a/VM-source/mainwindow.ui +++ b/VM-source/mainwindow.ui @@ -145,6 +145,20 @@ + + + + 安装 Qemu + + + + + + + 获取VirtualBox + + + @@ -228,7 +242,7 @@ p, li { white-space: pre-wrap; } <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">3、在这里修改即可</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/picture/截图/截图_VirtualBox_20220712223705.png" /></p> <hr /> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:26pt; font-weight:600;">安装加强功能有什么好处?</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:26pt; font-weight:600;">安装加强功能有什么好处?(只限使用 VirtualBox)</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">1、支持鼠标自由从虚拟机和实体机切换</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2、支持虚拟机根据窗口大小自动设置分辨率</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">3、支持文件共享、剪切板共享、文件拖放</p> diff --git a/VM-source/vbox.cpp b/VM-source/vbox.cpp index 0d2c94c..d9f5847 100644 --- a/VM-source/vbox.cpp +++ b/VM-source/vbox.cpp @@ -13,9 +13,13 @@ vbox::vbox(QString name, QString managerPath) { } int vbox::Create(QString type){ - return system(("\"" + managerPath + "\" createvm --name \"" + system(("\"" + managerPath + "\" createvm --name \"" + name + "\" --ostype \"" + type + "\" --register").toLatin1()); + return system(("\"" + managerPath + "\" modifyvm \"" + + name + "\" --ostype \"" + type + + "\" ").toLatin1()); + //vboxmanage modifyvm testvm --ostype } int vbox::CreateDisk(QString path, int size){ return system(("\"" + managerPath + "\" createvdi --filename \"" + path + "\" --size \"" + QString::number(size) + "\"").toLatin1());