MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / parseJsonFile

Function parseJsonFile

launcher/minecraft/ProfileUtils.cpp:112–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

loadComponentFunction · 0.85
installComponentsMethod · 0.85

Calls 5

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

Tested by

no test coverage detected