예제 #1
0
void List(const char* file)
{
	FileSystem fs;
	if (fs.Open(file))
	{
		auto it = fs.Entries().begin();
		for (; it != fs.Entries().end(); it++)
		{
			const FileEntry& entry = it->second;
			FILEPACKER_LOGV("%s\n", entry.path.c_str());
		}
	}
	else
	{
		FILEPACKER_LOGE("ERROR: Unable to open %s\n", file);
	}
}
예제 #2
0
void Extract(ExtractParameters* extractparams)
{
	FileSystem fs;
	if (fs.Open(extractparams->file))
	{
		if (!CreateDir(extractparams->out_path))
		{
			FILEPACKER_LOGE("ERROR: Unable to create %s\n", extractparams->out_path);
			return;
		}

		std::string out_path(extractparams->out_path);
		std::set<std::string> dirs;
		auto it = fs.Entries().begin();
		for (; it != fs.Entries().end(); it++)
		{
			const FileEntry& entry = it->second;
			size_t found = entry.path.find_last_of("/\\");
			if (found != std::string::npos)
			{
				std::string path = entry.path.substr(0, found);
				found = 0;
				while (1)
				{
					found = path.find_first_of("/\\", found);
					std::string curr = path.substr(0, found);
					if (dirs.find(curr) == dirs.end())
					{
						std::string full_dir = out_path + "/" + curr;
						if (!CreateDir(full_dir.c_str()))
						{
							FILEPACKER_LOGE("ERROR: Unable to create %s\n", full_dir.c_str());
						}
						else
						{
							FILEPACKER_LOGV(" + Created dir %s\n", curr.c_str());
						}

						dirs.insert(curr);
					}

					if (found == std::string::npos)
						break;

					found++;
				}
			}

			unsigned char* buffer = new unsigned char[entry.header.uncompr_size];
			fs.Read(entry, buffer);

			std::string full_dir = out_path + "/" + entry.path;
			FILE* f = fopen(full_dir.c_str(), "wb+");
			if (f != NULL)
			{
				FILEPACKER_LOGV(" + Writing %s\n", entry.path.c_str());
				fwrite(buffer, 1, entry.header.uncompr_size, f);
				fclose(f);
			}
			else
			{
				FILEPACKER_LOGE("ERROR: Unable to write %s\n", entry.path.c_str());
			}
		}
	}
	else
	{
		FILEPACKER_LOGE("ERROR: Unable to open %s\n", extractparams->file);
	}
}