lsnes rr2-β24
[lsnes.git] / src / library / fileimage-patch.cpp
blob126f4bcfe465a52b854433d74a341b8e30b6c04f
1 #include "fileimage-patch.hpp"
2 #include "sha256.hpp"
3 #include "string.hpp"
4 #include <cstdint>
5 #include <cstring>
6 #include <iostream>
7 #include <set>
9 namespace fileimage
11 namespace
13 std::set<patcher*>& patchers()
15 static std::set<patcher*> t;
16 return t;
20 std::vector<char> patch(const std::vector<char>& original, const std::vector<char>& patch,
21 int32_t offset) throw(std::bad_alloc, std::runtime_error)
23 std::vector<char> out;
24 for(auto i : patchers())
25 if(i->identify(patch)) {
26 i->dopatch(out, original, patch, offset);
27 return out;
29 throw std::runtime_error("Unknown patch file format");
32 patcher::patcher() throw(std::bad_alloc)
34 patchers().insert(this);
37 patcher::~patcher() throw()
39 patchers().erase(this);