Merge pull request #13459 from zfox23/MS16113_hifikeyPath

Fix MS16113: Use alternate method for creating backup instructions
This commit is contained in:
Zach Fox 2018-06-26 11:36:03 -07:00 committed by GitHub
commit 56b3c125c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -127,32 +127,41 @@ EC_KEY* readKeys(const char* filename) {
bool Wallet::writeBackupInstructions() { bool Wallet::writeBackupInstructions() {
QString inputFilename(PathUtils::resourcesPath() + "html/commerce/backup_instructions.html"); QString inputFilename(PathUtils::resourcesPath() + "html/commerce/backup_instructions.html");
QString outputFilename = PathUtils::getAppDataFilePath(INSTRUCTIONS_FILE); QString outputFilename = PathUtils::getAppDataFilePath(INSTRUCTIONS_FILE);
QFile inputFile(inputFilename);
QFile outputFile(outputFilename); QFile outputFile(outputFilename);
bool retval = false; bool retval = false;
if (QFile::exists(outputFilename) || getKeyFilePath() == "") if (getKeyFilePath() == "")
{ {
return false; return false;
} }
QFile::copy(inputFilename, outputFilename);
if (QFile::exists(outputFilename) && outputFile.open(QIODevice::ReadWrite)) { if (QFile::exists(inputFilename) && inputFile.open(QIODevice::ReadOnly)) {
if (outputFile.open(QIODevice::ReadWrite)) {
// Read the data from the original file, then close it
QByteArray fileData = inputFile.readAll();
inputFile.close();
QByteArray fileData = outputFile.readAll(); // Translate the data from the original file into a QString
QString text(fileData); QString text(fileData);
// Replace the necessary string
text.replace(QString("HIFIKEY_PATH_REPLACEME"), keyFilePath()); text.replace(QString("HIFIKEY_PATH_REPLACEME"), keyFilePath());
outputFile.seek(0); // go to the beginning of the file // Write the new text back to the file
outputFile.write(text.toUtf8()); // write the new text back to the file outputFile.write(text.toUtf8());
outputFile.close(); // close the file handle. // Close the output file
outputFile.close();
retval = true; retval = true;
qCDebug(commerce) << "wrote html file successfully"; qCDebug(commerce) << "wrote html file successfully";
} else { } else {
qCDebug(commerce) << "failed to open output html file" << outputFilename; qCDebug(commerce) << "failed to open output html file" << outputFilename;
} }
} else {
qCDebug(commerce) << "failed to open input html file" << inputFilename;
}
return retval; return retval;
} }