* write Update to flash * @param in Stream& * @param size uint32_t * @param md5 String * @return true if Update ok */
| 440 | * @return true if Update ok |
| 441 | */ |
| 442 | bool HTTPUpdate::runUpdate(Stream &in, uint32_t size, String md5, int command) { |
| 443 | if (!_updater) { |
| 444 | return false; |
| 445 | } |
| 446 | |
| 447 | StreamString error; |
| 448 | |
| 449 | if (_cbProgress) { |
| 450 | _updater->onProgress(_cbProgress); |
| 451 | } |
| 452 | |
| 453 | if (!_updater->begin(size, command, _ledPin, _ledOn)) { |
| 454 | _lastError = _updater->getError(); |
| 455 | _updater->printError(error); |
| 456 | error.trim(); // remove line ending |
| 457 | log_e("Update.begin failed! (%s)\n", error.c_str()); |
| 458 | return false; |
| 459 | } |
| 460 | |
| 461 | if (_cbProgress) { |
| 462 | _cbProgress(0, size); |
| 463 | } |
| 464 | |
| 465 | if (md5.length()) { |
| 466 | if (!_updater->setMD5(md5.c_str())) { |
| 467 | _lastError = HTTP_UE_SERVER_FAULTY_MD5; |
| 468 | log_e("Update.setMD5 failed! (%s)\n", md5.c_str()); |
| 469 | return false; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | // To do: the SHA256 could be checked if the server sends it |
| 474 | |
| 475 | if (_updater->writeStream(in) != size) { |
| 476 | _lastError = _updater->getError(); |
| 477 | _updater->printError(error); |
| 478 | error.trim(); // remove line ending |
| 479 | log_e("Update.writeStream failed! (%s)\n", error.c_str()); |
| 480 | return false; |
| 481 | } |
| 482 | |
| 483 | if (_cbProgress) { |
| 484 | _cbProgress(size, size); |
| 485 | } |
| 486 | |
| 487 | if (!_updater->end()) { |
| 488 | _lastError = _updater->getError(); |
| 489 | _updater->printError(error); |
| 490 | error.trim(); // remove line ending |
| 491 | log_e("Update.end failed! (%s)\n", error.c_str()); |
| 492 | return false; |
| 493 | } |
| 494 | |
| 495 | return true; |
| 496 | } |
| 497 | |
| 498 | #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE) |
| 499 | HTTPUpdate httpUpdate; |
nothing calls this directly
no test coverage detected