DCPlugin/src/ATBAPP/support/PTUSystem.cpp

110 lines
2.7 KiB
C++

#include "PTUSystem.h"
#include <QDebug>
#include <QDir>
#include <QFileInfo>
PTUSystem::PTUSystem(QObject *parent) : QObject(parent)
{
}
quint16 PTUSystem::readCustomerNumber()
{
QString resultFilename;
QStringList fileNameList;
fileNameList << "/mnt/system_data/cust_nr"
<< "/etc/cust_nr";
for (const auto& filename : fileNameList) {
if (QFileInfo(filename).isReadable()) {
resultFilename = filename;
break;
}
}
QString resultString = PTUSystem::readConfigString(resultFilename);
return static_cast<quint16>(resultString.toInt());
}
quint16 PTUSystem::readMachineNumber()
{
QString resultFilename;
QStringList fileNameList;
fileNameList << "/mnt/system_data/machine_nr"
<< "/etc/machine_nr";
for (const auto& filename : fileNameList) {
if (QFileInfo(filename).isReadable()) {
resultFilename = filename;
break;
}
}
QString resultString = PTUSystem::readConfigString(resultFilename);
return static_cast<quint16>(resultString.toInt());
}
quint16 PTUSystem::readZoneNumber()
{
QString resultFilename;
QStringList fileNameList;
fileNameList << "/mnt/system_data/zone_nr"
<< "/etc/zone_nr";
for (const auto& filename : fileNameList) {
if (QFileInfo(filename).isReadable()) {
resultFilename = filename;
break;
}
}
QString resultString = PTUSystem::readConfigString(resultFilename);
return static_cast<quint16>(resultString.toInt());
}
quint16 PTUSystem::readGroupNumber()
{
QString resultFilename;
QStringList fileNameList;
fileNameList << "/mnt/system_data/group_nr"
<< "/etc/group_nr";
for (const auto& filename : fileNameList) {
if (QFileInfo(filename).isReadable()) {
resultFilename = filename;
break;
}
}
QString resultString = PTUSystem::readConfigString(resultFilename);
return static_cast<quint16>(resultString.toInt());
}
QString PTUSystem::readConfigString(const QString & filename)
{
QFileInfo fileinfo(filename);
if (! fileinfo.isReadable() ) {
qDebug() << "PTUSystem::readConfigString(): \"" << filename << "\" is not readable";
return "";
}
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "PTUSystem::readConfigString() cannot open file: " << filename;
return "";
}
QTextStream in(&file);
QString stringValue = in.readLine(100);
qDebug() << "PTUSystem::readConfigString() stringValue = " << stringValue;
file.close();
return stringValue;
}