2015-11-23 23:19:57 +01:00
|
|
|
#include <QFile>
|
2015-11-26 19:13:59 +01:00
|
|
|
#include <QFileInfo>
|
2016-02-12 10:09:17 +01:00
|
|
|
#include "map.h"
|
2015-11-23 23:19:57 +01:00
|
|
|
#include "maplist.h"
|
|
|
|
|
|
|
|
|
2016-02-12 20:12:37 +01:00
|
|
|
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
2015-11-23 23:19:57 +01:00
|
|
|
{
|
|
|
|
QList<Map*> mapList;
|
2015-11-26 19:13:59 +01:00
|
|
|
QFileInfo fi(fileName);
|
|
|
|
|
|
|
|
if (!fi.exists())
|
|
|
|
return mapList;
|
2015-11-23 23:19:57 +01:00
|
|
|
|
2015-11-26 19:13:59 +01:00
|
|
|
QFile file(fileName);
|
2015-11-23 23:19:57 +01:00
|
|
|
|
|
|
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
|
fprintf(stderr, "Error opening map list file: %s: %s\n",
|
|
|
|
qPrintable(fileName), qPrintable(file.errorString()));
|
|
|
|
return mapList;
|
|
|
|
}
|
|
|
|
|
2015-12-01 22:31:39 +01:00
|
|
|
int ln = 0;
|
2015-11-23 23:19:57 +01:00
|
|
|
while (!file.atEnd()) {
|
2015-12-01 22:31:39 +01:00
|
|
|
ln++;
|
2015-11-23 23:19:57 +01:00
|
|
|
QByteArray line = file.readLine();
|
|
|
|
QList<QByteArray> list = line.split('\t');
|
|
|
|
if (list.size() != 2) {
|
|
|
|
fprintf(stderr, "Invalid map list entry on line %d\n", ln);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray ba1 = list[0].trimmed();
|
|
|
|
QByteArray ba2 = list[1].trimmed();
|
|
|
|
|
2016-02-12 20:12:37 +01:00
|
|
|
mapList.append(new Map(parent, QString::fromUtf8(ba1.data(), ba1.size()),
|
2015-11-24 10:05:28 +01:00
|
|
|
QString::fromLatin1(ba2.data(), ba2.size())));
|
2015-11-23 23:19:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return mapList;
|
|
|
|
}
|