MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / parseJsonFile

Function parseJsonFile

launcher/minecraft/ProfileUtils.cpp:111–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111VersionFilePtr parseJsonFile(const QFileInfo& fileInfo, const bool requireOrder)
112{
113 QFile file(fileInfo.absoluteFilePath());
114 if (!file.open(QFile::ReadOnly)) {
115 auto errorStr = QObject::tr("Unable to open the version file %1: %2.").arg(fileInfo.fileName(), file.errorString());
116 return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr);
117 }
118 QJsonParseError error;
119 auto data = file.readAll();
120 QJsonDocument doc = QJsonDocument::fromJson(data, &error);
121 file.close();
122 if (error.error != QJsonParseError::NoError) {
123 int line = 1;
124 int column = 0;
125 for (int i = 0; i < error.offset; i++) {
126 if (data[i] == '\n') {
127 line++;
128 column = 0;
129 continue;
130 }
131 column++;
132 }
133 auto errorStr = QObject::tr("Unable to process the version file %1: %2 at line %3 column %4.")
134 .arg(fileInfo.fileName(), error.errorString())
135 .arg(line)
136 .arg(column);
137 return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr);
138 }
139 return guardedParseJson(doc, fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), requireOrder);
140}
141
142bool saveJsonFile(const QJsonDocument& doc, const QString& filename)
143{

Callers 2

loadComponentFunction · 0.85
installComponentsMethod · 0.85

Calls 6

createErrorVersionFileFunction · 0.85
guardedParseJsonFunction · 0.85
errorStringMethod · 0.80
readAllMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected