]> git.saurik.com Git - ldid.git/blame - ldid.hpp
Add name of hash algorithm to Algorithm structure.
[ldid.git] / ldid.hpp
CommitLineData
a0c715e9
JF
1#ifndef LDID_HPP
2#define LDID_HPP
3
4#include <cstdlib>
5#include <map>
fc01987c 6#include <set>
42d1472e 7#include <sstream>
a0c715e9
JF
8#include <streambuf>
9#include <string>
42d1472e 10#include <vector>
a0c715e9
JF
11
12namespace ldid {
13
e6a376fc
JF
14// I wish Apple cared about providing quality toolchains :/
15
16template <typename Function_>
17class Functor;
18
19template <typename Type_, typename... Args_>
20class Functor<Type_ (Args_...)> {
21 public:
22 virtual Type_ operator ()(Args_... args) const = 0;
23};
24
25template <typename Function_>
26class FunctorImpl;
27
28template <typename Value_, typename Type_, typename... Args_>
29class FunctorImpl<Type_ (Value_::*)(Args_...) const> :
30 public Functor<Type_ (Args_...)>
31{
32 private:
33 const Value_ *value_;
34
35 public:
36 FunctorImpl(const Value_ &value) :
37 value_(&value)
38 {
39 }
40
41 virtual Type_ operator ()(Args_... args) const {
42 return (*value_)(args...);
43 }
44};
45
46template <typename Function_>
47FunctorImpl<decltype(&Function_::operator())> fun(const Function_ &value) {
48 return value;
49}
50
23c11ee8
JF
51class Folder {
52 public:
addc31c5
JF
53 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code) = 0;
54 virtual bool Look(const std::string &path) const = 0;
e1d26767 55 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const = 0;
addc31c5 56 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const = 0;
23c11ee8
JF
57};
58
59class DiskFolder :
60 public Folder
61{
62 private:
63 const std::string path_;
64 std::map<std::string, std::string> commit_;
65
d58cc49d 66 protected:
addc31c5 67 std::string Path(const std::string &path) const;
23c11ee8 68
d58cc49d 69 private:
addc31c5 70 void Find(const std::string &root, const std::string &base, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
54a0f854 71
23c11ee8
JF
72 public:
73 DiskFolder(const std::string &path);
74 ~DiskFolder();
75
addc31c5
JF
76 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
77 virtual bool Look(const std::string &path) const;
e1d26767 78 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
addc31c5 79 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
23c11ee8
JF
80};
81
82class SubFolder :
83 public Folder
84{
85 private:
2443500c 86 Folder &parent_;
23c11ee8
JF
87 std::string path_;
88
89 public:
2443500c 90 SubFolder(Folder &parent, const std::string &path);
23c11ee8 91
addc31c5
JF
92 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
93 virtual bool Look(const std::string &path) const;
e1d26767 94 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
addc31c5 95 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
23c11ee8
JF
96};
97
886cb3f1
JF
98class UnionFolder :
99 public Folder
100{
101 private:
4e6d856a
JF
102 struct Reset {
103 const void *flag_;
104 std::streambuf *data_;
4d453c35
JF
105 };
106
886cb3f1 107 Folder &parent_;
7c49f771
JF
108 std::set<std::string> deletes_;
109
110 std::map<std::string, std::string> remaps_;
4e6d856a 111 mutable std::map<std::string, Reset> resets_;
7c49f771 112
addc31c5 113 std::string Map(const std::string &path) const;
e1d26767 114 void Map(const std::string &path, const Functor<void (const std::string &)> &code, const std::string &file, const Functor<void (const Functor<void (std::streambuf &, size_t, const void *)> &)> &save) const;
886cb3f1
JF
115
116 public:
117 UnionFolder(Folder &parent);
118
addc31c5
JF
119 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
120 virtual bool Look(const std::string &path) const;
e1d26767 121 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
addc31c5 122 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
886cb3f1 123
7c49f771
JF
124 void operator ()(const std::string &from) {
125 deletes_.insert(from);
126 }
127
128 void operator ()(const std::string &from, const std::string &to) {
129 operator ()(from);
130 remaps_[to] = from;
131 }
132
4e6d856a 133 void operator ()(const std::string &from, const void *flag, std::streambuf &data) {
fefcecb0
JF
134 operator ()(from);
135 auto &reset(resets_[from]);
4e6d856a
JF
136 reset.flag_ = flag;
137 reset.data_ = &data;
886cb3f1
JF
138 }
139};
140
f74652ab
JF
141struct Hash {
142 uint8_t sha1_[0x14];
143 uint8_t sha256_[0x20];
144};
145
4ebf3494
JF
146struct Bundle {
147 std::string path;
f74652ab 148 Hash hash;
4ebf3494
JF
149};
150
8afb9766 151Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &requirements, const Functor<std::string (const std::string &, const std::string &)> &alter, const Functor<void (const std::string &)> &progress, const Functor<void (double)> &percent);
2dcf3faf 152
f74652ab 153typedef std::map<uint32_t, Hash> Slots;
a0c715e9 154
8afb9766 155Hash Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &requirements, const std::string &key, const Slots &slots, const Functor<void (double)> &percent);
a0c715e9
JF
156
157}
158
159#endif//LDID_HPP