Skip to content

Commit

Permalink
Merge pull request #47 from UltraStar-Deluxe/fix-illegal-filenames
Browse files Browse the repository at this point in the history
Fix illegal characters in filenames when saving txt
  • Loading branch information
DeinAlptraum authored Jun 30, 2024
2 parents 48337a4 + 6ae86a2 commit 592df78
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/QUMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include "compact_lang_det.h"
#include "srtparser.h"

std::vector<std::pair<std::string, const char *>> FILENAME_REPLACEMENTS{
std::make_pair(std::string("?:\""), ""),
std::make_pair(std::string("<"), "("),
std::make_pair(std::string(">"), ")"),
std::make_pair(std::string("/\\|*"), "-")};

QUMainWindow::QUMainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::QUMainWindow) {
ui->setupUi(this);

Expand Down Expand Up @@ -375,7 +381,11 @@ void QUMainWindow::initStatusBar() {

bool QUMainWindow::on_pushButton_SaveToFile_clicked()
{
QString suggestedAbsoluteFilePath = QDir::toNativeSeparators(fileInfo_MP3->absolutePath()).append(QDir::separator()).append("%1 - %2.txt").arg(ui->lineEdit_Artist->text(), ui->lineEdit_Title->text());
QString suggestedFileName = QString("%1 - %2.txt").arg(ui->lineEdit_Artist->text(), ui->lineEdit_Title->text());
for (auto repl : FILENAME_REPLACEMENTS)
for (auto in_char : repl.first)
suggestedFileName.replace(in_char, repl.second);
QString suggestedAbsoluteFilePath = QDir::toNativeSeparators(fileInfo_MP3->absolutePath()).append(QDir::separator()).append(suggestedFileName);
QString fileName = QFileDialog::getSaveFileName(this, tr("Please choose file"), suggestedAbsoluteFilePath, tr("Text files (*.txt)"));

if(fileName.isEmpty())
Expand Down

0 comments on commit 592df78

Please sign in to comment.