mirror of
https://github.com/GaryOderNichts/DRXUtil.git
synced 2024-11-27 18:34:19 +01:00
FlashScreen: Improve error handling
This commit is contained in:
parent
787a4df381
commit
94bb1bdac7
@ -63,9 +63,19 @@ bool CopyFile(const std::string& srcPath, const std::string& dstPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t buf[4096];
|
uint8_t buf[4096];
|
||||||
while (!feof(inf)) {
|
size_t bytesRead;
|
||||||
size_t read = fread(buf, 1, sizeof(buf), inf);
|
while ((bytesRead = fread(buf, 1, sizeof(buf), inf)) > 0) {
|
||||||
fwrite(buf, 1, read, outf);
|
if (fwrite(buf, 1, bytesRead, outf) != bytesRead) {
|
||||||
|
fclose(inf);
|
||||||
|
fclose(outf);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ferror(inf)) {
|
||||||
|
fclose(inf);
|
||||||
|
fclose(outf);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(inf);
|
fclose(inf);
|
||||||
@ -374,8 +384,8 @@ bool FlashScreen::Update(VPADStatus& input)
|
|||||||
CCRCDCSoftwareAbort(CCR_CDC_DESTINATION_DRC0);
|
CCRCDCSoftwareAbort(CCR_CDC_DESTINATION_DRC0);
|
||||||
|
|
||||||
// Reattach the DRC in update mode
|
// Reattach the DRC in update mode
|
||||||
if (!ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_UPDATE, 0)) {
|
if (!ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_UPDATE, FALSE)) {
|
||||||
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, 0);
|
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, FALSE);
|
||||||
mErrorString = "Failed to reattach DRC in update mode.";
|
mErrorString = "Failed to reattach DRC in update mode.";
|
||||||
mState = STATE_ERROR;
|
mState = STATE_ERROR;
|
||||||
break;
|
break;
|
||||||
@ -386,7 +396,7 @@ bool FlashScreen::Update(VPADStatus& input)
|
|||||||
mUpdateResult = 0;
|
mUpdateResult = 0;
|
||||||
if (CCRCDCSoftwareUpdate(CCR_CDC_DESTINATION_DRC0, mFirmwarePath.c_str(), SoftwareUpdateCallback, this) != 0) {
|
if (CCRCDCSoftwareUpdate(CCR_CDC_DESTINATION_DRC0, mFirmwarePath.c_str(), SoftwareUpdateCallback, this) != 0) {
|
||||||
AbortUpdate(CCR_CDC_DESTINATION_DRC0);
|
AbortUpdate(CCR_CDC_DESTINATION_DRC0);
|
||||||
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, 0);
|
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, FALSE);
|
||||||
mErrorString = "Failed to start software update.";
|
mErrorString = "Failed to start software update.";
|
||||||
mState = STATE_ERROR;
|
mState = STATE_ERROR;
|
||||||
break;
|
break;
|
||||||
@ -410,7 +420,7 @@ bool FlashScreen::Update(VPADStatus& input)
|
|||||||
mState = STATE_ACTIVATE;
|
mState = STATE_ACTIVATE;
|
||||||
} else {
|
} else {
|
||||||
AbortUpdate(CCR_CDC_DESTINATION_DRC0);
|
AbortUpdate(CCR_CDC_DESTINATION_DRC0);
|
||||||
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, 0);
|
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, FALSE);
|
||||||
mErrorString = "Software update failed.";
|
mErrorString = "Software update failed.";
|
||||||
mState = STATE_ERROR;
|
mState = STATE_ERROR;
|
||||||
}
|
}
|
||||||
@ -421,7 +431,7 @@ bool FlashScreen::Update(VPADStatus& input)
|
|||||||
// Activate the newly flashed firmware
|
// Activate the newly flashed firmware
|
||||||
if (CCRCDCSoftwareActivate(CCR_CDC_DESTINATION_DRC0) != 0) {
|
if (CCRCDCSoftwareActivate(CCR_CDC_DESTINATION_DRC0) != 0) {
|
||||||
AbortUpdate(CCR_CDC_DESTINATION_DRC0);
|
AbortUpdate(CCR_CDC_DESTINATION_DRC0);
|
||||||
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, 0);
|
ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, FALSE);
|
||||||
mErrorString = "Failed to activate software update.";
|
mErrorString = "Failed to activate software update.";
|
||||||
mState = STATE_ERROR;
|
mState = STATE_ERROR;
|
||||||
break;
|
break;
|
||||||
@ -429,7 +439,7 @@ bool FlashScreen::Update(VPADStatus& input)
|
|||||||
|
|
||||||
// Put the gamepad back into active mode
|
// Put the gamepad back into active mode
|
||||||
OSTime startTime = OSGetSystemTime();
|
OSTime startTime = OSGetSystemTime();
|
||||||
while (!ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, 0)) {
|
while (!ReattachDRC(CCR_CDC_DESTINATION_DRC0, CCR_CDC_DRC_STATE_ACTIVE, FALSE)) {
|
||||||
// 10 second timeout
|
// 10 second timeout
|
||||||
if (OSTicksToSeconds(OSGetSystemTime() - startTime) > 10) {
|
if (OSTicksToSeconds(OSGetSystemTime() - startTime) > 10) {
|
||||||
// At this point we don't really care if it times out or not
|
// At this point we don't really care if it times out or not
|
||||||
|
Loading…
Reference in New Issue
Block a user