#include <cstdlib>
#include <map>
+#include <set>
+#include <sstream>
#include <streambuf>
#include <string>
+#include <vector>
namespace ldid {
class Folder {
public:
- virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0;
- virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0;
- virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code) = 0;
+ virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code) = 0;
+ virtual bool Look(const std::string &path) const = 0;
+ virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const = 0;
+ 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;
};
class DiskFolder :
const std::string path_;
std::map<std::string, std::string> 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<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)>&code);
+ private:
+ 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;
public:
DiskFolder(const std::string &path);
~DiskFolder();
- virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code);
- virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code);
- virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
+ virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
+ virtual bool Look(const std::string &path) const;
+ virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
+ 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;
};
class SubFolder :
public:
SubFolder(Folder &parent, const std::string &path);
- virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code);
- virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code);
- virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
+ virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
+ virtual bool Look(const std::string &path) const;
+ virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
+ 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;
};
class UnionFolder :
public Folder
{
private:
+ struct Reset {
+ const void *flag_;
+ std::streambuf *data_;
+ };
+
Folder &parent_;
- std::map<std::string, std::stringbuf> files_;
+ std::set<std::string> deletes_;
+
+ std::map<std::string, std::string> remaps_;
+ mutable std::map<std::string, Reset> resets_;
+
+ std::string Map(const std::string &path) const;
+ 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;
public:
UnionFolder(Folder &parent);
- virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code);
- virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code);
- virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
+ virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
+ virtual bool Look(const std::string &path) const;
+ virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
+ 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;
+
+ 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<std::string, std::vector<char>> &remote);
+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<std::string (const std::string &, const std::string &)> &alter, const Functor<void (const std::string &)> &progress, const Functor<void (double)> &percent);
-typedef std::map<uint32_t, std::vector<char>> Slots;
+typedef std::map<uint32_t, Hash> 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<void (double)> &percent);
}