-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
66 lines (55 loc) · 1.41 KB
/
main.c
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
#include <io.h>
#include <stddef.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include "pack_file.h"
#include "main.h"
#ifdef _WIN32
#include <windows.h>
#include <direct.h>
#endif
pack_file_t* pack_files;
/* stackoverflow.com/a/2736841 */
char *ext_remove(const char* myStr) {
char *retStr;
char *lastExt;
if (myStr == NULL) return NULL;
if ((retStr = malloc (strlen (myStr) + 1)) == NULL) return NULL;
strcpy (retStr, myStr);
lastExt = strrchr (retStr, '.');
if (lastExt != NULL)
*lastExt = '\0';
return retStr;
}
int main(int argc, char const *argv[])
{
printf("RipMort %s\n",VERSION);
if(argc < 2) {
perror("Give me files");
exit(EXIT_FAILURE);
}
for (int i = 1; i < argc; ++i) {
char* argv_no_ext = ext_remove(argv[i]);
pack_file_t pack_file = load_pack_file(argv[i]);
mkdir(argv_no_ext);
/* Random size */
char path[0xFF];
for (int j = 0; j < pack_file.item_count; ++j) {
/* Make file name */
sprintf(path, "%s/%s", argv_no_ext, pack_file.items[j].name);
FILE* fp = fopen(path, "wb");
if(!fp) {
perror("Error creating extracted item");
exit(EXIT_FAILURE);
}
fwrite(pack_file.items[j].data, pack_file.items[j].data_length, 1, fp);
fclose(fp);
}
free_pack_file(&pack_file);
free(argv_no_ext);
}
return 0;
}