#pragma once

#include "halleystring.h"
#include "resource_locator.h"

namespace Halley {
	class ResourcePackEntry {
	public:
		String name;
		String diskPath;
		size_t size;
		size_t sizeOnDisk;
		size_t pos;

		bool encrypted;
		bool zipped;
	};

	class ResourcePack : public ResourceLocator {
	public:
		ResourcePack(String name="");
		~ResourcePack();

		void add(String root, String file, bool encrypted=false, bool zipped=false);

		void save(String path);
		void load(String path);

	protected:
		shared_ptr<ResourceData> doGet(String resource);
		std::vector<String> getResourceList();
		int getPriority() const { return priority; }

	private:

		void writeHeader(FILE* fp);
		void writeTOC(FILE* fp);
		void writeFile(FILE* fp, ResourcePackEntry& entry);

		void readHeader(FILE* fp);
		void readTOC(FILE* fp);

		void encrypt(char* data, size_t size);
		void decrypt(char* data, size_t size);

		std::map<String, ResourcePackEntry> entries;
		int priority;
		FILE* fileP;
		String name;
	};
}
