新增添加Qemu镜像功能

This commit is contained in:
2023-04-28 21:43:14 +08:00
parent 73551e9a12
commit 0d3e798644
4 changed files with 80 additions and 11 deletions

View File

@@ -20,6 +20,7 @@
#include <QJsonArray>
#include <QDesktopServices>
#include <QMessageBox>
#include <iostream>
#include "qemusetting.h"
MainWindow::MainWindow(QWidget *parent) :
@@ -201,3 +202,35 @@ void MainWindow::on_qemuSetting_clicked()
show->show();
}
void MainWindow::on_addQemuDisk_triggered()
{
if(QFile::exists(QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
if(QMessageBox::question(this, "提示", "磁盘文件已存在,是否覆盖?\n覆盖后将无法恢复!") == QMessageBox::No){
return;
}
}
QString path = QFileDialog::getOpenFileName(this, "选择 Qemu 镜像", QDir::homePath(), "Qemu镜像(*.qcow2 *.img *.raw *.qcow *.qed *.vdi *.vhdx *.vmdk);;所有文件(*.*)");
qDebug() << path;
if(path == ""){
return;
}
QDir dir(QDir::homePath() + "/Qemu/Windows/Windows.qcow2");
if(!dir.exists()){
dir.mkpath(QDir::homePath() + "/Qemu/Windows/Windows.qcow2");
}
if(!QFile::remove(QDir::homePath() + "/Qemu/Windows/Windows.qcow2") | !QFile::copy(path, QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
QMessageBox::critical(this, "提示", "添加错误!");
return;
}
QMessageBox::information(this, "提示", "添加完成!");
}
void MainWindow::on_delQemuDisk_triggered()
{
if(!QFile::exists(QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
QMessageBox::information(this, "提示", "不存在磁盘文件,无法导出");
return;
}
std::system(("xdg-open \"" + QDir::homePath() + "/Qemu/Windows/\"").toUtf8());
}