Example #1
0
bool L3DS::Load(const char *filename)
{
    FILE *f;
    f = fopen(filename, "rb");
    if (f == 0)
    {
        fprintf(stderr, "L3DS::LoadFile - cannot open file");
        return false;
    }
    fseek(f, 0, SEEK_END);
    m_bufferSize = ftell(f);
    fseek(f, 0, SEEK_SET);
    m_buffer = static_cast<unsigned char *>(calloc(m_bufferSize, 1));
    if (m_buffer == 0)
    {
        fprintf(stderr, "L3DS::LoadFile - not enough memory (malloc failed)");
        return false;
    }
    if (fread(m_buffer, m_bufferSize, 1, f) != 1)
    {
        fclose(f);
        free(m_buffer);
        m_bufferSize = 0;
        fprintf(stderr, "L3DS::LoadFile - error reading from file");
        return false;
    }
    fclose(f);

    Clear();
    bool res = Read3DS();
    free(m_buffer);
    m_buffer = 0;
    m_bufferSize = 0;
    return res;
}
Example #2
0
bool L3DS::LoadFile(StrPtr filename)
{
    FILE *f;
    f = _wfopen(filename, _qstr("rb"));
    if (f == 0)
    {
        ErrorMsg("L3DS::LoadFile - cannot open file");
        return false;
    }
    fseek(f, 0, SEEK_END);
    m_bufferSize = ftell(f);
    fseek(f, 0, SEEK_SET);
    m_buffer = (unsigned char*) calloc(m_bufferSize, 1);
    if (m_buffer == 0)
    {
        ErrorMsg("L3DS::LoadFile - not enough memory (malloc failed)");
        return false;
    }
    if (fread(m_buffer, m_bufferSize, 1, f) != 1)
    {
        fclose(f);
        free(m_buffer);
        m_bufferSize = 0;
        ErrorMsg("L3DS::LoadFile - error reading from file");
        return false;
    }
    fclose(f);
    Clear();
    bool res = Read3DS();
    free(m_buffer);
    m_buffer = 0;
    m_bufferSize = 0;
    return res;
}
Example #3
0
bool L3DS::Load(std::istream &is)
{
    // get length of file:
    is.seekg(0, std::ios::end);
    m_bufferSize = is.tellg();
    is.seekg(0, std::ios::beg);

    m_buffer = static_cast<unsigned char*>(calloc(m_bufferSize, 1));
    if (m_buffer == 0)
    {
        fprintf(stderr, "L3DS::LoadFile - not enough memory (malloc failed)");
        return false;
    }
    is.read(reinterpret_cast<char *>(m_buffer), m_bufferSize);
    if(is.gcount() != std::streamsize(m_bufferSize))
    {
        free(m_buffer);
        m_bufferSize = 0;
        fprintf(stderr, "L3DS::LoadFile - error reading from stream");
        return false;
    }

    Clear();
    bool res = Read3DS();
    free(m_buffer);
    m_buffer = 0;
    m_bufferSize = 0;
    return res;
}
Example #4
0
 /// MODIFIED BY R.Ambersky
bool L3DS::LoadMem(void *memo_ptr, uint memoSize){
    m_buffer = (unsigned char*)  memo_ptr;
    m_bufferSize = memoSize;
    bool res = Read3DS();
    m_buffer = 0;
    m_bufferSize = 0;
    return res;
};