From 52643b4d6abae2851df8633e1f27b08da0ce0ea7 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Mon, 27 May 2019 20:57:00 +0200 Subject: [PATCH] info: Add support for trying more than two versions --- src/setup/info.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/setup/info.cpp b/src/setup/info.cpp index 3ef9196..eb130f0 100644 --- a/src/setup/info.cpp +++ b/src/setup/info.cpp @@ -226,33 +226,38 @@ void info::load(std::istream & is, entry_types entries) { // Some setup versions didn't increment the data version number when they should have. // To work around this, we try to parse the headers for both data versions. - bool ambiguous = version.is_ambiguous(); - if(ambiguous) { + bool ambiguous = !version.known || version.is_ambiguous(); + if(version.is_ambiguous()) { // Force parsing all headers so that we don't miss any errors. entries |= NoSkip; } - if(!version.known || ambiguous) { - std::streampos start = is.tellg(); + + std::streampos start = is.tellg(); + for(;;) { + try { + + // Try to parse headers for this version load(is, entries, version); return; + } catch(...) { - version.value = version.next(); - if(!version) { + + if(!ambiguous || !(version.value = version.next())) { + // No more versions to try - report the original version version.value = listed_version; throw; } + + // Retry with the next version + ambiguous = version.is_ambiguous(); is.clear(); is.seekg(start); + } + } - try { - load(is, entries, version); - } catch(...) { - version.value = listed_version; - throw; - } } info::info() { }