| 5 | |
| 6 | namespace { |
| 7 | bool load(const QString& path, std::vector<GameOptionItem> &contents, int & version) |
| 8 | { |
| 9 | contents.clear(); |
| 10 | QFile file(path); |
| 11 | if (!file.open(QFile::ReadOnly)) |
| 12 | { |
| 13 | qWarning() << "Failed to read options file."; |
| 14 | return false; |
| 15 | } |
| 16 | version = 0; |
| 17 | while(!file.atEnd()) |
| 18 | { |
| 19 | auto line = file.readLine(); |
| 20 | if(line.endsWith('\n')) |
| 21 | { |
| 22 | line.chop(1); |
| 23 | } |
| 24 | auto separatorIndex = line.indexOf(':'); |
| 25 | if(separatorIndex == -1) |
| 26 | { |
| 27 | continue; |
| 28 | } |
| 29 | auto key = QString::fromUtf8(line.data(), separatorIndex); |
| 30 | auto value = QString::fromUtf8(line.data() + separatorIndex + 1, line.size() - 1 - separatorIndex); |
| 31 | qDebug() << "!!" << key << "!!"; |
| 32 | if(key == "version") |
| 33 | { |
| 34 | version = value.toInt(); |
| 35 | continue; |
| 36 | } |
| 37 | contents.emplace_back(GameOptionItem{key, value}); |
| 38 | } |
| 39 | qDebug() << "Loaded" << path << "with version:" << version; |
| 40 | return true; |
| 41 | } |
| 42 | bool save(const QString& path, std::vector<GameOptionItem> &mapping, int version) |
| 43 | { |
| 44 | QSaveFile out(path); |
no test coverage detected