mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
VolumeVerifier: Add zip support for datfile
This commit is contained in:
@ -82,6 +82,7 @@ add_library(common
|
||||
MemArena.h
|
||||
MemoryUtil.cpp
|
||||
MemoryUtil.h
|
||||
MinizipUtil.h
|
||||
MsgHandler.cpp
|
||||
MsgHandler.h
|
||||
NandPaths.cpp
|
||||
@ -134,6 +135,7 @@ PUBLIC
|
||||
enet
|
||||
fmt::fmt
|
||||
${MBEDTLS_LIBRARIES}
|
||||
minizip
|
||||
|
||||
PRIVATE
|
||||
${CURL_LIBRARIES}
|
||||
|
@ -139,6 +139,7 @@
|
||||
<ClInclude Include="MD5.h" />
|
||||
<ClInclude Include="MemArena.h" />
|
||||
<ClInclude Include="MemoryUtil.h" />
|
||||
<ClInclude Include="MinizipUtil.h" />
|
||||
<ClInclude Include="MsgHandler.h" />
|
||||
<ClInclude Include="NandPaths.h" />
|
||||
<ClInclude Include="Network.h" />
|
||||
|
@ -59,6 +59,7 @@
|
||||
<ClInclude Include="Matrix.h" />
|
||||
<ClInclude Include="MemArena.h" />
|
||||
<ClInclude Include="MemoryUtil.h" />
|
||||
<ClInclude Include="MinizipUtil.h" />
|
||||
<ClInclude Include="MsgHandler.h" />
|
||||
<ClInclude Include="NandPaths.h" />
|
||||
<ClInclude Include="Network.h" />
|
||||
|
42
Source/Core/Common/MinizipUtil.h
Normal file
42
Source/Core/Common/MinizipUtil.h
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2019 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <minizip/unzip.h>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/ScopeGuard.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
// Reads all of the current file. destination must be big enough to fit the whole file.
|
||||
template <typename ContiguousContainer>
|
||||
bool ReadFileFromZip(unzFile file, ContiguousContainer* destination)
|
||||
{
|
||||
const u32 MAX_BUFFER_SIZE = 65535;
|
||||
|
||||
if (unzOpenCurrentFile(file) != UNZ_OK)
|
||||
return false;
|
||||
|
||||
Common::ScopeGuard guard{[&] { unzCloseCurrentFile(file); }};
|
||||
|
||||
u32 bytes_to_go = static_cast<u32>(destination->size());
|
||||
while (bytes_to_go > 0)
|
||||
{
|
||||
const int bytes_read =
|
||||
unzReadCurrentFile(file, &(*destination)[destination->size() - bytes_to_go],
|
||||
std::min(bytes_to_go, MAX_BUFFER_SIZE));
|
||||
|
||||
if (bytes_read < 0)
|
||||
return false;
|
||||
|
||||
bytes_to_go -= static_cast<u32>(bytes_read);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Common
|
Reference in New Issue
Block a user