Test for Ident.json file first, complain if both .json and .tgt exisit

This commit is contained in:
Phil Olynyk 2021-09-12 13:45:24 -04:00
parent 43a3b155b7
commit 150bc3a3bc

View File

@ -263,26 +263,14 @@ MachineInfo ResmedLoader::PeekInfo(const QString & path)
QFile f(path+"/"+RMS9_STR_idfile+"tgt"); QFile f(path+"/"+RMS9_STR_idfile+"tgt");
// Abort if this file is dodgy.. QFile j(path+"/"+RMS9_STR_idfile+"json"); // Check for AS11 file first, just in case
if (f.exists() ) { if (j.exists() ) { // somebody is reusing an SD card w/o re-formatting
if ( !f.open(QIODevice::ReadOnly)) {
return MachineInfo();
}
MachineInfo info = newInfo();
// Parse # entries into idmap.
while (!f.atEnd()) {
QString line = f.readLine().trimmed();
QHash<QString, QString> hash = parseIdentLine( line, & info );
}
return info;
}
QFile j(path+"/"+RMS9_STR_idfile+"json");
if (j.exists() ) {
if ( !j.open(QIODevice::ReadOnly)) { if ( !j.open(QIODevice::ReadOnly)) {
return MachineInfo(); return MachineInfo();
} }
if ( f.exists() ) {
qDebug() << "Old Ident.tgt file is ignored";
}
QByteArray identData = j.readAll(); QByteArray identData = j.readAll();
j.close(); j.close();
QJsonDocument identDoc(QJsonDocument::fromJson(identData)); QJsonDocument identDoc(QJsonDocument::fromJson(identData));
@ -301,6 +289,21 @@ MachineInfo ResmedLoader::PeekInfo(const QString & path)
} }
} }
// Abort if this file is dodgy..
if (f.exists() ) {
if ( !f.open(QIODevice::ReadOnly)) {
return MachineInfo();
}
MachineInfo info = newInfo();
// Parse # entries into idmap.
while (!f.atEnd()) {
QString line = f.readLine().trimmed();
QHash<QString, QString> hash = parseIdentLine( line, & info );
}
return info;
}
// neither filename exists, return empty info // neither filename exists, return empty info
return MachineInfo(); return MachineInfo();
} }