More stuff
This commit is contained in:
27
source/fs.c
27
source/fs.c
@@ -90,4 +90,31 @@ Result file_to_buf(FS_Path path, char* buf)
|
||||
buf = malloc(size);
|
||||
res = FSFILE_Read(file, NULL, 0, buf, size);
|
||||
return res;
|
||||
}
|
||||
|
||||
int zip_file_to_buf(char *file_name, u16 *zip_path, char *buf)
|
||||
{
|
||||
ssize_t len = strulen(zip_path, 0x106);
|
||||
|
||||
u8 *path = calloc(sizeof(u8), len * 4);
|
||||
utf16_to_utf8(path, zip_path, len);
|
||||
|
||||
unzFile zip_handle = unzOpen((char*)path);
|
||||
|
||||
if (zip_handle == NULL) return 1;
|
||||
|
||||
if (unzLocateFile(zip_handle, file_name, 0) == UNZ_OK)
|
||||
{
|
||||
unz_file_info *file_info = malloc(sizeof(unz_file_info));
|
||||
ssize_t file_size = file_info->uncompressed_size;
|
||||
free(file_info);
|
||||
buf = malloc(file_size);
|
||||
unzOpenCurrentFile(zip_handle);
|
||||
unzReadCurrentFile(zip_handle, buf, file_size);
|
||||
unzCloseCurrentFile(zip_handle);
|
||||
unzClose(zip_handle);
|
||||
}
|
||||
|
||||
free(path);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user