-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
111 lines (106 loc) · 2.58 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
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
#include <getopt.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "tpak.h"
#ifdef HAVE_LUAJIT
#include "lua.h"
#endif
extern bool verbose;
// right now not really guessing, just a single hardcoed path
char *guess_path() {
char *path = "/.local/share/Steam/steamapps/common/star conflict/data/";
char *home = NULL;
if ((home = getenv("HOME")) == NULL)
return NULL;
char *ret = malloc(strlen(path) + strlen(home) + 1);
strcpy(ret, home);
strcat(ret, path);
return ret;
}
void usage(char* argv0, int ret) {
fprintf(stdout,
"Usage: %s [OPTIONS]\n\n"
"OPTIONS\n"
" -i --in <dir> Path to game dir (default to Steam installation in ~/.local/share\n"
" -o --out <dir> Path to outpit dir (default to ./)\n"
" -l --list Only list files, do no extract anything\n"
" -f --file <path> Only extract a single file\n"
" -c --console launch lua console\n"
" -v --verbose Enable verbose output\n"
" -h --help Print help\n", basename(argv0));
exit(ret);
}
int main(int argc, char **argv) {
bool list = false, console = false;
int c;
char *input = NULL;
char *outdir = NULL;
char *file = NULL;
const char * options = ":i:vo:lhf:c";
const struct option longoptions[] = {
{ "in", required_argument, NULL, 'i' },
{ "out", required_argument, NULL, 'o' },
{ "file", required_argument, NULL, 'f' },
{ "list", no_argument, NULL, 'l' },
{ "verbose", no_argument, NULL, 'v'},
{ "help", no_argument, NULL, 'h' },
{ "console", no_argument, NULL, 'c' }
};
while((c = getopt_long(argc, argv, options, longoptions, NULL)) != -1) {
switch(c) {
case 'i':
input = optarg;
break;
case 'o':
outdir = optarg;
break;
case 'f':
file = optarg;
break;
case 'h':
usage(argv[0], EXIT_SUCCESS);
break;
case 'v':
verbose = true;
break;
case 'l':
list = true;
break;
case 'c':
console = true;
break;
default:
usage(argv[0], EXIT_FAILURE);
break;
}
}
if(input == NULL) {
// not freed anywhere so far
if((input = guess_path()) == NULL) {
fprintf(stderr, "Cannon guess data path, please manual provide one with --in/-i <path>\n");
exit(EXIT_FAILURE);
}
}
if(file != NULL) {
read_input(input);
print_file(file);
} else if(list) {
read_input(input);
print_all(true);
} else if (console) {
#ifdef HAVE_LUAJIT
read_input(input);
if(initLua() == 0) luaConsole();
closeLua();
#else
fprintf(stderr, "Compiled without LuaJIT");
#endif
} else {
extract_all(input, outdir, true);
}
tpak_free();
}