From 51c77e8eeae8244818a1cbb716c3410940826973 Mon Sep 17 00:00:00 2001 From: Aestek Date: Thu, 14 Jul 2016 00:45:38 +0200 Subject: Add md5 testing to netplay Allows to test current game, an arbitrary game or the sdcard of all players at once. --- Source/Core/Common/MD5.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Source/Core/Common/MD5.cpp (limited to 'Source/Core/Common/MD5.cpp') diff --git a/Source/Core/Common/MD5.cpp b/Source/Core/Common/MD5.cpp new file mode 100644 index 0000000000..4746dbdebc --- /dev/null +++ b/Source/Core/Common/MD5.cpp @@ -0,0 +1,52 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include +#include +#include +#include + +#include "Common/MD5.h" +#include "Common/StringUtil.h" +#include "DiscIO/Blob.h" + +namespace MD5 +{ +std::string MD5Sum(const std::string& file_path, std::function report_progress) +{ + std::string output_string; + std::vector data(8 * 1024 * 1024); + u64 read_offset = 0; + mbedtls_md5_context ctx; + + std::unique_ptr file(DiscIO::CreateBlobReader(file_path)); + u64 game_size = file->GetDataSize(); + + mbedtls_md5_starts(&ctx); + + while (read_offset < game_size) + { + size_t read_size = std::min(static_cast(data.size()), game_size - read_offset); + if (!file->Read(read_offset, read_size, data.data())) + return output_string; + + mbedtls_md5_update(&ctx, data.data(), read_size); + read_offset += read_size; + + int progress = + static_cast(static_cast(read_offset) / static_cast(game_size) * 100); + if (!report_progress(progress)) + return output_string; + } + + std::array output; + mbedtls_md5_finish(&ctx, output.data()); + + // Convert to hex + for (u8 n : output) + output_string += StringFromFormat("%02x", n); + + return output_string; +} +} \ No newline at end of file -- cgit v1.2.3