-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgrf_func.cpp
119 lines (97 loc) · 2.73 KB
/
grf_func.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*############################################################################
## NEONCUBE - RAGNAROK ONLINE PATCH CLIENT (GNU General Public License)
##
## http://openkore.sourceforge.net/neoncube
## (c) 2005 Ansell "Cliffe" Cruz ([email protected])
##
##############################################################################*/
#include "precompiled.h"
#include <libgrf/grf.h>
#include <commctrl.h>
#include "main.h"
#include "archivefunc.h"
extern HWND hwndProgress;
//########################################################
// Extracts a GRF/GPF file
//
// @param fname - Filename to be extracted
//
// @return value - FALSE if an error occured, otherwise
// it returns TRUE.
//#########################################################
BOOL ExtractGRF(LPCSTR fname, LPCSTR fpath)
{
Grf *grf;
GrfError err;
grf = grf_open(fname, "r+b", &err);
if(!grf)
{
PostError(FALSE, "grflib failure message: %s", grf_strerror(err));
return FALSE;
}
SendMessage(hwndProgress, PBM_SETRANGE32, 0, grf->nfiles);
StatusMessage("Status: Extracting %s...\r\nInfo:------\r\nProgress:-----", fname);
for(DWORD ctr = 0;ctr < grf->nfiles; ctr++)
{
BOOL restarted = FALSE;
restart:
char szPath[GRF_NAMELEN];
int folders = 0;
int i;
if(lstrcmpiA(fpath, "FLD") == 0)
{
//patches will not be packed into a GRF
_tcscpy(szPath, grf->files[ctr].name);
}
else if(lstrcmpiA(fpath, "GRF") == 0)
{
//patches will be packed
lstrcpyA(szPath, "neoncube\\");
lstrcatA(szPath, grf->files[ctr].name);
}
else
{
PostError(TRUE, "Invalid patch_list string: %s \n2nd flag must be: FLD or GRF", fpath);
}
folders = CountFolders(szPath);
for(i = 1;i <= folders; i++)
{
char szCurrentFolder[GRF_NAMELEN];
lstrcpyA(szCurrentFolder,GetFolder(szPath,i));
CreateDirectory(szCurrentFolder,NULL);
}
GRF_normalize_path(szPath, szPath);
if(GRFFILE_IS_DIR(grf->files[ctr]))
{
CreateDirectory(szPath, NULL);
// else we extract it
}
else
{
if(grf_index_extract(grf, ctr, szPath, &err) > 0)
{
StatusMessage("Status: %s...\r\nInfo: %d of %d extracted\r\nProgress:-----", grf->files[ctr].name, ctr, grf->nfiles);
}
else
{
if(!restarted)
{
char buff[256];
WCHAR wcBuff[256];
MultiByteToWideChar(CP_ACP, 0, grf->files[ctr].name, -1, wcBuff, sizeof(wcBuff)/sizeof(wcBuff[0]));
WideCharToMultiByte(CP_ACP, 0, wcBuff, -1, buff, sizeof(buff), NULL, NULL);
lstrcpyA(grf->files[ctr].name, buff);
restarted = TRUE;
goto restart;
}
else
{
AddErrorLog("Failed to extract %s [code: %d, %s]\n", grf->files[ctr].name, err.type, grf_strerror(err));
}
}
}
SendMessage(hwndProgress, PBM_SETPOS, (WPARAM)ctr+1, 0);
}
grf_free(grf);
return TRUE;
}