他人の空似自作物置場

touhouSE_th145BGMOnly.zip/touhouSE_src/main.h


enum DAT_VER {
	DAT_VER_TH105 = 0,
	DAT_VAR_TH075,
	DAT_VAR_TH11,
	DAT_VAR_TH12,
	DAT_VAR_TH13,
	DAT_VAR_THMJ,
	DAT_VAR_TNB,
	DAT_VAR_NPA,
	DAT_VAR_MAX,
	DAT_VER_UNKNOWN = DAT_VAR_MAX,
};

typedef struct data_list{
	char fn[100];
	unsigned int size;
	unsigned int comp_size;
	unsigned int addr;
}LIST;

extern char dat_name[256];

DAT_VER GetList(std::vector<boost::shared_ptr<LIST> > &list, boost::shared_ptr<FILE> fp);
bool PutFile(DAT_VER dat_ver, boost::shared_ptr<const LIST> file_data, const std::vector<unsigned char> &data, const std::vector<boost::shared_ptr<LIST> > &list, boost::shared_ptr<FILE> fp);
bool Extract(std::vector<unsigned char> &data, DAT_VER dat_ver, boost::shared_ptr<const LIST> file_data, boost::shared_ptr<FILE> fp);






class ExtractorBase : boost::noncopyable {
public:
	virtual bool Extract(const unsigned int index, std::vector<unsigned char> &result) = 0;
	virtual unsigned int GetSize() const = 0;
	virtual std::wstring GetName() const = 0;
	virtual boost::filesystem::path GetFileName(unsigned int index) const = 0;
};

class DatExtractor : boost::noncopyable {
private:
	static DatExtractor *instance;
	std::vector<boost::function<boost::shared_ptr<ExtractorBase> (std::istream &/*in*/, const unsigned long long int /*fileSize*/)> > openFuncList;

	DatExtractor() { }

  bool ExtractImpl(const boost::filesystem::path &fileName, const std::vector<unsigned char> &data, ExtractorBase &ownerExtractor);

public:
	static DatExtractor &GetInstance() {
		if (DatExtractor::instance == NULL) {
			DatExtractor::instance = new DatExtractor();
		}
		return *DatExtractor::instance;
	}
	template<typename T>
	void Add() {
		this->openFuncList.push_back(boost::bind(typename T::Open, _1, _2));
	}
	bool ExtractAll(const boost::filesystem::path &path);
};

template<typename T>
class ExtractorAdder : boost::noncopyable {
public:
	ExtractorAdder() {
		DatExtractor::GetInstance().Add<T>();
	}
};

#define ADD_DAT_EXTRACTOR(extractorClass) ExtractorAdder<extractorClass> datClass##__LINE__







class ConverterBase : boost::noncopyable {
public:
};

class FileConverter : boost::noncopyable {
private:
	static FileConverter *instance;
	std::vector<boost::function<bool (
    const boost::filesystem::path &,
    const std::vector<unsigned char> &,
    boost::filesystem::path &,
    std::vector<unsigned char> &,
    ExtractorBase &)> > convertFuncList;

	FileConverter() { }

public:
	static FileConverter &GetInstance() {
		if (FileConverter::instance == NULL) {
			FileConverter::instance = new FileConverter();
		}
		return *FileConverter::instance;
	}
	template<typename T>
	void Add() {
		this->convertFuncList.push_back(boost::bind(typename T::Convert, _1, _2, _3, _4, _5));
	}
	bool Convert(
    const boost::filesystem::path &fileName,
    const std::vector<unsigned char> &data,
    boost::filesystem::path &resultFileName,
    std::vector<unsigned char> &result,
    ExtractorBase &extractor) const {
		BOOST_FOREACH(
			const boost::function<bool (
      const boost::filesystem::path &,
      const std::vector<unsigned char> &,
      boost::filesystem::path &,
      std::vector<unsigned char> &,
      ExtractorBase &)> &func,
			this->convertFuncList)
		{
			if (func(fileName, data, resultFileName, result, extractor)) {
				return true;
			}
		}
		return false;
	}
};

template<typename T>
class ConverterAdder : boost::noncopyable {
public:
	ConverterAdder() {
		FileConverter::GetInstance().Add<T>();
	}
};

#define ADD_FILE_CONVERTER(converterClass) ConverterAdder<converterClass> converterClass##__LINE__