I have a problem here. This function:
BOOL WINAPI SFileGetFileName(HANDLE hFile, char * szFileName) {
TMPQFile * hf = (TMPQFile *)hFile; // MPQ File handle
char *szExt = "xxx"; // Default extension
DWORD dwFirstBytes[2]; // The first 4 bytes of the file
DWORD dwFilePos; // Saved file position
int nError = ERROR_SUCCESS;
int i;
// Pre-zero the output buffer
if(szFileName != NULL)
*szFileName = 0;
// Check valid parameters
if(nError == ERROR_SUCCESS)
{
if(hf == NULL || szFileName == NULL)
nError = ERROR_INVALID_PARAMETER;
}
// If the file name is already filled, return it.
if(nError == ERROR_SUCCESS && *hf->szFileName != 0)
{
if(szFileName != hf->szFileName)
strcpy(szFileName, hf->szFileName);
return TRUE;
}
if(nError == ERROR_SUCCESS)
{
if(hf->dwBlockIndex == (DWORD)-1)
nError = ERROR_CAN_NOT_COMPLETE;
}
// Read the first 8 bytes from the file
if(nError == ERROR_SUCCESS)
{
dwFirstBytes[0] = dwFirstBytes[1] = 0;
dwFilePos = SFileSetFilePointer(hf, 0, NULL, FILE_CURRENT);
SFileReadFile(hFile, &dwFirstBytes, sizeof(dwFirstBytes), NULL);
BSWAP_ARRAY32_UNSIGNED(dwFirstBytes, sizeof(dwFirstBytes) / sizeof(DWORD));
SFileSetFilePointer(hf, dwFilePos, NULL, FILE_BEGIN);
}
if(nError == ERROR_SUCCESS)
{
if((dwFirstBytes[0] & 0x0000FFFF) == ID_EXE)
szExt = "exe";
else if(dwFirstBytes[0] == 0x00000006 && dwFirstBytes[1] == 0x00000001)
szExt = "dc6";
else
{
for(i = 0; id2ext[i].szExt != NULL; i++)
{
if(id2ext[i].dwID == dwFirstBytes[0])
{
szExt = id2ext[i].szExt;
break;
}
}
}
// Create the file name
sprintf(hf->szFileName, "File%08lu.%s", hf->dwBlockIndex, szExt);
if(szFileName != hf->szFileName)
strcpy(szFileName, hf->szFileName);
}
return (nError == ERROR_SUCCESS);
}
Gives me these errors on 'make':
SFileReadFile.cpp: In function ‘bool SFileGetFileName(HANDLE, char*)’:
SFileReadFile.cpp:655:19: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
char *szExt = "xxx"; // Default extension
^
SFileReadFile.cpp:700:19: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
szExt = "exe";
^
SFileReadFile.cpp:702:19: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
szExt = "dc6";
^
SFileReadFile.cpp:716:72: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘DWORD {aka unsigned int}’ [-Wformat=]
sprintf(hf->szFileName, "File%08lu.%s", hf->dwBlockIndex, szExt);
Please give me tips, how to fix these?
I have tried much in C++ documentation, but I had no much luck in finding what is needed. Look, I cannot do a const char const*
in declaration of szext
because I get many errors about constants. But I really want to get rid of these errors.
Please give me some advices or deeper explanation on why it's happening.