-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.cpp
More file actions
71 lines (59 loc) · 1.23 KB
/
Copy pathfunctions.cpp
File metadata and controls
71 lines (59 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "zlib/unzip.h"
#include "sdl/include/sdl.h"
#pragma comment(lib, "zlib/zlibstat.lib")
//打开ZIP文件中的指定文件, 读到新分配的空间(返), 并取得文件实际大小(返)
// 1=成功 0=失败
int loadzipfile(char* zipfile,
char* filename,
char** destbuf,
int* filesize)
{
int err;
unzFile uf=NULL;
unz_file_info finfo;
uf = unzOpen(zipfile);
if (uf==NULL)
return 0;
err=unzLocateFile(uf,filename,0);
if (err!=UNZ_OK)
{
unzClose(uf);
return 0;
}
unzGetCurrentFileInfo (uf, &finfo, NULL,0, NULL,0, NULL,0);
*filesize=finfo.uncompressed_size;
err=unzOpenCurrentFile(uf);
if (err!=UNZ_OK)
{
unzClose(uf);
return 0;
}
*destbuf=(char*)malloc(finfo.uncompressed_size);
err=unzReadCurrentFile(uf,*destbuf,finfo.uncompressed_size);
if (err!=(int)finfo.uncompressed_size)
{
free(*destbuf);
*destbuf=NULL;
return 0;
}
unzCloseCurrentFile(uf);
unzClose(uf);
return 1;
}
int loadfile(char* filename, char** destbuf, int* filesize)
{
FILE* wf=fopen(filename, "rb");
*destbuf=0;
*filesize=0;
if (!wf)
return 0;
fseek(wf, 0, SEEK_END);
*filesize=ftell(wf);
fseek(wf, 0, SEEK_SET);
*destbuf=(char*)malloc(*filesize);
if (!destbuf)
return 0;
fread(*destbuf, 1, *filesize, wf);
fclose(wf);
return 1;
}