Skip to content

Commit

Permalink
Better way to get files from demo footer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-Beirao committed May 23, 2024
1 parent 3f5b003 commit 0b96b1a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/demodialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class demodialog : public QDialog
QVector<QPair<QString, QString>> files_paths;
QLabel *selected_count;
void update_selected_count();
void findFiles();
};

#endif // DEMODIALOG_H
Expand Down
53 changes: 53 additions & 0 deletions src/funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,61 @@ QString getFileName(QString filePath)
#endif
}

QFileInfoList getFilePath_possibleFiles()
{
QFileInfoList files;

// Find file in dsda folder
#ifdef Q_OS_WIN
QDir dsda_folder(execPath);
#else
QDir dsda_folder(dotfolder);
#endif

files.append(dsda_folder.entryInfoList(QStringList() << "*.WAD"
<< "*.DEH"
<< "*.BEX",
QDir::Files));

// Find file in DOOMWADPATH
QString doomwadpath = QString(qgetenv("DOOMWADPATH"));
#ifdef _WIN32
QChar token = ';';
#else
QChar token = ':';
#endif
QStringList doomwadpath_folders_list = doomwadpath.split(token);
foreach (QString doomwadpath_folder, doomwadpath_folders_list)
{
files.append(QDir(doomwadpath_folder)
.entryInfoList(QStringList() << "*.WAD"
<< "*.DEH"
<< "*.BEX",
QDir::Files));
}

// Find file in the pwadfolders
int size = settings->beginReadArray("pwadfolders");
for (int j = 0; j < size; j++)
{
settings->setArrayIndex(j);
QString folder = settings->value("folder").toString();
if (!folder.isEmpty())
{
files.append(QDir(folder).entryInfoList(QStringList() << "*.WAD"
<< "*.DEH"
<< "*.BEX",
QDir::Files));
}
}
settings->endArray();

return files;
}

QString getFilePath(QString fileName)
{
getFilePath_possibleFiles();
fileName = fileName.toLower();

// Find file in dsda folder
Expand Down
2 changes: 2 additions & 0 deletions src/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ extern QSettings *settings;

void openIWADsFolder();
QString getFileName(QString filePath);
QFileInfoList getFilePath_possibleFiles();
QString getFilePath(QString fileName);
QStringList parseStringIntoArguments(QString line);
QString removeExtension(QString fileName);
QString getExtension(QString fileName);
QFileInfoList findIwads_possibleFiles();
QFileInfoList findIwads();

#endif // FUNCS_H
21 changes: 13 additions & 8 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ void MainWindow::dropLmp(QString filePath)
}
else if (args[i] == "-file" || args[i] == "-deh")
{
QFileInfoList files = getFilePath_possibleFiles();
for (i = i + 1; i < args.count(); i++)
{
qDebug() << 1 << args[i];
if (args[i].size() < 2 || args[i][0] == '-')
{
break;
Expand All @@ -309,16 +309,21 @@ void MainWindow::dropLmp(QString filePath)
int file_dot_pos = args[i].lastIndexOf('.');
if (file_dot_pos == -1) args[i] += ".wad";

QString filePath = getFilePath(args[i]);
if (filePath.isEmpty())
bool found = false;
for (QFileInfo &file : files)
{
missing_files.append(args[i]);
openDemoDialog = true;
if (file.fileName().toLower() == args[i].toLower())
{
ui->wads_listWidget->addItem(file.fileName());
ui->wads_listWidget->item(ui->wads_listWidget->count() - 1)->setToolTip(file.absoluteFilePath());
found = true;
break;
}
}
else
if (!found)
{
ui->wads_listWidget->addItem(getFileName(filePath));
ui->wads_listWidget->item(ui->wads_listWidget->count() - 1)->setToolTip(filePath);
missing_files.append(args[i]);
openDemoDialog = true;
}
}
}
Expand Down

0 comments on commit 0b96b1a

Please sign in to comment.