Example #1
0
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
{
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    bool result = false;
    switch (fmt) {
        case PlainTextFormat: result = loadFromFile_Plain(&file); break;
        case CockatriceFormat:
            result = loadFromFile_Native(&file);
            qDebug() << "Loaded from" << fileName << "-" << result;
            if (!result) {
                qDebug() << "Retying as plain format";
                file.seek(0);
                result = loadFromFile_Plain(&file);
                fmt = PlainTextFormat;
            }
            break;
    }
    if (result) {
        lastFileName = fileName;
        lastFileFormat = fmt;

        emit deckLoaded();
    }
    qDebug() << "Deck was loaded -" << result;
    return result;
}
Example #2
0
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
{
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;
    
    bool result = false;
    switch (fmt) {
        case PlainTextFormat: result = loadFromFile_Plain(&file); break;
        case CockatriceFormat: result = loadFromFile_Native(&file); break;
    }
    if (result) {
        lastFileName = fileName;
        lastFileFormat = fmt;
        
        emit deckLoaded();
    }
    return result;
}