|
| 1 | +/*****************************************************************************/ |
| 2 | +/* CascRootFile_Install.cpp Copyright (c) Ladislav Zezula 2018 */ |
| 3 | +/*---------------------------------------------------------------------------*/ |
| 4 | +/* Support for ROOT handler based on INSTALL manifest */ |
| 5 | +/*---------------------------------------------------------------------------*/ |
| 6 | +/* Date Ver Who Comment */ |
| 7 | +/* -------- ---- --- ------- */ |
| 8 | +/* 21.05.19 1.00 Lad The first version of CascRootFile_Install.cpp */ |
| 9 | +/*****************************************************************************/ |
| 10 | + |
| 11 | +#define __CASCLIB_SELF__ |
| 12 | +#include "CascLib.h" |
| 13 | +#include "CascCommon.h" |
| 14 | + |
| 15 | +//----------------------------------------------------------------------------- |
| 16 | +// Handler definitions for Starcraft I root file |
| 17 | + |
| 18 | +struct TRootHandler_Install : public TFileTreeRoot |
| 19 | +{ |
| 20 | + public: |
| 21 | + |
| 22 | + TRootHandler_Install() : TFileTreeRoot(0) |
| 23 | + { |
| 24 | + // We have file names and return CKey as result of search |
| 25 | + dwFeatures |= (CASC_FEATURE_FILE_NAMES | CASC_FEATURE_ROOT_CKEY); |
| 26 | + } |
| 27 | + |
| 28 | + static int CaptureInstallHeader(CASC_INSTALL_HEADER & InHeader, LPBYTE pbFileData, size_t cbFileData) |
| 29 | + { |
| 30 | + PFILE_INSTALL_HEADER pFileHeader = (PFILE_INSTALL_HEADER)pbFileData; |
| 31 | + |
| 32 | + // Check the signature ('DL') and version |
| 33 | + if (cbFileData < sizeof(FILE_INSTALL_HEADER) || pFileHeader->Magic != FILE_MAGIC_INSTALL || pFileHeader->Version != 1) |
| 34 | + return ERROR_BAD_FORMAT; |
| 35 | + |
| 36 | + // Note that we don't support CKey sizes greater than 0x10 in the INSTALL file |
| 37 | + if (pFileHeader->EKeyLength > MD5_HASH_SIZE) |
| 38 | + return ERROR_BAD_FORMAT; |
| 39 | + |
| 40 | + // Capture the header version 1 |
| 41 | + memset(&InHeader, 0, sizeof(CASC_INSTALL_HEADER)); |
| 42 | + InHeader.Magic = pFileHeader->Magic; |
| 43 | + InHeader.Version = pFileHeader->Version; |
| 44 | + InHeader.EKeyLength = pFileHeader->EKeyLength; |
| 45 | + InHeader.TagCount = ConvertBytesToInteger_2(pFileHeader->TagCount); |
| 46 | + InHeader.EntryCount = ConvertBytesToInteger_4(pFileHeader->EntryCount); |
| 47 | + InHeader.HeaderLength = sizeof(FILE_INSTALL_HEADER); |
| 48 | + return ERROR_SUCCESS; |
| 49 | + } |
| 50 | + |
| 51 | + int Load(TCascStorage * hs, CASC_INSTALL_HEADER InHeader, LPBYTE pbInstallFile, LPBYTE pbInstallEnd) |
| 52 | + { |
| 53 | + PCASC_CKEY_ENTRY pCKeyEntry; |
| 54 | + const char * szString; |
| 55 | + size_t nBitmapLength; |
| 56 | + size_t nFileCount = InHeader.EntryCount; |
| 57 | + |
| 58 | + // Skip the header |
| 59 | + pbInstallFile += InHeader.HeaderLength; |
| 60 | + |
| 61 | + // Skip the tags |
| 62 | + for (DWORD i = 0; i < InHeader.TagCount; i++) |
| 63 | + { |
| 64 | + szString = (const char *)pbInstallFile; |
| 65 | + nBitmapLength = GetTagBitmapLength(pbInstallFile, pbInstallEnd, InHeader.EntryCount); |
| 66 | + pbInstallFile = pbInstallFile + strlen(szString) + 1 + sizeof(USHORT) + nBitmapLength; |
| 67 | + } |
| 68 | + |
| 69 | + // Load the names and insert them to the root handler |
| 70 | + while(nFileCount > 0 && pbInstallFile < pbInstallEnd) |
| 71 | + { |
| 72 | + // File Name and CKey |
| 73 | + szString = (const char *)pbInstallFile; |
| 74 | + pbInstallFile += strlen(szString) + 1; |
| 75 | + |
| 76 | + // Verify whether it is a known entry |
| 77 | + pCKeyEntry = FindCKeyEntry_CKey(hs, pbInstallFile); |
| 78 | + pbInstallFile += MD5_HASH_SIZE + sizeof(DWORD); |
| 79 | + |
| 80 | + // Insert the FileName+CKey to the file tree |
| 81 | + if (pCKeyEntry != NULL) |
| 82 | + FileTree.InsertByName(pCKeyEntry, szString); |
| 83 | + nFileCount--; |
| 84 | + } |
| 85 | + |
| 86 | + return ERROR_SUCCESS; |
| 87 | + } |
| 88 | +}; |
| 89 | + |
| 90 | +//----------------------------------------------------------------------------- |
| 91 | +// Public functions |
| 92 | + |
| 93 | +// |
| 94 | +// Starcraft ROOT file is a text file with the following format: |
| 95 | +// HD2/portraits/NBluCrit/NLCFID01.webm|c2795b120592355d45eba9cdc37f691e |
| 96 | +// locales/enUS/Assets/campaign/EXPZerg/Zerg08/staredit/wav/zovtra01.ogg|316b0274bf2dabaa8db60c3ff1270c85 |
| 97 | +// locales/zhCN/Assets/sound/terran/ghost/tghdth01.wav|6637ed776bd22089e083b8b0b2c0374c |
| 98 | +// |
| 99 | + |
| 100 | +int RootHandler_CreateInstall(TCascStorage * hs, LPBYTE pbInstallFile, DWORD cbInstallFile) |
| 101 | +{ |
| 102 | + CASC_INSTALL_HEADER InHeader; |
| 103 | + TRootHandler_Install * pRootHandler = NULL; |
| 104 | + int nError = ERROR_BAD_FORMAT; |
| 105 | + |
| 106 | + // Capture the header of the DOWNLOAD file |
| 107 | + nError = TRootHandler_Install::CaptureInstallHeader(InHeader, pbInstallFile, cbInstallFile); |
| 108 | + if (nError == ERROR_SUCCESS) |
| 109 | + { |
| 110 | + // Allocate the root handler object |
| 111 | + pRootHandler = new TRootHandler_Install(); |
| 112 | + if (pRootHandler != NULL) |
| 113 | + { |
| 114 | + // Parse the entire install manifest |
| 115 | + nError = pRootHandler->Load(hs, InHeader, pbInstallFile, pbInstallFile + cbInstallFile); |
| 116 | + hs->pRootHandler = pRootHandler; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + return nError; |
| 121 | +} |
0 commit comments