Common: Remove MD5.h
It uses DiscIO, and Common shouldn't depend on DiscIO. Instead, put this code in NetPlayClient.cpp.
This commit is contained in:
parent
0c19f895d3
commit
301bc49efe
|
@ -81,8 +81,6 @@ add_library(common
|
|||
MathUtil.h
|
||||
Matrix.cpp
|
||||
Matrix.h
|
||||
MD5.cpp
|
||||
MD5.h
|
||||
MemArena.h
|
||||
MemoryUtil.cpp
|
||||
MemoryUtil.h
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright 2016 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "Common/MD5.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <mbedtls/md5.h>
|
||||
#include <string>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "Common/StringUtil.h"
|
||||
#include "DiscIO/Blob.h"
|
||||
|
||||
namespace MD5
|
||||
{
|
||||
std::string MD5Sum(const std::string& file_path, std::function<bool(int)> report_progress)
|
||||
{
|
||||
std::string output_string;
|
||||
std::vector<u8> data(8 * 1024 * 1024);
|
||||
u64 read_offset = 0;
|
||||
mbedtls_md5_context ctx;
|
||||
|
||||
std::unique_ptr<DiscIO::BlobReader> file(DiscIO::CreateBlobReader(file_path));
|
||||
u64 game_size = file->GetDataSize();
|
||||
|
||||
mbedtls_md5_starts_ret(&ctx);
|
||||
|
||||
while (read_offset < game_size)
|
||||
{
|
||||
size_t read_size = std::min(static_cast<u64>(data.size()), game_size - read_offset);
|
||||
if (!file->Read(read_offset, read_size, data.data()))
|
||||
return output_string;
|
||||
|
||||
mbedtls_md5_update_ret(&ctx, data.data(), read_size);
|
||||
read_offset += read_size;
|
||||
|
||||
int progress =
|
||||
static_cast<int>(static_cast<float>(read_offset) / static_cast<float>(game_size) * 100);
|
||||
if (!report_progress(progress))
|
||||
return output_string;
|
||||
}
|
||||
|
||||
std::array<u8, 16> output;
|
||||
mbedtls_md5_finish_ret(&ctx, output.data());
|
||||
|
||||
// Convert to hex
|
||||
for (u8 n : output)
|
||||
output_string += fmt::format("{:02x}", n);
|
||||
|
||||
return output_string;
|
||||
}
|
||||
} // namespace MD5
|
|
@ -1,12 +0,0 @@
|
|||
// Copyright 2016 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace MD5
|
||||
{
|
||||
std::string MD5Sum(const std::string& file_name, std::function<bool(int)> progress);
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include "Common/ENetUtil.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MD5.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/QoSSession.h"
|
||||
|
@ -62,6 +62,7 @@
|
|||
#include "Core/NetPlayCommon.h"
|
||||
#include "Core/PowerPC/PowerPC.h"
|
||||
#include "Core/SyncIdentifier.h"
|
||||
#include "DiscIO/Blob.h"
|
||||
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
|
||||
#include "InputCommon/GCAdapter.h"
|
||||
|
@ -2462,6 +2463,43 @@ bool NetPlayClient::DoAllPlayersHaveGame()
|
|||
});
|
||||
}
|
||||
|
||||
static std::string MD5Sum(const std::string& file_path, std::function<bool(int)> report_progress)
|
||||
{
|
||||
std::string output_string;
|
||||
std::vector<u8> data(8 * 1024 * 1024);
|
||||
u64 read_offset = 0;
|
||||
mbedtls_md5_context ctx;
|
||||
|
||||
std::unique_ptr<DiscIO::BlobReader> file(DiscIO::CreateBlobReader(file_path));
|
||||
u64 game_size = file->GetDataSize();
|
||||
|
||||
mbedtls_md5_starts_ret(&ctx);
|
||||
|
||||
while (read_offset < game_size)
|
||||
{
|
||||
size_t read_size = std::min(static_cast<u64>(data.size()), game_size - read_offset);
|
||||
if (!file->Read(read_offset, read_size, data.data()))
|
||||
return output_string;
|
||||
|
||||
mbedtls_md5_update_ret(&ctx, data.data(), read_size);
|
||||
read_offset += read_size;
|
||||
|
||||
int progress =
|
||||
static_cast<int>(static_cast<float>(read_offset) / static_cast<float>(game_size) * 100);
|
||||
if (!report_progress(progress))
|
||||
return output_string;
|
||||
}
|
||||
|
||||
std::array<u8, 16> output;
|
||||
mbedtls_md5_finish_ret(&ctx, output.data());
|
||||
|
||||
// Convert to hex
|
||||
for (u8 n : output)
|
||||
output_string += fmt::format("{:02x}", n);
|
||||
|
||||
return output_string;
|
||||
}
|
||||
|
||||
void NetPlayClient::ComputeMD5(const SyncIdentifier& sync_identifier)
|
||||
{
|
||||
if (m_should_compute_MD5)
|
||||
|
@ -2488,7 +2526,7 @@ void NetPlayClient::ComputeMD5(const SyncIdentifier& sync_identifier)
|
|||
if (m_MD5_thread.joinable())
|
||||
m_MD5_thread.join();
|
||||
m_MD5_thread = std::thread([this, file]() {
|
||||
std::string sum = MD5::MD5Sum(file, [&](int progress) {
|
||||
std::string sum = MD5Sum(file, [&](int progress) {
|
||||
sf::Packet packet;
|
||||
packet << MessageID::MD5Progress;
|
||||
packet << progress;
|
||||
|
|
|
@ -123,7 +123,6 @@
|
|||
<ClInclude Include="Common\Logging\LogManager.h" />
|
||||
<ClInclude Include="Common\MathUtil.h" />
|
||||
<ClInclude Include="Common\Matrix.h" />
|
||||
<ClInclude Include="Common\MD5.h" />
|
||||
<ClInclude Include="Common\MemArena.h" />
|
||||
<ClInclude Include="Common\MemoryUtil.h" />
|
||||
<ClInclude Include="Common\MinizipUtil.h" />
|
||||
|
@ -723,7 +722,6 @@
|
|||
<ClCompile Include="Common\Logging\LogManager.cpp" />
|
||||
<ClCompile Include="Common\MathUtil.cpp" />
|
||||
<ClCompile Include="Common\Matrix.cpp" />
|
||||
<ClCompile Include="Common\MD5.cpp" />
|
||||
<ClCompile Include="Common\MemArenaWin.cpp" />
|
||||
<ClCompile Include="Common\MemoryUtil.cpp" />
|
||||
<ClCompile Include="Common\MsgHandler.cpp" />
|
||||
|
|
Loading…
Reference in New Issue