1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
boolean MyClass::writeFromFile(QString filepath)
{
Log *log = Log::getInstance();
qDebug() << "Openning file " << filepath;
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "Error: File "<< filepath << " not found";
log->info("Error: File " + filepath + " not found");
return false;
}
qDebug() << "File "<< filepath << " found";
log->info("File " + filepath + " found");
QByteArray buffer = file.readAll();
file.close();
openBatDevice();
int retData = SetFilePointer(_batDevice, 0, NULL, FILE_BEGIN);
if (retData == 0xFFFFFFF)
{
qDebug() << "Error: SetFilePointer is 0xFFFFFFF";
log->info("Error: SetFilePointer is 0xFFFFFFF");
return false;
}
DWORD nbOfByteWr;
LPDWORD nNumberOfBytesToWrite;
BYTE* data = (BYTE*) buffer.data();
DWORD dwLen = strlen(buffer.data());
DWORD dwBytesRead = (DWORD) buffer.size();
qDebug() << "INFO buffer data: " << buffer.data();
qDebug() << "INFO buffer size: " << buffer.size();
BOOL out = WriteFile(_batDevice, data, dwBytesRead, &nbOfByteWr, NULL);
qDebug() << "INFO out: " << out;
qDebug() << "INFO nbOfByteWr: " << nbOfByteWr;
int errorId = (int) GetLastError();
qDebug() << "Error WriteSector : " + QString::number(errorId);
qDebug() << "Error WriteSector : " + errorId;
} |
Partager