-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgaf.cpp
More file actions
172 lines (151 loc) · 5.26 KB
/
Copy pathgaf.cpp
File metadata and controls
172 lines (151 loc) · 5.26 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/***************************************************************
** DLSTORM
** /\
** ---- D/L \----
** \/
** License: BSD
** Copyright: 2020
** File: gaf.cpp
** Description: GAF Game Archive File manager
** Author: Seth Parson aka Deadline
** Twitter: @Sethcoder
** Website: www.sethcoder.com
** Email: defectiveseth@gmail.com
***************************************************************/
#include "gaf.h"
CGAF *pGAF;
char szTopCWD[1024];
char szCWD[1024];
char szDir[1024];
GAF_SCANCALLBACK dir_callback(GAFFile_ElmHeader *ElmInfo, LPSTR FullPath) {
switch (ElmInfo->Type) {
case GAFELMTYPE_FILE:
#ifndef _WIN32
printf("%20d %-25s \n", ElmInfo->FileSize, ElmInfo->Name);
#else
printf("%20ld %-25s \n", ElmInfo->FileSize, ElmInfo->Name);
#endif
break;
case GAFELMTYPE_DIR:
printf("====== DIR: %-25s \n", ElmInfo->Name);
break;
default: break;
}
return 0;
}
GAF_SCANCALLBACK dir_callback_extract(GAFFile_ElmHeader *ElmInfo, LPSTR FullPath) {
switch (ElmInfo->Type) {
case GAFELMTYPE_FILE:
#ifndef _WIN32
printf("%20d %-25s \n", ElmInfo->FileSize, ElmInfo->Name);
#else
printf("%20ld %-25s \n", ElmInfo->FileSize, ElmInfo->Name);
#endif
pGAF->ExtractFile_ToFile(va("%s/%s", szDir, ElmInfo->Name), ElmInfo->Name);
break;
case GAFELMTYPE_DIR:
printf("====== DIR: %-25s \n", ElmInfo->Name);
strcpy(szDir, ElmInfo->Name);
dlcs_chdir(szTopCWD);
if (!dlcs_isdir(szDir)) dlcs_mkdir(szDir);
dlcs_chdir(szDir);
break;
default: break;
}
return 0;
}
int main(int argc, char *argv[]) {
setvbuf(stdout, NULL, _IONBF, 0);
char file[1024];
memset(file, 0, 1024);
strcpy(file, "gaf.gaf");
char res[1024];
memset(res, 0, 1024);
unsigned int i;
memset(szTopCWD, 0, 1024);
strcpy(szTopCWD, dlcs_getcwd());
pGAF = new CGAF();
if (argc < 3) {
print_help();
return 1;
}
strcpy(file, argv[1]);
switch (argv[2][1]) {
case 'a':
for (i = 3; i < strlen(argv[2]); i++) {
res[i - 3] = argv[2][i];
}
printf("Adding file %s to %s...\n", res, file);
pGAF->Open(file);
pGAF->AddFile(res, res);
pGAF->Close();
break;
case 'z':
for (i = 3; i < strlen(argv[2]); i++) {
res[i - 3] = argv[2][i];
}
printf("Adding directory %s to %s...\n", res, file);
pGAF->Open(file);
pGAF->AddDir(res);
pGAF->Close();
break;
case 'd':
for (i = 3; i < strlen(argv[2]); i++) {
res[i - 3] = argv[2][i];
}
printf("Removing file %s from %s...\n", res, file);
pGAF->Open(file);
pGAF->RemoveFile(res);
pGAF->Close();
break;
case 'c':
for (i = 3; i < strlen(argv[2]); i++) {
res[i - 3] = argv[2][i];
}
printf("Removing directory %s from %s...\n", res, file);
pGAF->Open(file);
pGAF->RemoveDir(res);
pGAF->Close();
break;
case 'x':
printf("EXTRACT\n");
printf("Working in %s\n", szTopCWD);
memset(szDir, 0, 1024);
memset(szCWD, 0, 1024);
dlcs_chdir(szTopCWD);
pGAF->Open(file);
pGAF->ScanTree("", (GAF_SCANCALLBACK)dir_callback_extract);
pGAF->Close();
break;
case 'l':
printf("LIST CONTENTS\n");
pGAF->Open(file);
pGAF->ScanTree("", (GAF_SCANCALLBACK)dir_callback);
pGAF->Close();
break;
default:
printf("Unknown or missing command. \n");
print_help();
break;
}
DEL(pGAF);
return 0;
}
void print_help(void) {
printf("\n");
printf("GAF Game Archive File by Seth Parson aka Deadline sethcoder.com\n");
printf("This application is based on the NukeDX SDK NUK file format.\n");
printf("nukesoftware.dk (Which is no longer available.)\n");
printf("NOTE: This archive format only nests one level of folder.\n");
printf("=======================================================\n");
printf("VERSION: %s compiled %s @ %s \n", GAFMAKEVERSION, __DATE__, __TIME__);
printf("=======================================================\n");
printf("USAGE:\n");
printf("gaf <gaf file> [-a:<filename>] [-z:<dir>] [-d:<file>] [-c:<dir>] [-x]\n");
printf("-a add a file to the GAF (This will create a new GAF if it does not exist)\n");
printf("-z add directory to the GAF (This will create a new GAF if it does not exist)\n");
printf("-d remove a file from the GAF\n");
printf("-c remove a directory from the GAF\n");
printf("-x extract GAF into the working directory\n");
printf("-l list contents\n");
}