QString inFileName; QString inFilter; inFilter = "Bin files (*.rpu);; All Files (*.*)"; inFileName = QFileDialog::getOpenFileName(0, trUtf8("Select file"), QApplication::applicationDirPath(), inFilter, 0); QFile inFile; inFile.setFileName(inFileName); QString outFileName = inFileName + "_output.rpu"; QFile outFile; outFile.setFileName(outFileName); if (!inFile.open(QIODevice::ReadOnly)) qDebug() << "inFile error"; if (!outFile.open(QIODevice::WriteOnly)) qDebug() << "outFile Error"; QByteArray inArray; inArray = inFile.read(12); QDataStream stream (&inArray, QIODevice::ReadWrite); stream.setByteOrder(QDataStream::LittleEndian); stream.device()->seek(0); quint32 tmp; quint16 inf3; stream.operator >>(tmp) >> (tmp) >> (tmp); inf3 = (tmp&0x00007FFF); qDebug() << inf3; stream.device()->seek(0);
C++ (Qt)quint16 temp; // читаем tempconst quint16 mask = 0x7FFF;quint16 newVal = (temp & ~mask) | ((temp & mask) + 10);
C++ (Qt)quint16 newVal = (temp & ~mask) | ((temp + 10) & mask);
QFile inFile; inFile.setFileName(inFileName); QString outFileName = inFileName + "_output.rpu"; QFile outFile; outFile.setFileName(outFileName); if (!inFile.open(QIODevice::ReadOnly) || (!outFile.open(QIODevice::ReadWrite))) { qDebug() << "some file error"; } else { QByteArray array; array = inFile.readAll(); inFile.close(); QDataStream stream (&array, QIODevice::ReadWrite); stream.setByteOrder(QDataStream::LittleEndian); QDataStream outStream (&outFile); stream.device()->seek(0); quint32 tmp; quint16 inf3; stream.operator >>(tmp) >> (tmp) >> (tmp); inf3 = (tmp&0x00007FFF); qDebug() << inf3; const quint16 mask = 0x7FFF; quint16 newVal = (inf3 & ~mask) | ((inf3 + 10) & mask); qDebug() << newVal; stream.device()->seek(0); //ВСТАТЬ НА НУЖНУЮ ПОЗИЦИЮ stream << newVal; stream.device()->seek(0); outStream << stream; outFile.close(); }}
C++ (Qt)// позиция заменяемого числа в файлеconst qlonglong editOffset = 0; bool Copy2Out( const QString & inFileName ){// копируем файл 1:1 QString outFileName = inFileName + "_output.rpu"; if (!QFile::copy(inFileName, outFileName)) return Error("File copy error"); // открываем выходной файл QFile file(outFileName); if (!file.open(QIODevice::ReadWrite)) return Error("File write error"); // читаем число для замены quint16 src, dst; file.seek(editOffset); file.read((char *) &src, 2); // меняем const quint16 mask = 0x7FFF; dst = src & mask; dst += 10; if (dst & ~mask) return Error("Overflow Error"); dst |= (src & ~mask); // пишем взад file.seek(editOffset); file.write((char *) &dst, 2); if (file.error() != QFile::NoError) return Error("File Write Error"); return true;}