mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
improve ui
This commit is contained in:
42
qv2ray/v3/components/GeositeReader/GeositeReader.cpp
Normal file
42
qv2ray/v3/components/GeositeReader/GeositeReader.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "GeositeReader.hpp"
|
||||
|
||||
#include "qv2ray/wrapper.hpp"
|
||||
#include "picoproto.hpp"
|
||||
|
||||
#include <QFile>
|
||||
#include <QMap>
|
||||
|
||||
namespace Qv2ray::components::GeositeReader {
|
||||
QMap<QString, QStringList> GeositeEntries;
|
||||
|
||||
QStringList ReadGeoSiteFromFile(const QString &filepath, bool allowCache) {
|
||||
if (GeositeEntries.contains(filepath) && allowCache)
|
||||
return GeositeEntries.value(filepath);
|
||||
|
||||
QStringList list;
|
||||
qInfo() << "Reading geosites from:" << filepath;
|
||||
QFile f(filepath);
|
||||
bool opened = f.open(QFile::OpenModeFlag::ReadOnly);
|
||||
|
||||
if (!opened) {
|
||||
qInfo() << "File cannot be opened:" << filepath;
|
||||
return list;
|
||||
}
|
||||
|
||||
const auto content = f.readAll();
|
||||
f.close();
|
||||
{
|
||||
picoproto::Message root;
|
||||
root.ParseFromBytes((unsigned char *) content.data(), content.size());
|
||||
|
||||
list.reserve(root.GetMessageArray(1).size());
|
||||
for (const auto &geosite: root.GetMessageArray(1))
|
||||
list << QString::fromStdString(geosite->GetString(1));
|
||||
}
|
||||
|
||||
qInfo() << "Loaded" << list.count() << "geosite entries from data file.";
|
||||
list.sort();
|
||||
GeositeEntries[filepath] = list;
|
||||
return list;
|
||||
}
|
||||
} // namespace Qv2ray::components::geosite
|
||||
Reference in New Issue
Block a user