1 | #include <iostream>
|
---|
2 | #include "StormLib.h"
|
---|
3 | #include <dirent.h>
|
---|
4 | #include <string.h>
|
---|
5 |
|
---|
6 | using namespace std;
|
---|
7 |
|
---|
8 | const char* help_msg = "Program for comprimation dir to MPQ file.\n"
|
---|
9 | "Suported by projekt wowpreklad (wowpreklad.zdechov.net).\n\n"
|
---|
10 | "Created by maron\n"
|
---|
11 | "email: maron2@centrum.cz\n\n"
|
---|
12 | "Parameters:\n"
|
---|
13 | " -h --help write this help\n\n"
|
---|
14 | "Usage:\n"
|
---|
15 | "dir - directory to comprimed\n"
|
---|
16 | "file - file name of new MPQ file\n\n"
|
---|
17 | "./MPQarchiver dir file\n";
|
---|
18 |
|
---|
19 |
|
---|
20 | int GetDirContent(char * current_dir)
|
---|
21 | {
|
---|
22 | DIR *dp;
|
---|
23 | char nextdir[40];
|
---|
24 | char * file;
|
---|
25 |
|
---|
26 | struct dirent *dirp;
|
---|
27 | if ((dp = opendir(current_dir)) != NULL) {
|
---|
28 |
|
---|
29 |
|
---|
30 | while ((dirp = readdir(dp)) != NULL) {
|
---|
31 |
|
---|
32 | file = dirp->d_name;
|
---|
33 | strcpy(nextdir,current_dir);
|
---|
34 | strncat(nextdir,"/",1);
|
---|
35 | strncat(nextdir,file,strlen(file));
|
---|
36 |
|
---|
37 |
|
---|
38 | if (opendir(nextdir) != NULL)
|
---|
39 | {
|
---|
40 | if (memchr (nextdir, '.', strlen(nextdir)) == NULL)
|
---|
41 | GetDirContent(nextdir);
|
---|
42 | }
|
---|
43 | else
|
---|
44 | {
|
---|
45 | printf(nextdir);
|
---|
46 | printf("\n");
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | }
|
---|
52 |
|
---|
53 | int main(int argc, char ** argv)
|
---|
54 | {
|
---|
55 | HANDLE hMpq = NULL; // Handle of created archive
|
---|
56 |
|
---|
57 | for (int i=0; i<argc; i++) {
|
---|
58 | if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"--help") == 0) {
|
---|
59 | printf(help_msg);
|
---|
60 | return EXIT_SUCCESS;
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | /* if (argc != 3) {
|
---|
65 | printf("Bad count of parameters, write -h for help\n");
|
---|
66 | return EXIT_FAILURE;
|
---|
67 | }
|
---|
68 | */
|
---|
69 | argv[2] = "new.mpq";
|
---|
70 | argv[1] = "test";
|
---|
71 |
|
---|
72 | GetDirContent(argv[1]);
|
---|
73 |
|
---|
74 |
|
---|
75 | if(!SFileCreateArchiveEx(argv[2], MPQ_CREATE_ARCHIVE_V2 | CREATE_ALWAYS, 0x100, &hMpq)) {
|
---|
76 | printf("Cannot create archive\n");
|
---|
77 | }
|
---|
78 |
|
---|
79 | if(!SFileAddFile(hMpq, "GameTips.dbc", "GameTips.dbc", 0 )) {
|
---|
80 | printf("Cannot add the file\n");
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | //TODO: listfile, parametry, help
|
---|
85 |
|
---|
86 | SFileCloseArchive(hMpq);
|
---|
87 |
|
---|
88 | return 0;
|
---|
89 | }
|
---|