diff --git a/mainwindow.cpp b/mainwindow.cpp index fdff6cd..97859ce 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -16,9 +16,15 @@ #include <QJsonObject> #include <QFile> #include <QProcess> +#include <QMessageBox> +#include <QObject> using namespace std; QComboBox *MainWindow::e1; +QComboBox *MainWindow::e2; +QComboBox *MainWindow::o1; QMap<QString, QString> MainWindow::setting; +QMap<QString, QString> MainWindow::wine; +QString MainWindow::lastRunCommand = ""; MainWindow::MainWindow(){ /********* * 设置变量 @@ -201,22 +207,115 @@ MainWindow::MainWindow(){ } QObject::connect(button3, &QPushButton::clicked, [&](){ Runexebutton_threading *thread = new Runexebutton_threading(); + //QObject::connect(thread, &Runexebutton_threading::signal, this, [this](){}); thread->start(); }); } void MainWindow::Runexebutton_threading::run(){ + QString programPath = QCoreApplication::applicationDirPath(); + QString wineBottlePath = ""; if(e1->currentText() == ""){ - QString wineBottlePath = setting.value("DefultBotton"); + wineBottlePath = setting.value("DefultBotton"); } else{ - QString wineBottlePath = e1->currentText(); + wineBottlePath = e1->currentText(); } QString option = ""; if(setting.value("Architecture") != "Auto"){ - QString option = option + "WINEARCH=" + setting.value("Architecture") + " "; + option += "WINEARCH=" + setting.value("Architecture") + " "; } + if(setting.value("MonoGeckoInstaller") == "1"){ + option += "WINEDLLOVERRIDES=\"mscoree,mshtml=\" "; + } + if(setting.value("") != "1"){ + option += "WINEDEBUG=-all "; + } + else{ + option += "WINEDEBUG=FIXME,ERR,WARN,TRACE,Message "; + } + QString wineUsingOption = ""; + QString exePath = e2->currentText(); + QStringList fileName = {".exe"}; + bool changePath = false; + for(QString i: fileName){ + if(exePath.contains(i)){ + qDebug() << i; + qDebug() << exePath; + int l = exePath.indexOf(i); + exePath = exePath.mid(0, l + 4) + "' " + exePath.mid(l + 4) + " '"; + qDebug() << l; + qDebug() << exePath; + changePath = true; + break; + } + } + if(!changePath && QFile::exists(exePath)){ + // 删除前后无用空格以防止出现问题 + qDebug() << exePath; + exePath = exePath.trimmed(); + // 有空格再说 + if(exePath.contains(" ")){ + int l = exePath.indexOf(" "); + exePath = exePath.mid(0, l) + "' " + exePath.mid(l) + " '"; + qDebug() << l; + } + qDebug() << exePath; + } + if(o1->currentText() == "基于 UOS exagear 的 deepin-wine6-stable" || + o1->currentText() == "基于 UOS box86 的 deepin-wine6-stable"){ + wineUsingOption = ""; + } + if(o1->currentText() == "基于 UOS box86 的 deepin-wine6-stable" || + o1->currentText() == "基于 UOS exagear 的 deepin-wine6-stable"){ + if(!QDir(programPath + "/dlls-arm").exists()){ + if(system(("7z x -y \"" + programPath + "/dlls-arm.7z\" -o\"" + programPath + "\"").toUtf8())){ + QMessageBox::critical(NULL, "错误", "无法解压资源"); + return; + } + QFile::remove(programPath + "/dlls-arm.7z"); + } + } + //QString runCommand = ""; + QString runCommand = ""; + QProcess *process = new QProcess(); + //if(setting.value("TerminalOpen") == "True"){ + if(0){ + if(e2->currentText().mid(-4) == ".msi" && QFile::exists(e2->currentText())){ + runCommand = "env WINEPREFIX='" + wineBottlePath + "' " + option + wine[o1->currentText()] + " msiexec /i '" + e2->currentText() + "' " + setting.value("WineOption"); + // OpenTerminal(runCommand) + } + // …… + } + else{ + if(e2->currentText().mid(-4) == ".msi" && QFile::exists(e2->currentText())){ + runCommand = "env WINEPREFIX='" + wineBottlePath + "' " + option + wine[o1->currentText()] + " msiexec /i '" + e2->currentText() + "' " + setting.value("WineOption"); + } + else if(e2->currentText().mid(-4) == ".bat" && QFile::exists(e2->currentText())){ + runCommand = "WINEPREFIX='" + wineBottlePath + "' " + option + wine[o1->currentText()] + " wineconsole '" + e2->currentText() + "' " + setting["WineOption"]; + } + else{ + runCommand = "WINEPREFIX='" + wineBottlePath + "' " + option + wine[o1->currentText()] + " '" + exePath + "' " + setting["WineOption"]; + } + + } + // 实时读取程序返回 + qDebug() << runCommand; + lastRunCommand = runCommand; + // 连接槽 + connect(process, &QProcess::readyReadStandardOutput, this, [this, process](){ + //emit this->signal(QString::fromUtf8(process.readAll())); + }); + //if(setting.value("TerminalOpen") != "True"){ + if(1){ + process->setReadChannel(QProcess::StandardOutput); + process->start(runCommand); + process->waitForStarted(); + process->waitForFinished(); + process->close(); + } + // …… } void MainWindow::DisableButton(bool things){ diff --git a/mainwindow.h b/mainwindow.h index 5abec91..03096e8 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -32,10 +32,10 @@ private: }; void runexebutton(); void DisableButton(bool things); - QString lastRunCommand = ""; + static QString lastRunCommand; QString homePath = QDir::homePath(); QString programPath = QCoreApplication::applicationDirPath(); - QMap<QString, QString> wine; + static QMap<QString, QString> wine; QStringList untipsWine = {"使用 Flatpak 安装的 Wine", "基于 exagear 的 deepin-wine6-stable", "基于 UOS box86 的 deepin-wine6-stable", "基于 UOS exagear 的 deepin-wine6-stable", "基于 linglong 的 deepin-wine6-stable(不推荐)"}; QStringList canUseWine = {}; QStringList qemuBottleList = {}; @@ -57,8 +57,8 @@ private: QPushButton *uninstallProgram; QPushButton *trasButton; static QComboBox *e1; - QComboBox *e2; - QComboBox *o1; + static QComboBox *e2; + static QComboBox *o1; }; diff --git a/mainwindow.ui b/mainwindow.ui index e727f0d..5975f9e 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -14,23 +14,9 @@ <string>MainWindow</string> </property> <widget class="QWidget" name="window"> - <layout class="QGridLayout" name="gridLayout" rowstretch="2,0" columnstretch="2,0,0"> + <layout class="QGridLayout" name="gridLayout" rowstretch="2,0" columnstretch="2,0"> <item row="0" column="0"> - <widget class="QWidget" name="leftUp" native="true"> - <widget class="QPushButton" name="pushButton"> - <property name="geometry"> - <rect> - <x>210</x> - <y>120</y> - <width>106</width> - <height>36</height> - </rect> - </property> - <property name="text"> - <string>PushButton</string> - </property> - </widget> - </widget> + <widget class="QWidget" name="leftUp" native="true"/> </item> <item row="0" column="1"> <widget class="QTextBrowser" name="returnText"> diff --git a/qr.ui b/qr.ui index 15539ad..357c971 100644 --- a/qr.ui +++ b/qr.ui @@ -25,8 +25,7 @@ <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Noto Sans CJK SC'; font-size:10.5pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">如果您觉得 Wine 运行器对您有帮助,可以请作者吃点零食</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">(本来想说喝一杯咖啡的,但我不喝啊)</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:11pt;">如果您觉得 Wine 运行器对你有帮助,可以请作者喝杯茶</span></p> <hr /> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">微信:</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/Icon/QR/Icon/QR/Wechat.png" width="256" /></p>