Move library patch functions with file image functions
This commit is contained in:
parent
b5aaf93f07
commit
57a36002d8
6 changed files with 33 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
#ifndef _library__patch__hpp__included__
|
||||
#define _library__patch__hpp__included__
|
||||
#ifndef _library__fileimage_patch__hpp__included__
|
||||
#define _library__fileimage_patch__hpp__included__
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -7,22 +7,24 @@
|
|||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
||||
std::vector<char> do_patch_file(const std::vector<char>& original, const std::vector<char>& patch,
|
||||
namespace fileimage
|
||||
{
|
||||
std::vector<char> patch(const std::vector<char>& original, const std::vector<char>& patch,
|
||||
int32_t offset) throw(std::bad_alloc, std::runtime_error);
|
||||
|
||||
/**
|
||||
* ROM patcher.
|
||||
*/
|
||||
struct rom_patcher
|
||||
struct patcher
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
rom_patcher() throw(std::bad_alloc);
|
||||
patcher() throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~rom_patcher() throw();
|
||||
virtual ~patcher() throw();
|
||||
/**
|
||||
* Identify patch.
|
||||
*
|
||||
|
@ -36,5 +38,6 @@ struct rom_patcher
|
|||
virtual void dopatch(std::vector<char>& out, const std::vector<char>& original,
|
||||
const std::vector<char>& patch, int32_t offset) throw(std::bad_alloc, std::runtime_error) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -15,7 +15,7 @@
|
|||
#include "interface/callbacks.hpp"
|
||||
#include "library/framebuffer-pixfmt-rgb16.hpp"
|
||||
#include "library/controller-data.hpp"
|
||||
#include "library/patch.hpp"
|
||||
#include "library/fileimage-patch.hpp"
|
||||
#include "library/sha256.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/zip.hpp"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "minmax.hpp"
|
||||
#include "patch.hpp"
|
||||
#include "fileimage-patch.hpp"
|
||||
#include "serialization.hpp"
|
||||
#include "string.hpp"
|
||||
#include <cstdint>
|
||||
|
@ -8,6 +8,8 @@
|
|||
#include <iostream>
|
||||
#include <zlib.h>
|
||||
|
||||
namespace fileimage
|
||||
{
|
||||
namespace
|
||||
{
|
||||
uint8_t readbyte(const char* buf, uint64_t& pos, uint64_t size)
|
||||
|
@ -51,7 +53,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct bps_patcher : public rom_patcher
|
||||
struct bps_patcher : public patcher
|
||||
{
|
||||
~bps_patcher() throw();
|
||||
bool identify(const std::vector<char>& patch) throw();
|
||||
|
@ -173,3 +175,4 @@ namespace
|
|||
<< ".").throwex();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#include "minmax.hpp"
|
||||
#include "patch.hpp"
|
||||
#include "fileimage-patch.hpp"
|
||||
#include "serialization.hpp"
|
||||
#include "string.hpp"
|
||||
#include <cstdint>
|
||||
|
@ -7,6 +7,8 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
namespace fileimage
|
||||
{
|
||||
namespace
|
||||
{
|
||||
uint8_t readbyte(const char* buf, uint64_t& pos, uint64_t size)
|
||||
|
@ -17,7 +19,7 @@ namespace
|
|||
return static_cast<uint8_t>(buf[pos++]);
|
||||
}
|
||||
|
||||
struct ips_patcher : public rom_patcher
|
||||
struct ips_patcher : public patcher
|
||||
{
|
||||
~ips_patcher() throw();
|
||||
bool identify(const std::vector<char>& patch) throw();
|
||||
|
@ -31,8 +33,8 @@ namespace
|
|||
|
||||
bool ips_patcher::identify(const std::vector<char>& patch) throw()
|
||||
{
|
||||
return (patch.size() > 5 && patch[0] == 'P' && patch[1] == 'A' && patch[2] == 'T' && patch[3] == 'C' &&
|
||||
patch[4] == 'H');
|
||||
return (patch.size() > 5 && patch[0] == 'P' && patch[1] == 'A' && patch[2] == 'T' &&
|
||||
patch[3] == 'C' && patch[4] == 'H');
|
||||
}
|
||||
|
||||
void ips_patcher::dopatch(std::vector<char>& out, const std::vector<char>& original,
|
||||
|
@ -84,3 +86,4 @@ namespace
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#include "patch.hpp"
|
||||
#include "fileimage-patch.hpp"
|
||||
#include "sha256.hpp"
|
||||
#include "string.hpp"
|
||||
#include <cstdint>
|
||||
|
@ -6,16 +6,18 @@
|
|||
#include <iostream>
|
||||
#include <set>
|
||||
|
||||
namespace fileimage
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::set<rom_patcher*>& patchers()
|
||||
std::set<patcher*>& patchers()
|
||||
{
|
||||
static std::set<rom_patcher*> t;
|
||||
static std::set<patcher*> t;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<char> do_patch_file(const std::vector<char>& original, const std::vector<char>& patch,
|
||||
std::vector<char> patch(const std::vector<char>& original, const std::vector<char>& patch,
|
||||
int32_t offset) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
std::vector<char> out;
|
||||
|
@ -27,12 +29,13 @@ std::vector<char> do_patch_file(const std::vector<char>& original, const std::ve
|
|||
throw std::runtime_error("Unknown patch file format");
|
||||
}
|
||||
|
||||
rom_patcher::rom_patcher() throw(std::bad_alloc)
|
||||
patcher::patcher() throw(std::bad_alloc)
|
||||
{
|
||||
patchers().insert(this);
|
||||
}
|
||||
|
||||
rom_patcher::~rom_patcher() throw()
|
||||
patcher::~patcher() throw()
|
||||
{
|
||||
patchers().erase(this);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#include "fileimage.hpp"
|
||||
#include "sha256.hpp"
|
||||
#include "patch.hpp"
|
||||
#include "fileimage-patch.hpp"
|
||||
#include "string.hpp"
|
||||
#include "minmax.hpp"
|
||||
#include "zip.hpp"
|
||||
|
@ -505,7 +505,7 @@ void image::patch(const std::vector<char>& patch, int32_t offset) throw(std::bad
|
|||
std::vector<char> data2 = *data;
|
||||
if(type == info::IT_MARKUP)
|
||||
data2.resize(data2.size() - 1);
|
||||
data2 = do_patch_file(data2, patch, offset);
|
||||
data2 = ::fileimage::patch(data2, patch, offset);
|
||||
//Mark the slot as valid and update hash.
|
||||
std::string new_sha256 = sha256::hash(data2);
|
||||
if(type == info::IT_MARKUP) {
|
||||
|
|
Loading…
Add table
Reference in a new issue