StormLib
28 Mar 2014创建mpq文件
HANDLE hMpq = NULL; DWORD dwCreateFlags = MPQ_CREATE_ARCHIVE_V4; TCHAR szMpqName[MAX_PATH] = "/Users/linguofeng/test/stormlib/new.mpq"; DWORD dwMaxFileCount = 1; if (!SFileCreateArchive(szMpqName, dwCreateFlags, dwMaxFileCount, &hMpq)) { nError = GetLastError(); } SFileCloseArchive(hMpq);
添加文件
if (!SFileAddFileEx(hMpq, "/Users/linguofeng/test/main.c", "main.c", MPQ_FILE_COMPRESS | MPQ_FILE_ENCRYPTED, MPQ_COMPRESSION_ZLIB, MPQ_COMPRESSION_NEXT_SAME)) { nError = GetLastError(); } if (nError != ERROR_SUCCESS) { return nError; }
读取文件
HANDLE hFile = NULL; TCHAR szArchivedFile[MAX_PATH] = "main.c"; if(!SFileOpenFileEx(hMpq, szArchivedFile, 0, &hFile)) { nError = GetLastError(); } if (nError != ERROR_SUCCESS) { return nError; } LPBYTE pbFileData = NULL; DWORD dwFileSizeLo = 0; DWORD dwBytes = 0; // 获取文件的大小 dwFileSizeLo = SFileGetFileSize(hFile, NULL); // 申请文件大小的内存 pbFileData = STORM_ALLOC(BYTE, dwFileSizeLo); // 初始化内存 memset(pbFileData, 0, dwFileSizeLo); // 读取文件内容 SFileReadFile(hFile, pbFileData, dwFileSizeLo, &dwBytes, NULL); // 关闭文件操作柄 SFileCloseFile(hFile); printf("文件内容:\n%s\n文件长度:%d\n", pbFileData, dwBytes); STORM_FREE(pbFileData);
patch的使用
主文件的listfile
main.cpp
patch文件的listfile
main.cpp
SFileOpenPatchArchive(hMpq, "patch.mpq", "", 0) // szPatchPathPrefix为NULL时,默认值为base SFileIsPatchedArchive(hMpq)