Ejemplo n.º 1
0
file_error emu_file::load__7zped_file()
{
    assert(m_file == NULL);
    assert(m__7zdata.count() == 0);
    assert(m__7zfile != NULL);

    // allocate some memory
    m__7zdata.resize(m__7zlength);

    // read the data into our buffer and return
    _7z_error _7zerr = _7z_file_decompress(m__7zfile, m__7zdata, m__7zdata.count());
    if (_7zerr != _7ZERR_NONE)
    {
        m__7zdata.reset();
        return FILERR_FAILURE;
    }

    // convert to RAM file
    file_error filerr = core_fopen_ram(m__7zdata, m__7zdata.count(), m_openflags, &m_file);
    if (filerr != FILERR_NONE)
    {
        m__7zdata.reset();
        return FILERR_FAILURE;
    }

    // close out the _7Z file
    _7z_file_close(m__7zfile);
    m__7zfile = NULL;
    return FILERR_NONE;
}
Ejemplo n.º 2
0
file_error emu_file::attempt__7zped()
{
    astring filename;

    // loop over directory parts up to the start of filename
    while (1)
    {
        // find the final path separator
        int dirsep = m_fullpath.rchr(0, PATH_SEPARATOR[0]);
        if (dirsep == -1)
            return FILERR_NOT_FOUND;

        // insert the part from the right of the separator into the head of the filename
        if (filename.len() > 0)
            filename.ins(0, "/");
        filename.inssubstr(0, m_fullpath, dirsep + 1, -1);

        // remove this part of the filename and append a .7z extension
        m_fullpath.substr(0, dirsep).cat(".7z");

        // attempt to open the _7Z file
        _7z_file *_7z;
        _7z_error _7zerr = _7z_file_open(m_fullpath, &_7z);

        // chop the ._7z back off the filename before continuing
        m_fullpath.substr(0, dirsep);

        // if we failed to open this file, continue scanning
        if (_7zerr != _7ZERR_NONE)
            continue;

        int fileno = -1;

        // see if we can find a file with the right name and (if available) crc
        if (m_openflags & OPEN_FLAG_HAS_CRC) fileno = _7z_search_crc_match(_7z, m_crc, filename.cstr(), filename.len(), true, true);

        // if that failed, look for a file with the right crc, but the wrong filename
        if (fileno==-1)
            if (m_openflags & OPEN_FLAG_HAS_CRC) fileno = _7z_search_crc_match(_7z, m_crc, filename.cstr(), filename.len(), true, false);

        // if that failed, look for a file with the right name; reporting a bad checksum
        // is more helpful and less confusing than reporting "rom not found"
        if (fileno==-1)
            fileno = _7z_search_crc_match(_7z, m_crc, filename.cstr(), filename.len(), false, true);

        if (fileno != -1)
        {
            m__7zfile = _7z;
            m__7zlength = _7z->uncompressed_length;

            // build a hash with just the CRC
            m_hashes.reset();
            m_hashes.add_crc(_7z->crc);
            return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? FILERR_NONE : load__7zped_file();
        }

        // close up the _7Z file and try the next level
        _7z_file_close(_7z);
    }
}
Ejemplo n.º 3
0
void emu_file::close()
{
    // close files and free memory
    if (m__7zfile != NULL)
        _7z_file_close(m__7zfile);
    m__7zfile = NULL;

    if (m_zipfile != NULL)
        zip_file_close(m_zipfile);
    m_zipfile = NULL;

    if (m_file != NULL)
        core_fclose(m_file);
    m_file = NULL;

    m__7zdata.reset();
    m_zipdata.reset();

    if (m_remove_on_close)
        osd_rmfile(m_fullpath);
    m_remove_on_close = false;

    // reset our hashes and path as well
    m_hashes.reset();
    m_fullpath.reset();
}
Ejemplo n.º 4
0
file_error emu_file::load__7zped_file()
{
	assert(m_file == NULL);
	assert(m__7zdata == NULL);
	assert(m__7zfile != NULL);

	// allocate some memory
	m__7zdata = global_alloc_array(UINT8, m__7zlength);

	// read the data into our buffer and return
	_7z_error _7zerr = _7z_file_decompress(m__7zfile, m__7zdata, m__7zlength);
	if (_7zerr != _7ZERR_NONE)
	{
		global_free(m__7zdata);
		m__7zdata = NULL;
		return FILERR_FAILURE;
	}

	// convert to RAM file
	file_error filerr = core_fopen_ram(m__7zdata, m__7zlength, m_openflags, &m_file);
	if (filerr != FILERR_NONE)
	{
		global_free(m__7zdata);
		m__7zdata = NULL;
		return FILERR_FAILURE;
	}

	// close out the _7Z file
	_7z_file_close(m__7zfile);
	m__7zfile = NULL;
	return FILERR_NONE;
}
Ejemplo n.º 5
0
file_error emu_file::load__7zped_file()
{
	assert(m_file == nullptr);
	assert(m__7zdata.empty());
	assert(m__7zfile != nullptr);

	// allocate some memory
	m__7zdata.resize(m__7zlength);

	// read the data into our buffer and return
	_7z_error _7zerr = _7z_file_decompress(m__7zfile, &m__7zdata[0], m__7zdata.size());
	if (_7zerr != _7ZERR_NONE)
	{
		m__7zdata.clear();
		return FILERR_FAILURE;
	}

	// convert to RAM file
	file_error filerr = util::core_file::open_ram(&m__7zdata[0], m__7zdata.size(), m_openflags, m_file);
	if (filerr != FILERR_NONE)
	{
		m__7zdata.clear();
		return FILERR_FAILURE;
	}

	// close out the _7Z file
	_7z_file_close(m__7zfile);
	m__7zfile = nullptr;
	return FILERR_NONE;
}
Ejemplo n.º 6
0
void emu_file::close()
{
	// close files and free memory
	if (m__7zfile != nullptr)
		_7z_file_close(m__7zfile);
	m__7zfile = nullptr;

	if (m_zipfile != nullptr)
		zip_file_close(m_zipfile);
	m_zipfile = nullptr;

	if (m_file != nullptr)
		core_fclose(m_file);
	m_file = nullptr;

	m__7zdata.clear();
	m_zipdata.clear();

	if (m_remove_on_close)
		osd_rmfile(m_fullpath.c_str());
	m_remove_on_close = false;

	// reset our hashes and path as well
	m_hashes.reset();
	m_fullpath.clear();
}