source: tools/mpq/main.cpp

Last change on this file was 640, checked in by maron, 10 years ago
  • Added: command mpq archiver
File size: 2.6 KB
Line 
1#include <iostream>
2#include "StormLib.h"
3
4using namespace std;
5
6int main(int argc, char* argv[])
7{
8 if (argc > 1)
9 if(strcmp(argv[1],"-h")==0){
10 cout << "Program for add file to MPQ file."<< endl;
11 cout << "Suported by projekt wowpreklad (wowpreklad.zdechov.net)."<< endl;
12 cout << "Created by maron"<< endl;
13 cout << "email: maron2@centrum.cz\n"<< endl;
14 cout << "Parameters:"<< endl;
15 cout << " -h --help write this help"<< endl;
16 cout << "Usage:\n"<< argv[0]<< " MPQ_Archive file file\patch\in\win\\in\\linux " << endl;
17
18 return 0;
19 }
20 // argc = 4;
21 // argv[1] = "patch-5.MPQ";
22 // argv[2] = "Interface\\FrameXML\\GlobalStrings.lua";
23 // argv[3] = "Achievement.dbc";
24
25 if (argc < 4){
26 cout << "Bad count of argumets!"<< endl;
27 return 1;
28 }
29
30 HANDLE hMpq = NULL;
31 HANDLE hFile = NULL;
32 ULONGLONG FileSize = 0;
33 ULONGLONG ByteOffset;
34 TFileStream * pStream = NULL;
35
36 SFileSetLocale(0x405);
37
38
39 pStream = FileStream_OpenFile(argv[3], false);
40 if(pStream == NULL){
41 cout << "Error opening file" << endl;
42 return 1;
43 }
44 if(!FileStream_GetSize(pStream, &FileSize)){
45 cout << "Error geting size file" << endl;
46 return 1;
47 }
48
49 if (!SFileOpenArchive(argv[1], 0, 0, &hMpq)){
50 cout << "Error open archive!" << endl;
51 return 1;
52 }
53
54 ULONGLONG EndOffset = ByteOffset + FileSize;
55 BYTE pbCopyBuffer[0x7000];
56 DWORD BytesToRead;
57 DWORD BlockLength = 0x7000;
58
59 if(!SFileCreateFile(hMpq, argv[2], 0, FileSize, 0, MPQ_FILE_REPLACEEXISTING, &hFile))
60 {
61 cout << "Error creating file" << endl;
62 return 1;
63 }
64
65 if(pbCopyBuffer != NULL)
66 {
67 while(ByteOffset < EndOffset)
68 {
69 // Notify the user
70
71 // Read source
72 BytesToRead = ((EndOffset - ByteOffset) > BlockLength) ? BlockLength : (DWORD)(EndOffset - ByteOffset);
73 if(!FileStream_Read(pStream, &ByteOffset, pbCopyBuffer, BytesToRead))
74 {
75 cout << "Error reading file" << endl;
76 return 1;
77 }
78 if(!SFileWriteFile(hFile, pbCopyBuffer, BytesToRead, MPQ_COMPRESSION_ZLIB))
79 {
80 cout << "Error writing" << endl;
81 return 1;
82 }
83 // cout << pbCopyBuffer << endl;
84 ByteOffset += BytesToRead;
85 }
86 }
87
88 cout << argv[3] << " Done!" <<endl;
89
90 SFileSetLocale(0x405);
91 SFileCompactArchive(hMpq, NULL, 0);
92 SFileCloseArchive(hMpq);
93 return 0;
94}
Note: See TracBrowser for help on using the repository browser.