From 81384949e2f3672ecd25797a31fbaa2d842492cd Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Feb 2016 09:34:02 -0800 Subject: Properly check for preexisting HRTF names --- utils/alsoft-config/mainwindow.cpp | 66 ++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 44302e53..81b3a8e8 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -379,23 +379,24 @@ QStringList MainWindow::collectHrtfs() QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name); foreach(const QString &fname, fnames) { - if(fname.endsWith(".mhr", Qt::CaseInsensitive)) + if(!fname.endsWith(".mhr", Qt::CaseInsensitive)) + continue; + + QString name = fname.left(fname.length()-4); + if(!ret.contains(name)) + ret.push_back(name); + else { - if(!ret.contains(fname)) - ret.push_back(fname.left(fname.length()-4)); - else - { - size_t i = 1; - do { - QString s = fname.left(fname.length()-4)+" #"+QString::number(i); - if(!ret.contains(s)) - { - ret.push_back(s); - break; - } - ++i; - } while(1); - } + size_t i = 1; + do { + QString s = name+" #"+QString::number(i); + if(!ret.contains(s)) + { + ret.push_back(s); + break; + } + ++i; + } while(1); } } } @@ -409,23 +410,24 @@ QStringList MainWindow::collectHrtfs() QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name); foreach(const QString &fname, fnames) { - if(fname.endsWith(".mhr", Qt::CaseInsensitive)) + if(!fname.endsWith(".mhr", Qt::CaseInsensitive)) + continue; + + QString name = fname.left(fname.length()-4); + if(!ret.contains(name)) + ret.push_back(name); + else { - if(!ret.contains(fname)) - ret.push_back(fname.left(fname.length()-4)); - else - { - size_t i = 1; - do { - QString s = fname.left(fname.length()-4)+" #"+QString::number(i); - if(!ret.contains(s)) - { - ret.push_back(s); - break; - } - ++i; - } while(1); - } + size_t i = 1; + do { + QString s = name+" #"+QString::number(i); + if(!ret.contains(s)) + { + ret.push_back(s); + break; + } + ++i; + } while(1); } } } -- cgit v1.2.3