Ejemplo n.º 1
0
// (archive:lightuserdata, filename:string) -> nil
int C_archive_AddFileToArchive(lua_State* L)
{
    struct QArchive* qa = (struct QArchive*)lua_topointer(L, 1);
    const char* filename = luaL_checkstring(L, 2);
    AddFileToArchive(qa, filename);
    return 0;
}
Ejemplo n.º 2
0
BOOL WINAPI SFileAddFileEx(HANDLE hMPQ, const char * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwQuality, int nFileType)
{
    TMPQArchive * ha = (TMPQArchive *)hMPQ;
    HANDLE hFile = INVALID_HANDLE_VALUE;
    BOOL   bReplaced = FALSE;          // TRUE if replacing file in the archive
    int    nError = ERROR_SUCCESS;

    if(nError == ERROR_SUCCESS)
    {
        // Check valid parameters
        if(IsValidMpqHandle(ha) == FALSE || szFileName == NULL || *szFileName == 0 || szArchivedName == NULL || *szArchivedName == 0)
            nError = ERROR_INVALID_PARAMETER;

        // Check the values of dwFlags
        if((dwFlags & MPQ_FILE_IMPLODE) && (dwFlags & MPQ_FILE_COMPRESS))
            nError = ERROR_INVALID_PARAMETER;
    }

    // If anyone is trying to add listfile, and the archive already has a listfile,
    // deny the operation, but return success.
    if(nError == ERROR_SUCCESS)
    {
        if(ha->pListFile != NULL && !_stricmp(szFileName, LISTFILE_NAME))
            return ERROR_SUCCESS;
    }

    // Open added file
    if(nError == ERROR_SUCCESS)
    {
        hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, NULL);
        if(hFile == INVALID_HANDLE_VALUE)
            nError = GetLastError();
    }

    if(nError == ERROR_SUCCESS)
        nError = AddFileToArchive(ha, hFile, szArchivedName, dwFlags, dwQuality, nFileType, &bReplaced);

    // Add the file into listfile also
    if(nError == ERROR_SUCCESS && bReplaced == FALSE)
        nError = SListFileCreateNode(ha, szArchivedName, lcLocale);

    // Cleanup and exit
    if(hFile != INVALID_HANDLE_VALUE)
        CloseHandle(hFile);
    if(nError != ERROR_SUCCESS)
        SetLastError(nError);
    return (nError == ERROR_SUCCESS);
}
Ejemplo n.º 3
0
int SAttrFileSaveToMpq(TMPQArchive * ha)
{
    HANDLE hFile = INVALID_HANDLE_VALUE;
    DWORD dwToWrite;
    DWORD dwWritten;
    LCID lcSave = lcLocale;
    char szAttrFile[MAX_PATH];
    int nError = ERROR_SUCCESS;

    // If there are no attributes, do nothing
    if(ha->pAttributes == NULL)
        return ERROR_SUCCESS;

    // Create the local attributes file
    if(nError == ERROR_SUCCESS)
    {
        GetAttributesFileName(ha, szAttrFile);
        hFile = CreateFile(szAttrFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
        if(hFile == INVALID_HANDLE_VALUE)
            nError = GetLastError();
    }

    // Write the content of the attributes to the file
    if(nError == ERROR_SUCCESS)
    {
        // Write the header of the attributes file
        dwToWrite = sizeof(DWORD) + sizeof(DWORD);
        WriteFile(hFile, ha->pAttributes, dwToWrite, &dwWritten, NULL);
        if(dwWritten != dwToWrite)
            nError = ERROR_DISK_FULL;
    }

    // Write the array of CRC32
    if(nError == ERROR_SUCCESS && ha->pAttributes->pCrc32 != NULL)
    {
        dwToWrite = sizeof(TMPQCRC32) * ha->pHeader->dwBlockTableSize;
        WriteFile(hFile, ha->pAttributes->pCrc32, dwToWrite, &dwWritten, NULL);
        if(dwWritten != dwToWrite)
            nError = ERROR_DISK_FULL;
    }

    // Write the array of FILETIMEs
    if(nError == ERROR_SUCCESS && ha->pAttributes->pFileTime != NULL)
    {
        dwToWrite = sizeof(TMPQFileTime) * ha->pHeader->dwBlockTableSize;
        WriteFile(hFile, ha->pAttributes->pFileTime, dwToWrite, &dwWritten, NULL);
        if(dwWritten != dwToWrite)
            nError = ERROR_DISK_FULL;
    }

    // Write the array of MD5s
    if(nError == ERROR_SUCCESS && ha->pAttributes->pMd5 != NULL)
    {
        dwToWrite = sizeof(TMPQMD5) * ha->pHeader->dwBlockTableSize;
        WriteFile(hFile, ha->pAttributes->pMd5, dwToWrite, &dwWritten, NULL);
        if(dwWritten != dwToWrite)
            nError = ERROR_DISK_FULL;
    }

    // Add the attributes into MPQ
    if(nError == ERROR_SUCCESS)
    {
        SFileSetLocale(LANG_NEUTRAL);
        nError = AddFileToArchive(ha, hFile, ATTRIBUTES_NAME, MPQ_FILE_COMPRESS | MPQ_FILE_REPLACEEXISTING, 0, SFILE_TYPE_DATA, NULL);
        lcLocale = lcSave;
    }

    // Close the temporary file and delete it.
    // There is no FILE_FLAG_DELETE_ON_CLOSE on LINUX.
    if(hFile != INVALID_HANDLE_VALUE)
        CloseHandle(hFile);
    DeleteFile(szAttrFile);

    return nError;
}