Exemplo n.º 1
0
BYTE uncomp_zip_file_from_archive(_uncomp_file_data *file) {
    mz_zip_archive zip_archive;

    memset(&zip_archive, 0, sizeof(zip_archive));

    if (!mz_zip_reader_init_file(&zip_archive, info.rom_file, 0)) {
        fprintf(stderr, "mz_zip_reader_init_file() failed!\n");
        return (EXIT_ERROR);
    }

    mz_zip_reader_get_filename(&zip_archive, file->num, uncomp.buffer, sizeof(uncomp.buffer));

    snprintf(uncomp.uncompress_file, sizeof(uncomp.uncompress_file), "%s" TMP_FOLDER "/%s",
             info.base_folder, basename(uncomp.buffer));

    if (mz_zip_reader_extract_to_file(&zip_archive, file->num, uncomp.uncompress_file, 0)) {
        strncpy(uncomp.compress_archive, info.rom_file, sizeof(uncomp.compress_archive));
        strncpy(info.rom_file, uncomp.uncompress_file, sizeof(info.rom_file));
        info.uncompress_rom = TRUE;
    } else {
        fprintf(stderr, "unzip file failed!\n");
    }

    // Close the archive, freeing any resources it was using
    mz_zip_reader_end(&zip_archive);

    return (EXIT_OK);
}
Exemplo n.º 2
0
static int Lreader_get_filename(lua_State* L) {
    mz_zip_archive *za = luaL_checkudata(L, 1, LMZ_ZIP_READER);
    mz_uint file_index = (mz_uint)luaL_checkinteger(L, 2) - 1;
    char filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
    if (!mz_zip_reader_get_filename(za, file_index,
                filename, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE))
        return lmz_zip_pusherror(L, za, NULL);
    lua_pushstring(L, filename);
    return 1;
}
Exemplo n.º 3
0
static int lmz_reader_get_filename(lua_State* L) {
  lmz_file_t* zip = luaL_checkudata(L, 1, "miniz_reader");
  mz_uint file_index = (mz_uint)luaL_checkinteger(L, 2) - 1;
  char pFilename[PATH_MAX];
  mz_uint filename_buf_size = PATH_MAX;
  if (!mz_zip_reader_get_filename(&(zip->archive), file_index, pFilename, filename_buf_size)) {
    lua_pushnil(L);
    lua_pushfstring(L, "%d is an invalid index", file_index);
    return 2;
  }
  lua_pushstring(L, pFilename);
  return 1;
}
Exemplo n.º 4
0
BYTE uncomp_zip_name_file_compress(_uncomp_file_data *file) {
    mz_zip_archive zip_archive;

    memset(&zip_archive, 0, sizeof(zip_archive));

    if (!mz_zip_reader_init_file(&zip_archive, info.rom_file, 0)) {
        fprintf(stderr, "mz_zip_reader_init_file() failed!\n");
        return (EXIT_ERROR);
    }

    mz_zip_reader_get_filename(&zip_archive, file->num, uncomp.buffer, sizeof(uncomp.buffer));

    // Close the archive, freeing any resources it was using
    mz_zip_reader_end(&zip_archive);

    return (EXIT_OK);
}
Exemplo n.º 5
0
static int Lreader___index(lua_State* L) {
    mz_zip_archive *za = luaL_checkudata(L, 1, LMZ_ZIP_READER);
    int type = lua_type(L, 2);
    if (type == LUA_TSTRING) {
        if (lua_getmetatable(L, 1)) {
            lua_pushvalue(L, 2);
            lua_rawget(L, -2);
            return 1;
        }
        return 0;
    }
    else if (type == LUA_TNUMBER) {
        mz_uint file_index = (mz_uint)luaL_checkinteger(L, 2) - 1;
        char filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
        if (!mz_zip_reader_get_filename(za, file_index,
                    filename, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE))
            return lmz_zip_pusherror(L, za, NULL);
        lua_pushstring(L, filename);
        return 1;
    }
    return 0;
}
Exemplo n.º 6
0
int main(int argc,char *argv[])
{
	if(argc != 4) {
		fprintf(stderr,"USAGE: %s extract <saz> <bin>\n",argv[0]);
		return 1;
	}

	const char *inPath = argv[2];
	const char *outPath = argv[3];

	mz_zip_archive zip={0};
	if(!mz_zip_reader_init_file(&zip,inPath,MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY)) {
		fprintf(stderr,"Failed to open '%s' for reading or invalid archive.\n",inPath);
		return 1;
	}

	FILE *outFile = fopen(outPath,"wb");
	if(outFile == NULL) {
		fprintf(stderr,"Failed to open '%s' for writing.\n",outPath);
		return 1;
	} 

	int files = mz_zip_reader_get_num_files(&zip);
	for(int i=0;i<files;i++) {
		char filename[1024];
		if(!mz_zip_reader_get_filename(&zip,i,filename,sizeof(filename))) {
			continue;
		}
		int httpIdx = -1;
		char ext[1024];
		if(sscanf(filename,"raw/%d_c.%s",&httpIdx,ext) != 2) {
			continue;
		}
		
		size_t postSize;
		char *post = (char *)mz_zip_reader_extract_to_heap(&zip,i,&postSize,0);
		if(post == NULL) {
			continue;
		}
		char *data = NULL;
		int nl=0;
		for(size_t j=0;j<postSize;j++) {
			if(post[j] == '\n' || post[j] == '\r') {
				nl++;
				if(nl == 4) {
					data = post+j+1;
					break;
				}
			} else {
				nl = 0;
			}
		}
		if(data && postSize-(data-post)) {
			fwrite(data,1,postSize-(data-post),outFile);
		}
		printf("%s\n",filename);
		free(post);
	}

	fclose(outFile);
	return 0;
}