Exemplo n.º 1
0
	bool Zip::open(const char* file)
	{
		_zipFile = unzOpen(file);

		if (!_zipFile)
			return false;

		char szCurrentFileName[PATH_MAX];
		unz_file_info64 fileInfo;

		int err = unzGoToNextFile2(_zipFile, &fileInfo,
			szCurrentFileName, sizeof(szCurrentFileName) - 1, nullptr, 0, nullptr, 0);
		while (err == UNZ_OK)
		{
			unz_file_pos posInfo;
			if (unzGetFilePos(_zipFile, &posInfo) == UNZ_OK)
			{
				std::string currentFileName = szCurrentFileName;

				ZipEntryInfo entry;
				entry.pos = posInfo;
				entry.uncompressed_size = (uLong)fileInfo.uncompressed_size;
				_files[currentFileName] = entry;
			}
			err = unzGoToNextFile2(_zipFile, &fileInfo,
				szCurrentFileName, sizeof(szCurrentFileName) - 1, nullptr, 0, nullptr, 0);
		}

		return true;
	}
Exemplo n.º 2
0
int archiveOpen(char *file) {
	// Start position of the archive path
	archive_path_start = strlen(file) + 1;

	// Close previous zip file first
	if (uf)
		unzClose(uf);

	// Open zip file
	uf = unzOpen64(file);
	if (!uf)
		return -1;

	// Clear archive list
	memset(&archive_list, 0, sizeof(FileList));

	// Go through all files
	int res;
	char name[MAX_PATH_LENGTH];
	unz_file_info64 file_info;

	res = unzGoToFirstFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0);
	if (res < 0)
		return res;

	while (res >= 0) {
		FileListEntry *entry = malloc(sizeof(FileListEntry));

		// File info
		strcpy(entry->name, name);
		entry->is_folder = 0;
		entry->name_length = file_info.size_filename;
		entry->size = file_info.uncompressed_size;
		entry->size2 = file_info.compressed_size;

		// Time
		SceDateTime time;
		sceRtcSetDosTime(&time, file_info.dosDate);
		convertLocalTimeToUtc(&time, &time);

		memcpy(&entry->ctime, &time, sizeof(SceDateTime));
		memcpy(&entry->mtime, &time, sizeof(SceDateTime));
		memcpy(&entry->atime, &time, sizeof(SceDateTime));

		// Get pos
		unzGetFilePos64(uf, (unz64_file_pos *)&entry->reserved);

		// Add entry
		fileListAddEntry(&archive_list, entry, SORT_BY_NAME);

		// Next
		res = unzGoToNextFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0);
	}

	return 0;
}