removed PrefixPath debug line
[opentx.git] / companion / src / converteeprom.cpp
blob8c75be049f9b1026a13efd63583fc32a91a1ec2b
1 #include "converteeprom.h"
2 #include "eeprominterface.h"
3 #include "firmwareinterface.h"
4 #include <QFile>
6 bool convertEEprom(const QString &sourceEEprom, const QString &destinationEEprom, const QString &firmwareFilename)
8 Firmware *currentFirmware = GetCurrentFirmware();
9 FirmwareInterface firmware(firmwareFilename);
10 if (!firmware.isValid())
11 return false;
13 unsigned int version = firmware.getEEpromVersion();
14 unsigned int variant = firmware.getEEpromVariant();
16 QFile sourceFile(sourceEEprom);
17 int eeprom_size = sourceFile.size();
18 if (!eeprom_size)
19 return false;
21 if (!sourceFile.open(QIODevice::ReadOnly))
22 return false;
24 QByteArray eeprom(eeprom_size, 0);
25 long result = sourceFile.read(eeprom.data(), eeprom_size);
26 sourceFile.close();
28 QSharedPointer<RadioData> radioData = QSharedPointer<RadioData>(new RadioData());
29 if (!loadEEprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size) || !currentFirmware->saveEEPROM((uint8_t *)eeprom.data(), *radioData, variant, version))
30 return false;
32 QFile destinationFile(destinationEEprom);
33 if (!destinationFile.open(QIODevice::WriteOnly))
34 return false;
36 result = destinationFile.write(eeprom.constData(), eeprom_size);
37 destinationFile.close();
38 if (result != eeprom_size)
39 return false;
41 return true;