From aa53b74a411c93983eb7a8c0d00ae25dc33f0017 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Wed, 1 Jul 2015 15:19:39 +0100 Subject: [PATCH] Fixed GetCrc32 test failure. --- src/backend/helpers/helpers.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/backend/helpers/helpers.cpp b/src/backend/helpers/helpers.cpp index a7845f75..c27682b7 100644 --- a/src/backend/helpers/helpers.cpp +++ b/src/backend/helpers/helpers.cpp @@ -67,19 +67,23 @@ namespace loot { //Calculate the CRC of the given file for comparison purposes. uint32_t GetCrc32(const fs::path& filename) { uint32_t chksum = 0; - loot::ifstream ifile(filename, ios::binary); - BOOST_LOG_TRIVIAL(trace) << "Calculating CRC for: " << filename.string(); - boost::crc_32_type result; - if (ifile) { - static const size_t buffer_size = 8192; - char buffer[buffer_size]; - do { - ifile.read(buffer, buffer_size); - result.process_bytes(buffer, ifile.gcount()); - } while (ifile); - chksum = result.checksum(); + try { + loot::ifstream ifile(filename, ios::binary); + BOOST_LOG_TRIVIAL(trace) << "Calculating CRC for: " << filename.string(); + boost::crc_32_type result; + if (ifile) { + static const size_t buffer_size = 8192; + char buffer[buffer_size]; + do { + ifile.read(buffer, buffer_size); + result.process_bytes(buffer, ifile.gcount()); + } while (ifile); + chksum = result.checksum(); + } + else + throw exception(); } - else { + catch (exception&) { BOOST_LOG_TRIVIAL(error) << "Unable to open \"" << filename.string() << "\" for CRC calculation."; throw error(error::path_read_fail, (boost::format(lc::translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str()); }