aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadislav Zezula <zezula@volny.cz>2023-06-02 07:31:28 +0200
committerGitHub <noreply@github.com>2023-06-02 07:31:28 +0200
commite0dc612ec8deeb12773009f6bb3d9df7a95b1051 (patch)
tree2bc61b63f1c996aaee9c75374f4e77e74bae8fde
parent33e6a2bdfec872c31bfd7ce2899012c129894f7e (diff)
parent927bac4d58db93764c272abedd4a7b263ed66a9c (diff)
Merge pull request #291 from TheNitesWhoSay/feature/add-listfile-from-memory
Sounds fine. I'll merge it and then do some cosmetics to your code. Thanks for the contribution! 👍
-rw-r--r--src/SFileListFile.cpp45
-rw-r--r--src/StormLib.h1
2 files changed, 46 insertions, 0 deletions
diff --git a/src/SFileListFile.cpp b/src/SFileListFile.cpp
index 2a3f02a..efad14e 100644
--- a/src/SFileListFile.cpp
+++ b/src/SFileListFile.cpp
@@ -558,6 +558,25 @@ static DWORD SFileAddArbitraryListFile(
return (pCache != NULL) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT;
}
+static int SFileAddArbitraryListFile(
+ TMPQArchive * ha,
+ const char ** listFileEntries,
+ DWORD dwEntryCount)
+{
+ if(listFileEntries != NULL && dwEntryCount > 0)
+ {
+ // Get the next line
+ for (DWORD dwListFileNum=0; dwListFileNum<dwEntryCount; dwListFileNum++)
+ {
+ const char* listFileEntry = listFileEntries[dwListFileNum];
+ if ( listFileEntry != NULL )
+ SListFileCreateNodeForAllLocales(ha, listFileEntry);
+ }
+ }
+
+ return (listFileEntries != NULL && dwEntryCount > 0) ? ERROR_SUCCESS : ERROR_INVALID_PARAMETER;
+}
+
static DWORD SFileAddInternalListFile(
TMPQArchive * ha,
HANDLE hMpq)
@@ -662,6 +681,32 @@ DWORD WINAPI SFileAddListFile(HANDLE hMpq, const TCHAR * szListFile)
return dwErrCode;
}
+DWORD WINAPI SFileAddListFileEntries(HANDLE hMpq, const char ** listFileEntries, DWORD dwEntryCount)
+{
+ TMPQArchive * ha = (TMPQArchive *)hMpq;
+ DWORD dwErrCode = ERROR_SUCCESS;
+
+ // Add the listfile for each MPQ in the patch chain
+ while(ha != NULL)
+ {
+ if(listFileEntries != NULL && dwEntryCount > 0)
+ dwErrCode = SFileAddArbitraryListFile(ha, listFileEntries, dwEntryCount);
+ else
+ dwErrCode = SFileAddInternalListFile(ha, hMpq);
+
+ // Also, add three special files to the listfile:
+ // (listfile) itself, (attributes) and (signature)
+ SListFileCreateNodeForAllLocales(ha, LISTFILE_NAME);
+ SListFileCreateNodeForAllLocales(ha, SIGNATURE_NAME);
+ SListFileCreateNodeForAllLocales(ha, ATTRIBUTES_NAME);
+
+ // Move to the next archive in the chain
+ ha = ha->haPatch;
+ }
+
+ return dwErrCode;
+}
+
//-----------------------------------------------------------------------------
// Enumerating files in listfile
diff --git a/src/StormLib.h b/src/StormLib.h
index e45f99d..07408b2 100644
--- a/src/StormLib.h
+++ b/src/StormLib.h
@@ -1025,6 +1025,7 @@ bool WINAPI SFileCloseArchive(HANDLE hMpq);
// so you can use this API to combining more listfiles.
// Note that this function is internally called by SFileFindFirstFile
DWORD WINAPI SFileAddListFile(HANDLE hMpq, const TCHAR * szListFile);
+DWORD WINAPI SFileAddListFileEntries(HANDLE hMpq, const char ** listFileEntries, DWORD dwEntryCount);
// Archive compacting
bool WINAPI SFileSetCompactCallback(HANDLE hMpq, SFILE_COMPACT_CALLBACK CompactCB, void * pvUserData);