Sign in to follow this  
NicoG

ZLib / Ziputil and MINGW

Recommended Posts

bool dtZipManager::OpenZip(const char* archive, const char* passwd)
{
    this->CloseZip();

    // Copy stuff
    m_archivename = archive;
    if (!passwd && !m_password.empty())
    {
        m_password.clear();
    }
    else
    {
        m_password = passwd;
    }

    for (u32 i = 0; i < strlen(archive); i++)
    {
        if (m_archivename[i] == dtEvilSep)
        {
            m_archivename[i] = dtPathSep;
        }
    }

    m_zip = unzOpen(m_archivename.c_str());
    if (!m_zip)
    {
        return false;
    }
    return true;
}

dtMemoryHandle* dtZipManager::Decompress(const char* file)
{
    // Return if there is no file open
    if (!m_zip)
    {
        return NULL;
    }

    dtMemoryHandle* handle = NULL;
    unz_file_info file_info;
    int done = 0;
    char current[_MAX_PATH];

    done = unzGoToFirstFile(m_zip);
    while(done == UNZ_OK)
    {
        unzGetCurrentFileInfo(m_zip, &file_info, current, sizeof(current), 0, 0, 0, 0);

        for(int i=0; current[i]; i++)
        {
            if(current[i]== dtEvilSep)
            {
                current[i]= dtPathSep;
            }
        }

        if (CompareFileName(current, file) == true)
        {
            // If no password supplied, this opens the File normally.
            if(unzOpenCurrentFilePassword(m_zip, m_password.empty() ? NULL : m_password.c_str()) == UNZ_OK)
            {
                handle = new dtMemoryHandle(file_info.uncompressed_size);
                assert(handle->data != NULL);

                unzReadCurrentFile(m_zip, handle->data, handle->size);
                assert(handle->data);
                handle->file = file;
                unzCloseCurrentFile(m_zip);

                return handle;
            }
        }

        done=unzGoToNextFile(m_zip);
    }
    return NULL;
}
I use this code to unzip textures (tga) from zips to memory. It works as long as I use MSVC Express 2008 but it fails when I use mingw. With "it fails" I mean that the pictures are black with artifacts or the picture has other distortions. Anyone any clue about this issue? Is my code bad or something in the library? I have recreated the zip with alternative packers, no change. The textures are loaded properly when I load them from the disc, so I assume the problem is here. I am using the ziputil (unzip.h) for zlib and compiled this as static library. The code above is compiled as DLL. However, the user has no interaction with objects from zlib, so this shouldn't be an issue. And as I said, it works under MSCVE. regards

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this