新增架构检测

This commit is contained in:
gfdgd xi 2023-02-19 15:43:24 +08:00
parent 4632417414
commit 6b5c514760
11 changed files with 60 additions and 15 deletions

Binary file not shown.

View File

@ -37,6 +37,13 @@ QString buildvbox::GetNet(){
} }
buildvbox::buildvbox(QString isoPath, int id){ buildvbox::buildvbox(QString isoPath, int id){
/*QDir vboxPath(QDir::homePath() + "/VirtualBox VMs/Windows");
if(vboxPath.exists()){
qDebug("虚拟机存在,直接启动!");
vbox vm("Windows");
vm.Start();
return;
}*/
QString programPath = QCoreApplication::applicationDirPath(); QString programPath = QCoreApplication::applicationDirPath();
QString net = GetNet(); QString net = GetNet();
qDebug() << "使用网卡:" << net << endl; qDebug() << "使用网卡:" << net << endl;

View File

@ -2,6 +2,18 @@
#include <QApplication> #include <QApplication>
#include <QTranslator> #include <QTranslator>
#include <QCoreApplication> #include <QCoreApplication>
#include <QProcess>
#include <QMessageBox>
QString GetRunCommand(QString command){
QProcess process;
process.start(command);
process.waitForStarted();
process.waitForFinished();
QString re = process.readAllStandardOutput();
process.close();
return re;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -11,6 +23,11 @@ int main(int argc, char *argv[])
trans->load("virtualmachine-en_US.qm"); trans->load("virtualmachine-en_US.qm");
a.installTranslator(trans); a.installTranslator(trans);
// 判断是否为 !amd64
if(GetRunCommand("arch").replace(" ", "").replace("\n", "") == QString("x86_64")){
QMessageBox::critical(NULL, "错误", "此程序不支持非 X86 架构,立即退出");
return 0;
}
MainWindow w; MainWindow w;
w.show(); w.show();

Binary file not shown.

View File

@ -21,7 +21,24 @@ MainWindow::MainWindow(QWidget *parent) :
ui->tabWidget->setTabPosition(QTabWidget::West); // 标签靠左 ui->tabWidget->setTabPosition(QTabWidget::West); // 标签靠左
// 允许输出 qDebug 信息 // 允许输出 qDebug 信息
QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, true); QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, true);
// 判断是否安装 vbox
if(system("which VBoxManage")){
if(QMessageBox::question(NULL, "提示", "检测到您似乎没有安装 VirtualBox立即安装") == QMessageBox::Yes){
system("xdg-open https://www.virtualbox.org/wiki/Linux_Downloads");
} }
}
}
QString MainWindow::GetRunCommand(QString command){
QProcess process;
process.start(command);
process.waitForStarted();
process.waitForFinished();
QString re = process.readAllStandardOutput();
process.close();
return re;
}
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {

View File

@ -17,7 +17,7 @@ public:
private slots: private slots:
void on_browser_clicked(); void on_browser_clicked();
QString GetRunCommand(QString command);
void on_install_clicked(); void on_install_clicked();
private: private:

Binary file not shown.

View File

@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_MainWindow_t { struct qt_meta_stringdata_MainWindow_t {
QByteArrayData data[4]; QByteArrayData data[6];
char stringdata0[50]; char stringdata0[72];
}; };
#define QT_MOC_LITERAL(idx, ofs, len) \ #define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@ -35,11 +35,13 @@ static const qt_meta_stringdata_MainWindow_t qt_meta_stringdata_MainWindow = {
QT_MOC_LITERAL(0, 0, 10), // "MainWindow" QT_MOC_LITERAL(0, 0, 10), // "MainWindow"
QT_MOC_LITERAL(1, 11, 18), // "on_browser_clicked" QT_MOC_LITERAL(1, 11, 18), // "on_browser_clicked"
QT_MOC_LITERAL(2, 30, 0), // "" QT_MOC_LITERAL(2, 30, 0), // ""
QT_MOC_LITERAL(3, 31, 18) // "on_install_clicked" QT_MOC_LITERAL(3, 31, 13), // "GetRunCommand"
QT_MOC_LITERAL(4, 45, 7), // "command"
QT_MOC_LITERAL(5, 53, 18) // "on_install_clicked"
}, },
"MainWindow\0on_browser_clicked\0\0" "MainWindow\0on_browser_clicked\0\0"
"on_install_clicked" "GetRunCommand\0command\0on_install_clicked"
}; };
#undef QT_MOC_LITERAL #undef QT_MOC_LITERAL
@ -49,7 +51,7 @@ static const uint qt_meta_data_MainWindow[] = {
8, // revision 8, // revision
0, // classname 0, // classname
0, 0, // classinfo 0, 0, // classinfo
2, 14, // methods 3, 14, // methods
0, 0, // properties 0, 0, // properties
0, 0, // enums/sets 0, 0, // enums/sets
0, 0, // constructors 0, 0, // constructors
@ -57,11 +59,13 @@ static const uint qt_meta_data_MainWindow[] = {
0, // signalCount 0, // signalCount
// slots: name, argc, parameters, tag, flags // slots: name, argc, parameters, tag, flags
1, 0, 24, 2, 0x08 /* Private */, 1, 0, 29, 2, 0x08 /* Private */,
3, 0, 25, 2, 0x08 /* Private */, 3, 1, 30, 2, 0x08 /* Private */,
5, 0, 33, 2, 0x08 /* Private */,
// slots: parameters // slots: parameters
QMetaType::Void, QMetaType::Void,
QMetaType::QString, QMetaType::QString, 4,
QMetaType::Void, QMetaType::Void,
0 // eod 0 // eod
@ -74,11 +78,12 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
(void)_t; (void)_t;
switch (_id) { switch (_id) {
case 0: _t->on_browser_clicked(); break; case 0: _t->on_browser_clicked(); break;
case 1: _t->on_install_clicked(); break; case 1: { QString _r = _t->GetRunCommand((*reinterpret_cast< QString(*)>(_a[1])));
if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = std::move(_r); } break;
case 2: _t->on_install_clicked(); break;
default: ; default: ;
} }
} }
(void)_a;
} }
QT_INIT_METAOBJECT const QMetaObject MainWindow::staticMetaObject = { { QT_INIT_METAOBJECT const QMetaObject MainWindow::staticMetaObject = { {
@ -110,13 +115,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0) if (_id < 0)
return _id; return _id;
if (_c == QMetaObject::InvokeMetaMethod) { if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 2) if (_id < 3)
qt_static_metacall(this, _c, _id, _a); qt_static_metacall(this, _c, _id, _a);
_id -= 2; _id -= 3;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 2) if (_id < 3)
*reinterpret_cast<int*>(_a[0]) = -1; *reinterpret_cast<int*>(_a[0]) = -1;
_id -= 2; _id -= 3;
} }
return _id; return _id;
} }

Binary file not shown.

View File

@ -41,7 +41,6 @@ int vbox::SetCPU(int number){
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --cpus " + QString::number(number)).toLatin1()); return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --cpus " + QString::number(number)).toLatin1());
} }
int vbox::SetMemory(int memory){ int vbox::SetMemory(int memory){
QMessageBox::information(NULL, "", ("\"" + managerPath + "\" modifyvm \"" + name + "\" --memory " + QString::number(memory)).toLatin1());
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --memory " + QString::number(memory)).toLatin1()); return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --memory " + QString::number(memory)).toLatin1());
} }
int vbox::SetRemote(bool setting){ int vbox::SetRemote(bool setting){

Binary file not shown.