diff --git a/src/demodialog.cpp b/src/demodialog.cpp index 32be316..64c2ec7 100644 --- a/src/demodialog.cpp +++ b/src/demodialog.cpp @@ -1,19 +1,32 @@ #include "demodialog.h" #include "mainwindow.h" -demodialog::demodialog(QStringList iwad_list, QWidget *parent) - : QDialog(parent) +demodialog::demodialog(QString missing_iwad, QStringList missing_files, QWidget *parent) : QDialog(parent) { QGridLayout *mainLayout = new QGridLayout; - QLabel *description = new QLabel("No footer found on the demo.\nPlease select the correct files.\n"); + QLabel *description; + if (missing_iwad.isEmpty() && missing_files.isEmpty()) + { + description = new QLabel("No footer found on the demo.\n"); + } + else + { + description = new QLabel(""); + if (!missing_iwad.isEmpty()) description->setText("Demo IWAD not found.\n"); + if (!missing_files.isEmpty()) description->setText(description->text() + "Demo PWADs/DEHs not found.\n"); + } mainLayout->addWidget(description, 0, 0, 1, 3); QLabel *iwad_label = new QLabel("IWAD:"); mainLayout->addWidget(iwad_label, 1, 0); iwad_comboBox = new QComboBox(); - iwad_comboBox->addItems(iwad_list); + QFileInfoList IWADs = findIwads(); + for (int i = 0; i < IWADs.count(); i++) + { + iwad_comboBox->addItem(IWADs[i].baseName().toLower()); + } mainLayout->addWidget(iwad_comboBox, 1, 1, 1, 2); QLabel *files_label = new QLabel("Files:"); diff --git a/src/demodialog.h b/src/demodialog.h index 1364cc2..55f3014 100644 --- a/src/demodialog.h +++ b/src/demodialog.h @@ -1,25 +1,26 @@ #ifndef DEMODIALOG_H #define DEMODIALOG_H +#include "funcs.h" +#include #include -#include +#include +#include #include -#include +#include #include -#include #include -#include +#include #include -#include class demodialog : public QDialog { Q_OBJECT public: - explicit demodialog(QStringList iwad_list, QWidget *parent = nullptr); - int get_iwad_index(); - QStringList get_files_list(); + explicit demodialog(QString missing_iwad, QStringList missing_files, QWidget *parent = nullptr); + int get_iwad_index(); + QStringList get_files_list(); private: QComboBox *iwad_comboBox; diff --git a/src/funcs.cpp b/src/funcs.cpp index 9b13e9a..98b2de6 100644 --- a/src/funcs.cpp +++ b/src/funcs.cpp @@ -22,6 +22,8 @@ QString getFileName(QString filePath) QString getFilePath(QString fileName) { + fileName = fileName.toLower(); + // Find file in dsda folder QString dsda_folder; #ifdef _WIN32 @@ -86,4 +88,89 @@ QString getFilePath(QString fileName) return ""; } +QString removeExtension(QString fileName) +{ + int dot_pos = fileName.lastIndexOf('.'); + if (dot_pos == -1) return fileName; + + return fileName.left(dot_pos); +} + +QString getExtension(QString fileName) +{ + int dot_pos = fileName.lastIndexOf('.'); + if (dot_pos == -1) return ""; + + return fileName.mid(dot_pos + 1); +} + +QFileInfoList findIwads_possibleFiles() +{ + QFileInfoList possible_files; + QString doomwaddirstr = QString(qgetenv("DOOMWADDIR")); + +// Find the IWADs in the correct folder depending on the OS +#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) + if (!QDir(dotfolder).exists()) QDir().mkdir(dotfolder); + +// Copies dsda-doom.wad to the dotfolder +#if defined(Q_OS_MAC) + QProcess::startDetached("cp", {launcherFolderPath + "/../Resources/" + gameName + ".wad", dotfolder}); +#endif + + QDir directory(dotfolder); + + doomwaddirstr = doomwaddirstr.split(":")[0]; + +#elif defined(Q_OS_WIN) + QDir directory(execPath); + + doomwaddirstr = doomwaddirstr.split(";")[0]; +#endif + + possible_files = directory.entryInfoList(QStringList() << "*.WAD", QDir::Files); + + QDir doomwaddir(doomwaddirstr); + possible_files += doomwaddir.entryInfoList(QStringList() << "*.WAD", QDir::Files); + + int size = settings->beginReadArray("iwadfolders"); + for (int i = 0; i < size; i++) + { + settings->setArrayIndex(i); + QString folder = settings->value("folder").toString(); + if (!folder.isEmpty()) + { + possible_files += QDir(folder).entryInfoList(QStringList() << "*.WAD", QDir::Files); + } + } + settings->endArray(); + + return possible_files; +} + +QFileInfoList findIwads() +{ + QFileInfoList ret; + QFileInfoList possible_files = findIwads_possibleFiles(); + + // This makes sure that a logical order to display the IWADs is followed + // I think doing this is better than having random orders like: Doom 2 -> TNT -> Doom + QStringList IWADS = exmxIWADS + mapxxIWADS; + + for (int i = 0; i < IWADS.size(); i++) + { + for (QFileInfo &fileInfo : possible_files) + { + QString file_name = fileInfo.baseName().toLower(); + if (IWADS[i] == file_name) + { + ret.append(fileInfo); + break; + } + } + } + + return ret; +} + QStringList parseStringIntoArguments(QString line) { return QProcess::splitCommand(line); } diff --git a/src/funcs.h b/src/funcs.h index cfe9d93..5aeb28a 100644 --- a/src/funcs.h +++ b/src/funcs.h @@ -15,5 +15,8 @@ void openIWADsFolder(); QString getFileName(QString filePath); QString getFilePath(QString fileName); QStringList parseStringIntoArguments(QString line); +QString removeExtension(QString fileName); +QString getExtension(QString fileName); +QFileInfoList findIwads(); #endif // FUNCS_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 42ed438..4043987 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -95,7 +95,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi QShortcut *shortcut3 = new QShortcut(QKeySequence(Qt::Key_W | Qt::CTRL), this, SLOT(close())); shortcut3->setAutoRepeat(false); - findIwads(); + QFileInfoList IWADs = findIwads(); + for (int i = 0; i < IWADs.count(); i++) + { + ui->iwad_comboBox->addItem(IWADs[i].baseName().toLower()); + ui->iwad_comboBox->setItemData(ui->iwad_comboBox->count() - 1, IWADs[i].absoluteFilePath(), Qt::ToolTipRole); + } + + // If no IWAD found, show a tool tip + if (ui->iwad_comboBox->count() == 0) ui->tooltip_textBrowser->show(); + else ui->tooltip_textBrowser->hide(); loadSelected(); @@ -258,73 +267,59 @@ void MainWindow::dropLmp(QString filePath) QTextStream stream(&file); QString buffer; - bool found_footer = false; + bool openDemoDialog = true; + QString missing_iwad = ""; + QStringList missing_files; + while (stream.readLineInto(&buffer)) { - if (buffer.mid(0, 5) == "-iwad") + if (buffer.left(5) == "-iwad") { - found_footer = true; + openDemoDialog = false; ui->wads_listWidget->clear(); - QStringList argList; - QString tmp; - for (qsizetype i = 0; i < buffer.size(); i++) - { - if (buffer[i] != ' ' && buffer[i] != '\"') - { - tmp += buffer[i]; - } - else if (!tmp.isEmpty()) - { - argList.push_back(tmp); - tmp.clear(); - } - } - if (!tmp.isEmpty()) - { - argList.push_back(tmp); - tmp.clear(); - } + QStringList args = QProcess::splitCommand(buffer); - for (int i = 0; i < argList.count() - 1; i++) + for (int i = 0; i < args.count() - 1; i++) { - if (argList[i] == "-iwad") + if (args[i] == "-iwad") { - int iwad_dot_pos = argList[i + 1].lastIndexOf('.'); - iwad_dot_pos = iwad_dot_pos == -1 ? argList[i + 1].size() : iwad_dot_pos; - - int iwad_index = ui->iwad_comboBox->findText(argList[i + 1].left(iwad_dot_pos)); + int iwad_index = ui->iwad_comboBox->findText(removeExtension(args[i + 1]).toLower()); if (iwad_index != -1) { ui->iwad_comboBox->setCurrentIndex(iwad_index); } + else + { + missing_iwad = args[i + 1]; + openDemoDialog = true; + } } - else if (argList[i] == "-file" || argList[i] == "-deh") + else if (args[i] == "-file" || args[i] == "-deh") { - QStringList files; - for (int ii = i + 1; ii < argList.count(); ii++) + for (i = i + 1; i < args.count(); i++) { - if (argList[ii].size() < 2 || argList[ii][0] == '-') + qDebug() << 1 << args[i]; + if (args[i].size() < 2 || args[i][0] == '-') { break; } - QString tmp = argList[ii].toLower(); - // Some old Woof demos don't have the .wad extension on the footer - int file_dot_pos = tmp.lastIndexOf('.'); - if (file_dot_pos == -1) tmp += ".wad"; - - files.append(tmp); - } - - for (int i = 0; i < files.count(); i++) - { - QString filePath = getFilePath(files[i]); - if (filePath.isEmpty()) continue; + int file_dot_pos = args[i].lastIndexOf('.'); + if (file_dot_pos == -1) args[i] += ".wad"; - ui->wads_listWidget->addItem(getFileName(filePath)); - ui->wads_listWidget->item(ui->wads_listWidget->count() - 1)->setToolTip(filePath); + QString filePath = getFilePath(args[i]); + if (filePath.isEmpty()) + { + missing_files.append(args[i]); + openDemoDialog = true; + } + else + { + ui->wads_listWidget->addItem(getFileName(filePath)); + ui->wads_listWidget->item(ui->wads_listWidget->count() - 1)->setToolTip(filePath); + } } } } @@ -333,14 +328,9 @@ void MainWindow::dropLmp(QString filePath) file.close(); - if (!found_footer) + if (openDemoDialog) { - QStringList iwad_list; - for (int i = 0; i < ui->iwad_comboBox->count(); i++) - { - iwad_list.push_back(ui->iwad_comboBox->itemText(i)); - } - demodialog *demoDialogNew = new demodialog(iwad_list, this); + demodialog *demoDialogNew = new demodialog(missing_iwad, missing_files, this); demoDialogNew->open(); demoDialog = demoDialogNew; diff --git a/src/mainwindow.h b/src/mainwindow.h index 2929c20..d03ce2a 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -136,7 +136,6 @@ public slots: void setResolutionsList(QListWidget *list); void dropFile(QString fileName); void dropLmp(QString filePath); - void findIwads(); void changeExeName(QString newName); void setToggles(QString t1, QString a1, QString t2, QString a2, QString t3, QString a3, QString t4, QString a4); void whenAnimationFinishNext(); @@ -169,7 +168,6 @@ private slots: void on_hud_pushButton_clicked(); void on_config_pushButton_clicked(); void on_playback_lineEdit_textChanged(const QString &arg1); - QFileInfoList findIwads_possibleFiles(); void loadSelected(); void saveSelected(); void setStyles(); diff --git a/src/mainwindow_top.cpp b/src/mainwindow_top.cpp index 8bf9217..3d388a1 100644 --- a/src/mainwindow_top.cpp +++ b/src/mainwindow_top.cpp @@ -1,76 +1,5 @@ #include "mainwindow.h" -QFileInfoList MainWindow::findIwads_possibleFiles() -{ - QFileInfoList possible_files; - QString doomwaddirstr = QString(qgetenv("DOOMWADDIR")); - -// Find the IWADs in the correct folder depending on the OS -#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) - if (!QDir(dotfolder).exists()) QDir().mkdir(dotfolder); - -// Copies dsda-doom.wad to the dotfolder -#if defined(Q_OS_MAC) - QProcess::startDetached("cp", {launcherFolderPath + "/../Resources/" + gameName + ".wad", dotfolder}); -#endif - - QDir directory(dotfolder); - - doomwaddirstr = doomwaddirstr.split(":")[0]; - -#elif defined(Q_OS_WIN) - QDir directory(execPath); - - doomwaddirstr = doomwaddirstr.split(";")[0]; -#endif - - possible_files = directory.entryInfoList(QStringList() << "*.WAD", QDir::Files); - - QDir doomwaddir(doomwaddirstr); - possible_files += doomwaddir.entryInfoList(QStringList() << "*.WAD", QDir::Files); - - int size = settings->beginReadArray("iwadfolders"); - for (int i = 0; i < size; i++) - { - settings->setArrayIndex(i); - QString folder = settings->value("folder").toString(); - if (!folder.isEmpty()) - { - possible_files += QDir(folder).entryInfoList(QStringList() << "*.WAD", QDir::Files); - } - } - settings->endArray(); - - return possible_files; -} - -void MainWindow::findIwads() -{ - QFileInfoList possible_files = findIwads_possibleFiles(); - - // This makes sure that a logical order to display the IWADs is followed - // I think doing this is better than having random orders like: Doom 2 -> TNT -> Doom - QStringList IWADS = exmxIWADS + mapxxIWADS; - - for (int i = 0; i < IWADS.size(); i++) - { - for (QFileInfo &fileInfo : possible_files) - { - QString file_name = fileInfo.baseName().toLower(); - if (IWADS[i] == file_name) - { - ui->iwad_comboBox->addItem(file_name); - ui->iwad_comboBox->setItemData(ui->iwad_comboBox->count() - 1, fileInfo.absoluteFilePath(), Qt::ToolTipRole); - break; - } - } - } - - // If no IWAD found, show a tool tip - if (ui->iwad_comboBox->count() == 0) ui->tooltip_textBrowser->show(); - else ui->tooltip_textBrowser->hide(); -} - // If the IWAD selected changes void MainWindow::on_iwad_comboBox_currentIndexChanged(int index) { diff --git a/src/settings.cpp b/src/settings.cpp index 0aab0ed..98a3f67 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -2,9 +2,7 @@ #include "ui_settings.h" #include -Settings::Settings(QWidget *parent) : - QWidget(parent), - ui(new Ui::Settings) +Settings::Settings(QWidget *parent) : QWidget(parent), ui(new Ui::Settings) { ui->setupUi(this);