예제 #1
0
static bool OpenLocalFile(const char * szFileName, HANDLE * phFile)
{
    TFileStream * pStream;
    TMPQFile * hf = NULL;
    TCHAR szFileNameT[MAX_PATH];

    // Convert the file name to UNICODE (if needed)
    CopyFileName(szFileNameT, szFileName, strlen(szFileName));

    // Open the file and create the TMPQFile structure
    pStream = FileStream_OpenFile(szFileNameT, STREAM_FLAG_READ_ONLY);
    if(pStream != NULL)
    {
        // Allocate and initialize file handle
        hf = CreateMpqFile(NULL);
        if(hf != NULL)
        {
            hf->pStream = pStream;
            *phFile = hf;
            return true;
        }
        else
        {
            FileStream_Close(pStream);
            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
        }
    }
    *phFile = NULL;
    return false;
}
예제 #2
0
bool WINAPI SFileGetFileName(HANDLE hFile, char * szFileName)
{
    TMPQFile * hf = (TMPQFile *)hFile;  // MPQ File handle
    int nError = ERROR_INVALID_HANDLE;

    // Pre-zero the output buffer
    if(szFileName != NULL)
        *szFileName = 0;

    // Check valid parameters
    if(IsValidFileHandle(hFile))
    {
        TFileEntry * pFileEntry = hf->pFileEntry;

        // For MPQ files, retrieve the file name from the file entry
        if(hf->pStream == NULL)
        {
            if(pFileEntry != NULL)
            {
                // If the file name is not there yet, create a pseudo name
                if(pFileEntry->szFileName == NULL)
                {
                    nError = CreatePseudoFileName(hFile, pFileEntry, szFileName);
                }
                else
                {
                    if(szFileName != NULL)
                        strcpy(szFileName, pFileEntry->szFileName);
                    nError = ERROR_SUCCESS;
                }
            }
        }

        // For local files, copy the file name from the stream
        else
        {
            if(szFileName != NULL)
            {
                const TCHAR * szStreamName = FileStream_GetFileName(hf->pStream);
                CopyFileName(szFileName, szStreamName, _tcslen(szStreamName));
            }
            nError = ERROR_SUCCESS;
        }
    }

    if(nError != ERROR_SUCCESS)
        SetLastError(nError);
    return (nError == ERROR_SUCCESS);
}
예제 #3
0
int EXPORT_SYMBOL SFileGetFileName(void * hFile, char * szFileName)
{
    TMPQFile * hf = (TMPQFile *)hFile;  /* MPQ File handle */
    int nError = ERROR_INVALID_HANDLE;

    /* Check valid parameters */
    if(IsValidFileHandle(hFile))
    {
        TFileEntry * pFileEntry = hf->pFileEntry;

        /* For MPQ files, retrieve the file name from the file entry */
        if(hf->pStream == NULL)
        {
            if(pFileEntry != NULL)
            {
                /* If the file name is not there yet, create a pseudo name */
                if(pFileEntry->szFileName == NULL)
                    nError = CreatePseudoFileName(hFile, pFileEntry, szFileName);

                /* Copy the file name to the output buffer, if any */
                if(pFileEntry->szFileName && szFileName)
                    strcpy(szFileName, pFileEntry->szFileName);
            }
        }

        /* For local files, copy the file name from the stream */
        else
        {
            if(szFileName != NULL)
            {
                const char * szStreamName = FileStream_GetFileName(hf->pStream);
                CopyFileName(szFileName, szStreamName, strlen(szStreamName));
            }
            nError = ERROR_SUCCESS;
        }
    }

    if(nError != ERROR_SUCCESS)
        SetLastError(nError);
    return (nError == ERROR_SUCCESS);
}