MCPcopy Create free account
hub / github.com/diasurgical/devilution / GetFilePatchChain

Function GetFilePatchChain

3rdParty/StormLib/src/SFileGetFileInfo.cpp:72–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72static bool GetFilePatchChain(TMPQFile * hf, void * pvFileInfo, DWORD cbFileInfo, DWORD * pcbLengthNeeded)
73{
74 TMPQFile * hfTemp;
75 TCHAR * szFileInfo = (TCHAR *)pvFileInfo;
76 size_t cchCharsNeeded = 1;
77 size_t cchFileInfo = (cbFileInfo / sizeof(TCHAR));
78 size_t nLength;
79
80 // Patch chain is only supported on MPQ files.
81 if(hf->pStream != NULL)
82 {
83 SetLastError(ERROR_INVALID_PARAMETER);
84 return false;
85 }
86
87 // Calculate the necessary length of the multi-string
88 for(hfTemp = hf; hfTemp != NULL; hfTemp = hfTemp->hfPatch)
89 cchCharsNeeded += _tcslen(FileStream_GetFileName(hfTemp->ha->pStream)) + 1;
90
91 // Give the caller the needed length
92 if(pcbLengthNeeded != NULL)
93 pcbLengthNeeded[0] = (DWORD)(cchCharsNeeded * sizeof(TCHAR));
94
95 // If the caller gave both buffer pointer and data length,
96 // try to copy the patch chain
97 if(szFileInfo != NULL && cchFileInfo != 0)
98 {
99 // If there is enough space in the buffer, copy the patch chain
100 if(cchCharsNeeded > cchFileInfo)
101 {
102 SetLastError(ERROR_INSUFFICIENT_BUFFER);
103 return false;
104 }
105
106 // Copy each patch
107 for(hfTemp = hf; hfTemp != NULL; hfTemp = hfTemp->hfPatch)
108 {
109 // Get the file name and its length
110 const TCHAR * szFileName = FileStream_GetFileName(hfTemp->ha->pStream);
111 nLength = _tcslen(szFileName) + 1;
112
113 // Copy the file name
114 memcpy(szFileInfo, szFileName, nLength * sizeof(TCHAR));
115 szFileInfo += nLength;
116 }
117
118 // Make it multi-string
119 szFileInfo[0] = 0;
120 }
121
122 return true;
123}
124
125//-----------------------------------------------------------------------------
126// Retrieves an information about an archive or about a file within the archive

Callers 1

SFileGetFileInfoFunction · 0.85

Calls 2

SetLastErrorFunction · 0.85
FileStream_GetFileNameFunction · 0.85

Tested by

no test coverage detected