Ejemplo n.º 1
0
void AnsiFileSystem::AttachArchive(const char8 * archiveName, const char8 * attachPath)
{	
	ResourceArchive * resourceArchive = new ResourceArchive();
	
	if (!resourceArchive->Open(archiveName)) 
	{
		delete resourceArchive;
		resourceArchive = 0;
		return;
	}
	ResourceArchiveItem item;
	item.attachPath = attachPath;
	item.archive = resourceArchive;
	resourceArchiveList.push_back(item);
};
int main(int argc, char* argv[])
{
	
	if (argc <= 2)
	{
		printf("Usage: resourcepacker.exe [-d] [-u] [resourceDirectoryPath] [archiveName]\n");
		printf("Written by Borodovsky Vitaliy (C) 2006.\n");
		printf("Example:\n");
		printf("resourcepacker.exe -d data data.re\n\t- pack directory data to archive data.re\n");
		printf("resourcepacker.exe -u data data.re\n\t- unpack archive data.re to directory data\n");
		printf("Options:\n");
		printf("\t -d don't include to archive relative pathnames\n");
		printf("\t -u unpack archive with contents\n");
		return 0;
	}
	
	bool	packPaths = true;
	bool	showMode = false;
	String	directoryPath;
	String  archiveName;
	String	headerName;
	
	int32 pathIndex = 1;
	
	for (int flag = 0; flag < 2; ++flag)
	{
		if (String(argv[pathIndex]) == "-d")
		{
			pathIndex++;
			packPaths = false;
		}
		else if (String(argv[pathIndex]) == "-u")
		{
			pathIndex++;
			showMode = true;
		}
	}
	

//	IEngineSystem * es = CreateConsoleEngine();
	new AnsiFileSystem();
	
	IFileSystem * fs = Singleton<IO::IFileSystem>::Instance();
	String programmPath = fs->GetCurrentDirectory();

	if (showMode)	// show mode of ResourcePacker tool
	{
		directoryPath = argv[pathIndex];	
		
		if (directoryPath.find(':') == -1)
		{
			directoryPath = programmPath + "/" + directoryPath;
		}

		if ((pathIndex + 1) > (argc - 1))
		{
			String::size_type pos = directoryPath.rfind('/');
			if (pos == -1)
			{
				archiveName = directoryPath + ".re";
			}else
			{
				archiveName = directoryPath.substr(pos + 1) + ".re";
			}
		}else
		{
			archiveName = argv[pathIndex + 1];
			String::size_type pos = archiveName.rfind('.');
			if (pos == -1)
			{
				headerName = archiveName;
				archiveName += ".re";
				headerName += ".h";
			}
		}


		printf("===================================================\n");
		printf("=== Unpacker started\n");
		printf("=== Unpack directory: %s\n", directoryPath.c_str());
		printf("=== Unpack archiveName: %s\n", archiveName.c_str());
		printf("===================================================\n");


		fs->CreateDirectory(directoryPath.c_str());

		ResourceArchive ra;
		ra.Open(programmPath + "/" + archiveName);
		
		

		for (int file = 0; file < ra.GetFileCount(); ++file)
		{
			String pathName = ra.GetResourcePathname(file);
			pathName = directoryPath + pathName;
			
			String::size_type pos = pathName.rfind('/');
			if (pos == -1)
			{
			}else
			{
				String dirCreate = pathName.substr(0, pos);
				fs->CreateDirectory(dirCreate.c_str());
			}

			int32 size = ra.LoadResource(file, 0);
			uint8 * data = new uint8[size];
			ra.LoadResource(file, data);
					
			IFile * unpackFile = fs->CreateFile(pathName.c_str(), IO::EFA_CREATE | IO::EFA_WRITE);
			if (unpackFile)
			{
				unpackFile->Write(data, size);
				SafeRelease(unpackFile);
			}
			else
			{
				
			}

			delete [] data;
		}

	}else	// archive mode of ResourcePacker tool
	{
		directoryPath = argv[pathIndex];	

		if (directoryPath.find(':') == -1)
		{
			directoryPath = programmPath + "/" + directoryPath;
		}


		if ((pathIndex + 1) > (argc - 1))
		{
			String::size_type pos = directoryPath.rfind('/');
			if (pos == -1)
			{
				archiveName = directoryPath + ".re";
				headerName = directoryPath + ".h";
			}else
			{
				archiveName = directoryPath.substr(pos + 1) + ".re";
				headerName = directoryPath.substr(pos + 1) + ".h";
			}
		}else
		{
			archiveName = argv[pathIndex + 1];
			String::size_type pos = archiveName.rfind('.');
			if (pos == -1)
			{
				headerName = archiveName;
				archiveName += ".re";
				headerName += ".h";
			}else
			{
				headerName = archiveName.substr(0, pos) + ".h";
			}
		}

		printf("===================================================\n");
		printf("=== Packer started\n");
		printf("=== Include relative filepaths %s\n", (packPaths == true)? ("enabled"):("disabled"));
		printf("=== Pack directory: %s\n", directoryPath.c_str());
		printf("=== Pack archiveName: %s\n", archiveName.c_str());
		printf("=== Pack headerName: %s\n", headerName.c_str());
		printf("===================================================\n");

		Packer * packer = new Packer(programmPath + "/" + archiveName, directoryPath, programmPath + "/" + headerName);

		packer->Pack(packPaths);

		delete packer;
		packer = 0;
	}
	

//	SafeRelease(es);

	return 0;
}