13 #define ADS ":::AGSpack " VERSION " by rofl0r:::"
15 static int usage(char *argv0
) {
17 "\nusage:\n%s OPTIONS directory target-pack\n\n"
19 "-e: recreate original exe stub\n"
24 int main(int argc
, char** argv
) {
26 while((c
= getopt(argc
, argv
, "e")) != -1) switch(c
) {
27 default: return usage(argv
[0]);
28 case 'e': exe_opt
= 1; break;
30 if (!argv
[optind
] || !argv
[optind
+1])
31 return usage(argv
[0]);
33 char *dir
= argv
[optind
];
34 char *pack
= argv
[optind
+1];
38 snprintf(fnbuf
, sizeof(fnbuf
), "%s%c%s", dir
, PSEP
, "agspack.info");
39 if(!(fp
= fopen(fnbuf
, "r"))) {
40 fprintf(stderr
, "couldnt open %s\n", fnbuf
);
44 snprintf(fnbuf
, sizeof(fnbuf
), "%s%c%s", dir
, PSEP
, "agspack.exestub");
45 if(access(fnbuf
, R_OK
) == -1) {
46 fprintf(stderr
, "exestub requested, but couldnt read %s\n", fnbuf
);
51 struct AgsFile
*ags
= calloc(1, sizeof(*ags
));
52 AgsFile_init(ags
, pack
);
53 AgsFile_setSourceDir(ags
, dir
);
54 AgsFile_setDataFileCount(ags
, 1); //TODO
55 if(!AgsFile_setDataFile(ags
, 0, "AGSPACKv" VERSION
)) {
56 fprintf(stderr
, "error: packname exceeds 20 chars\n");
59 if(exe_opt
) AgsFile_setExeStub(ags
, "agspack.exestub");
61 while(fgets(line
, sizeof(line
), fp
)) {
62 size_t l
= strlen(line
);
65 if(--l
&& line
[l
-1] == '\r') line
[l
- 1] = 0;
67 char *p
= strchr(line
, '=');
71 else if(strcmp(line
, "agsversion") == 0 || strcmp(line
, "mflversion") == 0)
72 AgsFile_setVersion(ags
, atoi(p
));
73 else if(strcmp(line
, "filecount") == 0)
74 AgsFile_setFileCount(ags
, atoi(p
));
75 else if(isdigit(*line
))
76 if(!AgsFile_setFile(ags
, index
++, p
)) {
82 size_t l
= AgsFile_getFileCount(ags
);
83 for(index
= 0; index
< l
; index
++) {
84 // TODO read from input file, but it seems to be all 0 for some games.
85 AgsFile_setFileNumber(ags
, index
, 0);
87 int ret
= AgsFile_write(ags
);
88 if(!ret
) perror("write");