// Read-only pack inspector: opens an existing .eix/.epk pair and prints every
// entry's stored filename, so we can learn the exact relative-path naming
// convention a given pack uses before writing anything back.
//
// Usage: PackList.exe <pathToPackFolder> <dbname>
//   e.g. PackList.exe "Y:\Metin2Dev\Exec_Client\pack" root

#include <windows.h>
#include <cstdio>
#include <string>
#include <vector>

#include "../EterPack/EterPack.h"

int main(int argc, char** argv)
{
	if (argc < 3)
	{
		fprintf(stderr, "Usage: %s <packFolder> <dbname>\n", argv[0]);
		return 1;
	}

	const char* pathName = argv[1];
	const char* dbname = argv[2];

	if (!SetCurrentDirectoryA(pathName))
	{
		fprintf(stderr, "FAILED to chdir to '%s'\n", pathName);
		return 4;
	}

	CEterFileDict dict;
	CEterPack pack;

	if (!pack.Create(dict, dbname, "", true))
	{
		fprintf(stderr, "FAILED to open pack '%s' in '%s'\n", dbname, pathName);
		return 2;
	}

	std::vector<std::string> names;
	if (!pack.GetNames(&names))
	{
		fprintf(stderr, "FAILED GetNames\n");
		return 3;
	}

	printf("Entries: %zu\n", names.size());
	for (auto& n : names)
		printf("%s\n", n.c_str());

	return 0;
}
