mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 16:24:45 -07:00
Add a dialog to prompt user to convert to .cod format if trying to apply tags to a .txt deck. (#5514)
* Add a dialog to prompt user to convert to .cod format if trying to apply tags to a .txt deck. * Lint mocks. * Address comments, move dialog to appropriate folder. * Unlint. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
4e96157091
commit
ce416df3fb
14 changed files with 229 additions and 6 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#include "decklist.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QFutureWatcher>
|
||||
|
|
@ -481,6 +482,53 @@ void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out,
|
|||
}
|
||||
}
|
||||
|
||||
bool DeckLoader::convertToCockatriceFormat(QString fileName)
|
||||
{
|
||||
// Change the file extension to .cod
|
||||
QFileInfo fileInfo(fileName);
|
||||
QString newFileName = QDir::toNativeSeparators(fileInfo.path() + "/" + fileInfo.completeBaseName() + ".cod");
|
||||
|
||||
// Open the new file for writing
|
||||
QFile file(newFileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qCWarning(DeckLoaderLog) << "Failed to open file for writing:" << newFileName;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
// Perform file modifications based on the detected format
|
||||
switch (getFormatFromName(fileName)) {
|
||||
case PlainTextFormat:
|
||||
// Save in Cockatrice's native format
|
||||
result = saveToFile_Native(&file);
|
||||
break;
|
||||
case CockatriceFormat:
|
||||
qCInfo(DeckLoaderLog) << "File is already in Cockatrice format. No conversion needed.";
|
||||
result = true;
|
||||
break;
|
||||
default:
|
||||
qCWarning(DeckLoaderLog) << "Unsupported file format for conversion:" << fileName;
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
// Delete the old file if conversion was successful
|
||||
if (result) {
|
||||
if (!QFile::remove(fileName)) {
|
||||
qCWarning(DeckLoaderLog) << "Failed to delete original file:" << fileName;
|
||||
} else {
|
||||
qCInfo(DeckLoaderLog) << "Original file deleted successfully:" << fileName;
|
||||
}
|
||||
lastFileName = newFileName;
|
||||
lastFileFormat = CockatriceFormat;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneName)
|
||||
{
|
||||
CardInfoPtr card = CardDatabaseManager::getInstance()->getCard(cardName);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue