MCPcopy Create free account
hub / github.com/Kenix3/libultraship / CreateListFileCache

Function CreateListFileCache

extern/StormLib/src/SFileListFile.cpp:84–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84static TListFileCache * CreateListFileCache(
85 LOAD_LISTFILE PfnLoadFile,
86 TListFileHandle * pHandle,
87 const char * szWildCard,
88 DWORD dwFileSize,
89 DWORD dwMaxSize,
90 DWORD dwFlags)
91{
92 TListFileCache * pCache = NULL;
93 size_t cchWildCardAligned = 0;
94 size_t cchWildCard = 0;
95 DWORD dwBytesRead = 0;
96
97 // Get the amount of bytes that need to be allocated
98 if(dwFileSize == 0 || dwFileSize > dwMaxSize)
99 return NULL;
100
101 // Append buffer for name mask, if any
102 if(szWildCard != NULL)
103 {
104 cchWildCard = strlen(szWildCard) + 1;
105 cchWildCardAligned = (cchWildCard + 3) & 0xFFFFFFFC;
106 }
107
108 // Allocate cache for one file block
109 pCache = (TListFileCache *)STORM_ALLOC(BYTE, sizeof(TListFileCache) + cchWildCardAligned + dwFileSize + 1);
110 if(pCache != NULL)
111 {
112 // Clear the entire structure
113 memset(pCache, 0, sizeof(TListFileCache) + cchWildCard);
114 pCache->dwFlags = dwFlags;
115
116 // Shall we copy the mask?
117 if(cchWildCard != 0)
118 {
119 pCache->szWildCard = (char *)(pCache + 1);
120 memcpy(pCache->szWildCard, szWildCard, cchWildCard);
121 }
122
123 // Fill-in the rest of the cache pointers
124 pCache->pBegin = (LPBYTE)(pCache + 1) + cchWildCardAligned;
125
126 // Load the entire listfile to the cache
127 PfnLoadFile(pHandle, pCache->pBegin, dwFileSize, &dwBytesRead);
128 if(dwBytesRead != 0)
129 {
130 // Allocate pointers
131 pCache->pPos = pCache->pBegin;
132 pCache->pEnd = pCache->pBegin + dwBytesRead;
133 }
134 else
135 {
136 FreeListFileCache(pCache);
137 pCache = NULL;
138 }
139 }
140
141 // Return the cache

Callers 2

SListFileFindFirstFileFunction · 0.85

Calls 8

FreeListFileCacheFunction · 0.85
SFileOpenFileExFunction · 0.85
SFileGetFileSizeFunction · 0.85
SFileCloseFileFunction · 0.85
FileStream_OpenFileFunction · 0.85
FileStream_GetSizeFunction · 0.85
FileStream_CloseFunction · 0.85
SetLastErrorFunction · 0.85

Tested by

no test coverage detected