diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 47b6f3ac6..4f6344a16 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -714,9 +714,6 @@ void TabDeckEditor::actNewDeck() void TabDeckEditor::actLoadDeck() { - if (!confirmClose()) - return; - QFileDialog dialog(this, tr("Load deck")); dialog.setDirectory(settingsCache->getDeckPath()); dialog.setNameFilters(DeckLoader::fileNameFilters); @@ -891,25 +888,33 @@ void TabDeckEditor::actAddCustomSet() if (!dialog.exec()) return; + QDir dir(dataDir + "/customsets"); + int nextPrefix = getNextCustomSetPrefix(dir); + QString fileName = dialog.selectedFiles().at(0); - QDir dir(dataDir.append("/customsets")); - QStringList files = dir.entryList(); - int maxIndex = 0; - for (int i = 0; i < files.size(); ++i) { - int fileIndex = files.at(i).split(".").at(0).toInt(); - if (fileIndex > maxIndex) - maxIndex = fileIndex; - } - maxIndex++; bool res = QFile::copy( - fileName, dir.absolutePath() + "/" + (maxIndex > 9 ? "" : "0") + - QString::number(maxIndex) + "." + QFileInfo(fileName).fileName() + fileName, dir.absolutePath() + "/" + (nextPrefix > 9 ? "" : "0") + + QString::number(nextPrefix) + "." + QFileInfo(fileName).fileName() ); DlgAddSetResult dlg(this, res); dlg.exec(); } +int TabDeckEditor::getNextCustomSetPrefix(QDir dataDir) { + QStringList files = dataDir.entryList(); + int maxIndex = 0; + + QStringList::const_iterator filesIterator; + for (filesIterator = files.constBegin(); filesIterator != files.constEnd(); ++filesIterator) { + int fileIndex = (*filesIterator).split(".").at(0).toInt(); + if (fileIndex > maxIndex) + maxIndex = fileIndex; + } + + return maxIndex + 1; +} + void TabDeckEditor::actEditSets() { WndSets *w = new WndSets; diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index 57152408b..13e4203c4 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -3,6 +3,7 @@ #include "tab.h" #include +#include #include #include "keysignals.h" @@ -95,6 +96,7 @@ private: void offsetCountAtIndex(const QModelIndex &idx, int offset); void decrementCardHelper(QString zoneName); void recursiveExpand(const QModelIndex &index); + int getNextCustomSetPrefix(QDir dataDir); CardDatabaseModel *databaseModel; CardDatabaseDisplayModel *databaseDisplayModel;