From 9cbcf55a70d75c5bd003593201935df532ecaa4f Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Tue, 22 Apr 2025 13:39:19 +0000 Subject: [PATCH] retry saving to zip if saving to zip fails --- .../accessible-actors/SfxExtractor.cpp | 15 +++++++++------ .../Enhancements/accessible-actors/SfxExtractor.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp b/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp index 2bf7380ea..c18445408 100644 --- a/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp +++ b/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp @@ -56,11 +56,11 @@ size_t SfxExtractor::adjustedEndOfInput(size_t endOfInput) { return endOfInput; } -void SfxExtractor::renderOutput(size_t endOfInput) { +bool SfxExtractor::renderOutput(size_t endOfInput) { size_t startOfInput = adjustedStartOfInput(); endOfInput = adjustedEndOfInput(endOfInput); if (endOfInput <= startOfInput) { - return; + return true; } ma_channel_converter_config config = @@ -80,7 +80,7 @@ void SfxExtractor::renderOutput(size_t endOfInput) { size_t size = 0; if (!drwav_init_memory_write(&wav, &mem, &size, &format, NULL)) - throw std::runtime_error("SFX Extractor: Unable to initialize wave writer."); + throw std::runtime_error("SfxExtractor: Unable to initialize wave writer."); int16_t chunk[64]; int16_t* mark = tempBuffer + startOfInput; size_t samplesLeft = endOfInput - startOfInput; @@ -94,7 +94,7 @@ void SfxExtractor::renderOutput(size_t endOfInput) { drwav_uninit(&wav); std::vector fileData((uint8_t*)mem, (uint8_t*)mem + size); drwav_free(mem, NULL); - archive->WriteFile(fileName.c_str(), fileData); + return archive->WriteFile(fileName.c_str(), fileData); } void SfxExtractor::setup() { @@ -240,8 +240,11 @@ void SfxExtractor::captureCallback() { endOfInput += (SFX_EXTRACTION_ONE_FRAME * 2); samplesLeft -= std::min(SFX_EXTRACTION_ONE_FRAME, samplesLeft); } - renderOutput(endOfInput); - captureThreadState = CT_FINISHED; // Go to the next one. + if (renderOutput(endOfInput)) { + captureThreadState = CT_FINISHED; + } else { + SPDLOG_ERROR("failed to write file to archive, trying again"); + } } std::string SfxExtractor::getExternalFileName(int16_t sfxId) { std::stringstream ss; diff --git a/soh/soh/Enhancements/accessible-actors/SfxExtractor.h b/soh/soh/Enhancements/accessible-actors/SfxExtractor.h index 46287c40b..ce1b80e03 100644 --- a/soh/soh/Enhancements/accessible-actors/SfxExtractor.h +++ b/soh/soh/Enhancements/accessible-actors/SfxExtractor.h @@ -12,7 +12,7 @@ class SfxExtractor { bool isAllZero(int16_t* buffer, size_t count); size_t adjustedStartOfInput(); size_t adjustedEndOfInput(size_t endOfInput); - void renderOutput(size_t endOfInput); + bool renderOutput(size_t endOfInput); void setup(); void ripNextSfx(); void finished(); // Also handles failure.