aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/legacy_ftb/PrivatePackManager.cpp
blob: 824798c0d9882005d5dafd8ed77b623fa3914968 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "PrivatePackManager.h"

#include <QDebug>

#include "FileSystem.h"

namespace LegacyFTB {

void PrivatePackManager::load()
{
    try
    {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
        auto foo = QString::fromUtf8(FS::read(m_filename)).split('\n', Qt::SkipEmptyParts);
        currentPacks = QSet<QString>(foo.begin(), foo.end());
#else
        currentPacks = QString::fromUtf8(FS::read(m_filename)).split('\n', QString::SkipEmptyParts).toSet();
#endif

        dirty = false;
    }
    catch(...)
    {
        currentPacks = {};
        qWarning() << "Failed to read third party FTB pack codes from" << m_filename;
    }
}

void PrivatePackManager::save() const
{
    if(!dirty)
    {
        return;
    }
    try
    {
        QStringList list = currentPacks.values();
        FS::write(m_filename, list.join('\n').toUtf8());
        dirty = false;
    }
    catch(...)
    {
        qWarning() << "Failed to write third party FTB pack codes to" << m_filename;
    }
}

}