X-Git-Url: https://git.saurik.com/ldid.git/blobdiff_plain/42d1472e2c6d056d9c35f6f8d3b4f5c0237a320d..2da83dea4ef1fa6c8e8cc0f5f2fbe2dca6873e36:/ldid.hpp diff --git a/ldid.hpp b/ldid.hpp index 40b1c8b..a5cf5d7 100644 --- a/ldid.hpp +++ b/ldid.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -49,9 +50,10 @@ FunctorImpl fun(const Function_ &value) { class Folder { public: - virtual void Save(const std::string &path, const Functor &code) = 0; - virtual bool Open(const std::string &path, const Functor &code) = 0; - virtual void Find(const std::string &path, const Functor &)> &)> &code) = 0; + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code) = 0; + virtual bool Look(const std::string &path) const = 0; + virtual void Open(const std::string &path, const Functor &code) const = 0; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const = 0; }; class DiskFolder : @@ -61,17 +63,20 @@ class DiskFolder : const std::string path_; std::map commit_; - std::string Path(const std::string &path); + protected: + std::string Path(const std::string &path) const; - void Find(const std::string &root, const std::string &base, const Functor &)> &)>&code); + private: + void Find(const std::string &root, const std::string &base, const Functor &code, const Functor &)> &link) const; public: DiskFolder(const std::string &path); ~DiskFolder(); - virtual void Save(const std::string &path, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); - virtual void Find(const std::string &path, const Functor &)> &)> &code); + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code); + virtual bool Look(const std::string &path) const; + virtual void Open(const std::string &path, const Functor &code) const; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const; }; class SubFolder : @@ -84,48 +89,70 @@ class SubFolder : public: SubFolder(Folder &parent, const std::string &path); - virtual void Save(const std::string &path, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); - virtual void Find(const std::string &path, const Functor &)> &)> &code); + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code); + virtual bool Look(const std::string &path) const; + virtual void Open(const std::string &path, const Functor &code) const; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const; }; class UnionFolder : public Folder { private: - class StringBuffer : - public std::stringbuf - { - public: - StringBuffer() { - } - - StringBuffer(const StringBuffer &rhs) : - std::stringbuf(rhs.str()) - { - } + struct Reset { + const void *flag_; + std::streambuf *data_; }; Folder &parent_; - std::map files_; + std::set deletes_; + + std::map remaps_; + mutable std::map resets_; + + std::string Map(const std::string &path) const; + void Map(const std::string &path, const Functor &code, const std::string &file, const Functor &)> &save) const; public: UnionFolder(Folder &parent); - virtual void Save(const std::string &path, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); - virtual void Find(const std::string &path, const Functor &)> &)> &code); + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code); + virtual bool Look(const std::string &path) const; + virtual void Open(const std::string &path, const Functor &code) const; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const; + + void operator ()(const std::string &from) { + deletes_.insert(from); + } + + void operator ()(const std::string &from, const std::string &to) { + operator ()(from); + remaps_[to] = from; + } - std::stringbuf &operator [](const std::string &path) { - return files_[path]; + void operator ()(const std::string &from, const void *flag, std::streambuf &data) { + operator ()(from); + auto &reset(resets_[from]); + reset.flag_ = flag; + reset.data_ = &data; } }; -std::string Bundle(const std::string &root, Folder &folder, const std::string &key, std::map> &remote, const std::string &entitlements); +struct Hash { + uint8_t sha1_[0x14]; + uint8_t sha256_[0x20]; +}; + +struct Bundle { + std::string path; + Hash hash; +}; + +Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &requirements, const Functor &alter, const Functor &progress, const Functor &percent); -typedef std::map> Slots; +typedef std::map Slots; -void Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &key, const Slots &slots); +Hash 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 &percent); }