mirror of
https://github.com/holub/mame
synced 2025-10-05 08:41:31 +03:00
Turn core_file into a proper class that gets cleaned up safely using unique_ptr
Subverted somewhat by chd_file class
This commit is contained in:
parent
00941faaab
commit
73b44c9429
@ -537,7 +537,7 @@ std::string a78_cart_slot_device::get_default_card_software()
|
||||
int type = A78_TYPE0, mapper;
|
||||
|
||||
// Load and check the header
|
||||
core_fread(m_file, &head[0], 128);
|
||||
m_file->read(&head[0], 128);
|
||||
|
||||
// let's try to auto-fix some common errors in the header
|
||||
mapper = validate_header((head[53] << 8) | head[54], FALSE);
|
||||
@ -558,7 +558,7 @@ std::string a78_cart_slot_device::get_default_card_software()
|
||||
break;
|
||||
case 0x0022:
|
||||
case 0x0026:
|
||||
if (core_fsize(m_file) > 0x40000)
|
||||
if (m_file->size() > 0x40000)
|
||||
type = A78_MEGACART;
|
||||
else
|
||||
type = A78_VERSABOARD;
|
||||
|
@ -412,13 +412,13 @@ std::string a800_cart_slot_device::get_default_card_software()
|
||||
{
|
||||
const char *slot_string;
|
||||
dynamic_buffer head(0x10);
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
int type = A800_8K;
|
||||
|
||||
// check whether there is an header, to identify the cart type
|
||||
if ((len % 0x1000) == 0x10)
|
||||
{
|
||||
core_fread(m_file, &head[0], 0x10);
|
||||
m_file->read(&head[0], 0x10);
|
||||
type = identify_cart_type(&head[0]);
|
||||
}
|
||||
else // otherwise try to guess based on size
|
||||
@ -449,13 +449,13 @@ std::string a5200_cart_slot_device::get_default_card_software()
|
||||
{
|
||||
const char *slot_string;
|
||||
dynamic_buffer head(0x10);
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
int type = A5200_8K;
|
||||
|
||||
// check whether there is an header, to identify the cart type
|
||||
if ((len % 0x1000) == 0x10)
|
||||
{
|
||||
core_fread(m_file, &head[0], 0x10);
|
||||
m_file->read(&head[0], 0x10);
|
||||
type = identify_cart_type(&head[0]);
|
||||
|
||||
std::string info;
|
||||
@ -482,13 +482,13 @@ std::string xegs_cart_slot_device::get_default_card_software()
|
||||
{
|
||||
const char *slot_string;
|
||||
dynamic_buffer head(0x10);
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
int type = A800_8K;
|
||||
|
||||
// check whether there is an header, to identify the cart type
|
||||
if ((len % 0x1000) == 0x10)
|
||||
{
|
||||
core_fread(m_file, &head[0], 0x10);
|
||||
m_file->read(&head[0], 0x10);
|
||||
type = identify_cart_type(&head[0]);
|
||||
}
|
||||
if (type != A800_XEGS)
|
||||
|
@ -226,7 +226,7 @@ std::string apf_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 size = core_fsize(m_file);
|
||||
UINT32 size = m_file->size();
|
||||
int type = APF_STD;
|
||||
|
||||
// attempt to identify Space Destroyer, which needs 1K of additional RAM
|
||||
|
@ -203,7 +203,7 @@ std::string astrocade_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 size = core_fsize(m_file);
|
||||
UINT32 size = m_file->size();
|
||||
int type = ASTROCADE_STD;
|
||||
|
||||
if (size == 0x40000)
|
||||
|
@ -153,7 +153,7 @@ bool c64_expansion_slot_device::call_load()
|
||||
int exrom = 1;
|
||||
int game = 1;
|
||||
|
||||
if (cbm_crt_read_header(m_file, &roml_size, &romh_size, &exrom, &game))
|
||||
if (cbm_crt_read_header(*m_file, &roml_size, &romh_size, &exrom, &game))
|
||||
{
|
||||
UINT8 *roml = nullptr;
|
||||
UINT8 *romh = nullptr;
|
||||
@ -164,7 +164,7 @@ bool c64_expansion_slot_device::call_load()
|
||||
if (roml_size) roml = m_card->m_roml;
|
||||
if (romh_size) romh = m_card->m_roml;
|
||||
|
||||
cbm_crt_read_data(m_file, roml, romh);
|
||||
cbm_crt_read_data(*m_file, roml, romh);
|
||||
}
|
||||
|
||||
m_card->m_exrom = exrom;
|
||||
@ -222,7 +222,7 @@ std::string c64_expansion_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
if (!core_stricmp(filetype(), "crt"))
|
||||
return cbm_crt_get_card(m_file);
|
||||
return cbm_crt_get_card(*m_file);
|
||||
|
||||
clear();
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ std::string channelf_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
int type;
|
||||
|
||||
if (len == 0x40000)
|
||||
|
@ -116,7 +116,7 @@ std::string colecovision_cartridge_slot_device::get_default_card_software()
|
||||
{
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
UINT32 length = core_fsize(m_file);
|
||||
UINT32 length = m_file->size();
|
||||
if (length == 0x100000 || length == 0x200000)
|
||||
return software_get_default_slot("xin1");
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ std::string crvision_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 size = core_fsize(m_file);
|
||||
UINT32 size = m_file->size();
|
||||
int type = CRV_4K;
|
||||
|
||||
switch (size)
|
||||
|
@ -605,11 +605,11 @@ std::string base_gb_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file), offset = 0;
|
||||
UINT32 len = m_file->size(), offset = 0;
|
||||
dynamic_buffer rom(len);
|
||||
int type;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
if ((len % 0x4000) == 512)
|
||||
offset = 512;
|
||||
|
@ -405,11 +405,11 @@ std::string gba_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
int type;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
type = get_cart_type(&rom[0], len);
|
||||
slot_string = gba_get_slot(type);
|
||||
|
@ -464,11 +464,11 @@ std::string intv_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
int type = INTV_STD;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
if (rom[0] == 0xa8 && (rom[1] == (rom[2] ^ 0xff)))
|
||||
{
|
||||
|
@ -1370,7 +1370,7 @@ void omti_disk_image_device::device_start()
|
||||
{
|
||||
m_image = this;
|
||||
|
||||
if (m_image->image_core_file() == nullptr)
|
||||
if (!m_image->is_open())
|
||||
{
|
||||
LOG1(("device_start_omti_disk: no disk"));
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ void sc499_device::device_start()
|
||||
|
||||
m_installed = false;
|
||||
|
||||
if (m_image->image_core_file() == nullptr)
|
||||
if (!m_image->is_open())
|
||||
{
|
||||
LOG2(("start sc499: no cartridge tape"));
|
||||
}
|
||||
|
@ -905,11 +905,11 @@ std::string base_md_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file), offset = 0;
|
||||
UINT32 len = m_file->size(), offset = 0;
|
||||
dynamic_buffer rom(len);
|
||||
int type;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
if (genesis_is_SMD(&rom[0x200], len - 0x200))
|
||||
offset = 0x200;
|
||||
|
@ -283,7 +283,7 @@ std::string msx_slot_cartridge_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string = "nomapper";
|
||||
UINT32 length = core_fsize(m_file);
|
||||
UINT32 length = m_file->size();
|
||||
dynamic_buffer rom(length);
|
||||
int type = NOMAPPER;
|
||||
|
||||
@ -328,7 +328,7 @@ std::string msx_slot_cartridge_device::get_default_card_software()
|
||||
if (type == NOMAPPER)
|
||||
{
|
||||
// Not identified through hashfile, try automatic detection
|
||||
core_fread(m_file, &rom[0], length);
|
||||
m_file->read(&rom[0], length);
|
||||
type = get_cart_type(&rom[0], length);
|
||||
}
|
||||
|
||||
|
@ -147,11 +147,11 @@ std::string nes_aladdin_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string = "algn";
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
UINT8 mapper;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
mapper = (rom[6] & 0xf0) >> 4;
|
||||
mapper |= rom[7] & 0xf0;
|
||||
|
@ -917,10 +917,10 @@ std::string nes_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string = "nrom";
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
if ((rom[0] == 'N') && (rom[1] == 'E') && (rom[2] == 'S'))
|
||||
slot_string = get_default_card_ines(&rom[0], len);
|
||||
|
@ -214,7 +214,7 @@ std::string o2_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 size = core_fsize(m_file);
|
||||
UINT32 size = m_file->size();
|
||||
int type = O2_STD;
|
||||
|
||||
if (size == 12288)
|
||||
|
@ -344,11 +344,11 @@ std::string pce_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
int type;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
type = get_cart_type(&rom[0], len);
|
||||
slot_string = pce_get_slot(type);
|
||||
|
@ -264,11 +264,11 @@ std::string scv_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
int type;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
type = get_cart_type(&rom[0], len);
|
||||
slot_string = scv_get_slot(type);
|
||||
|
@ -608,11 +608,11 @@ std::string sega8_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file), offset = 0;
|
||||
UINT32 len = m_file->size(), offset = 0;
|
||||
dynamic_buffer rom(len);
|
||||
int type;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
if ((len % 0x4000) == 512)
|
||||
offset = 512;
|
||||
|
@ -1007,11 +1007,11 @@ std::string base_sns_cart_slot_device::get_default_card_software()
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 offset;
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
int type = 0, addon = 0;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
offset = snes_skip_header(&rom[0], len);
|
||||
|
||||
|
@ -240,7 +240,7 @@ std::string vc4000_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 size = core_fsize(m_file);
|
||||
UINT32 size = m_file->size();
|
||||
int type = VC4000_STD;
|
||||
|
||||
// attempt to identify the non-standard types
|
||||
|
4
src/devices/bus/vcs/vcs_slot.cpp
Executable file → Normal file
4
src/devices/bus/vcs/vcs_slot.cpp
Executable file → Normal file
@ -786,11 +786,11 @@ std::string vcs_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 len = core_fsize(m_file);
|
||||
UINT32 len = m_file->size();
|
||||
dynamic_buffer rom(len);
|
||||
int type;
|
||||
|
||||
core_fread(m_file, &rom[0], len);
|
||||
m_file->read(&rom[0], len);
|
||||
|
||||
type = identify_cart_type(&rom[0], len);
|
||||
slot_string = vcs_get_slot(type);
|
||||
|
@ -222,11 +222,11 @@ std::string vectrex_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 size = core_fsize(m_file);
|
||||
UINT32 size = m_file->size();
|
||||
dynamic_buffer rom(size);
|
||||
int type = VECTREX_STD;
|
||||
|
||||
core_fread(m_file, &rom[0], size);
|
||||
m_file->read(&rom[0], size);
|
||||
|
||||
if (!memcmp(&rom[0x06], "SRAM", 4))
|
||||
type = VECTREX_SRAM;
|
||||
|
@ -139,7 +139,7 @@ bool vic10_expansion_slot_device::call_load()
|
||||
int exrom = 1;
|
||||
int game = 1;
|
||||
|
||||
if (cbm_crt_read_header(m_file, &roml_size, &romh_size, &exrom, &game))
|
||||
if (cbm_crt_read_header(*m_file, &roml_size, &romh_size, &exrom, &game))
|
||||
{
|
||||
UINT8 *roml = nullptr;
|
||||
UINT8 *romh = nullptr;
|
||||
@ -150,7 +150,7 @@ bool vic10_expansion_slot_device::call_load()
|
||||
if (roml_size) roml = m_card->m_lorom;
|
||||
if (romh_size) romh = m_card->m_lorom;
|
||||
|
||||
cbm_crt_read_data(m_file, roml, romh);
|
||||
cbm_crt_read_data(*m_file, roml, romh);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -187,7 +187,7 @@ std::string vic10_expansion_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
if (!core_stricmp(filetype(), "crt"))
|
||||
return cbm_crt_get_card(m_file);
|
||||
return cbm_crt_get_card(*m_file);
|
||||
|
||||
clear();
|
||||
}
|
||||
|
@ -311,12 +311,12 @@ std::string ws_cart_slot_device::get_default_card_software()
|
||||
if (open_image_file(mconfig().options()))
|
||||
{
|
||||
const char *slot_string;
|
||||
UINT32 size = core_fsize(m_file);
|
||||
UINT32 size = m_file->size();
|
||||
dynamic_buffer rom(size);
|
||||
int type;
|
||||
UINT32 nvram;
|
||||
|
||||
core_fread(m_file, &rom[0], size);
|
||||
m_file->read(&rom[0], size);
|
||||
|
||||
// nvram size is not really used here, but we set it up nevertheless
|
||||
type = get_cart_type(&rom[0], size, nvram);
|
||||
|
@ -109,7 +109,7 @@ bool cdrom_image_device::call_load()
|
||||
if (software_entry() == nullptr)
|
||||
{
|
||||
if (strstr(m_image_name.c_str(), ".chd") && is_loaded()) {
|
||||
err = m_self_chd.open( *image_core_file() ); /* CDs are never writeable */
|
||||
err = m_self_chd.open( image_core_file() ); /* CDs are never writeable */
|
||||
if ( err )
|
||||
goto error;
|
||||
chd = &m_self_chd;
|
||||
|
@ -124,7 +124,7 @@ bool diablo_image_device::call_create(int create_format, option_resolution *crea
|
||||
|
||||
/* create the CHD file */
|
||||
chd_codec_type compression[4] = { CHD_CODEC_NONE };
|
||||
err = m_origchd.create(*image_core_file(), (UINT64)totalsectors * (UINT64)sectorsize, hunksize, sectorsize, compression);
|
||||
err = m_origchd.create(image_core_file(), (UINT64)totalsectors * (UINT64)sectorsize, hunksize, sectorsize, compression);
|
||||
if (err != CHDERR_NONE)
|
||||
goto error;
|
||||
|
||||
@ -219,14 +219,14 @@ int diablo_image_device::internal_load_dsk()
|
||||
}
|
||||
else
|
||||
{
|
||||
err = m_origchd.open(*image_core_file(), true);
|
||||
err = m_origchd.open(image_core_file(), true);
|
||||
if (err == CHDERR_NONE)
|
||||
{
|
||||
m_chd = &m_origchd;
|
||||
}
|
||||
else if (err == CHDERR_FILE_NOT_WRITEABLE)
|
||||
{
|
||||
err = m_origchd.open(*image_core_file(), false);
|
||||
err = m_origchd.open(image_core_file(), false);
|
||||
if (err == CHDERR_NONE)
|
||||
{
|
||||
err = open_disk_diff(device().machine().options(), basename_noext(), m_origchd, m_diffchd);
|
||||
|
@ -295,7 +295,7 @@ void floppy_image_device::commit_image()
|
||||
io.procs = &image_ioprocs;
|
||||
io.filler = 0xff;
|
||||
|
||||
file_error err = core_truncate(image_core_file(), 0);
|
||||
file_error err = image_core_file().truncate(0);
|
||||
if (err != 0)
|
||||
popmessage("Error, unable to truncate image: %d", err);
|
||||
|
||||
@ -362,7 +362,7 @@ void floppy_image_device::device_timer(emu_timer &timer, device_timer_id id, int
|
||||
|
||||
floppy_image_format_t *floppy_image_device::identify(std::string filename)
|
||||
{
|
||||
core_file *fd;
|
||||
util::core_file::ptr fd;
|
||||
std::string revised_path;
|
||||
|
||||
file_error err = zippath_fopen(filename.c_str(), OPEN_FLAG_READ, fd, revised_path);
|
||||
@ -372,19 +372,20 @@ floppy_image_format_t *floppy_image_device::identify(std::string filename)
|
||||
}
|
||||
|
||||
io_generic io;
|
||||
io.file = fd;
|
||||
io.file = fd.get();
|
||||
io.procs = &corefile_ioprocs_noclose;
|
||||
io.filler = 0xff;
|
||||
int best = 0;
|
||||
floppy_image_format_t *best_format = nullptr;
|
||||
for(floppy_image_format_t *format = fif_list; format; format = format->next) {
|
||||
for (floppy_image_format_t *format = fif_list; format; format = format->next)
|
||||
{
|
||||
int score = format->identify(&io, form_factor);
|
||||
if(score > best) {
|
||||
best = score;
|
||||
best_format = format;
|
||||
}
|
||||
}
|
||||
core_fclose(fd);
|
||||
fd.reset();
|
||||
return best_format;
|
||||
}
|
||||
|
||||
@ -1001,11 +1002,11 @@ void ui_menu_control_floppy_image::hook_load(std::string filename, bool softlist
|
||||
if(can_in_place) {
|
||||
file_error filerr;
|
||||
std::string tmp_path;
|
||||
core_file *tmp_file;
|
||||
util::core_file::ptr tmp_file;
|
||||
/* attempt to open the file for writing but *without* create */
|
||||
filerr = zippath_fopen(filename.c_str(), OPEN_FLAG_READ | OPEN_FLAG_WRITE, tmp_file, tmp_path);
|
||||
if(!filerr)
|
||||
core_fclose(tmp_file);
|
||||
tmp_file.reset();
|
||||
else
|
||||
can_in_place = false;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ bool harddisk_image_device::call_create(int create_format, option_resolution *cr
|
||||
|
||||
/* create the CHD file */
|
||||
chd_codec_type compression[4] = { CHD_CODEC_NONE };
|
||||
err = m_origchd.create(*image_core_file(), (UINT64)totalsectors * (UINT64)sectorsize, hunksize, sectorsize, compression);
|
||||
err = m_origchd.create(image_core_file(), (UINT64)totalsectors * (UINT64)sectorsize, hunksize, sectorsize, compression);
|
||||
if (err != CHDERR_NONE)
|
||||
goto error;
|
||||
|
||||
@ -243,14 +243,14 @@ int harddisk_image_device::internal_load_hd()
|
||||
}
|
||||
else
|
||||
{
|
||||
err = m_origchd.open(*image_core_file(), true);
|
||||
err = m_origchd.open(image_core_file(), true);
|
||||
if (err == CHDERR_NONE)
|
||||
{
|
||||
m_chd = &m_origchd;
|
||||
}
|
||||
else if (err == CHDERR_FILE_NOT_WRITEABLE)
|
||||
{
|
||||
err = m_origchd.open(*image_core_file(), false);
|
||||
err = m_origchd.open(image_core_file(), false);
|
||||
if (err == CHDERR_NONE)
|
||||
{
|
||||
err = open_disk_diff(device().machine().options(), basename_noext(), m_origchd, m_diffchd);
|
||||
|
@ -77,7 +77,7 @@ void serflash_device::nvram_read(emu_file &file)
|
||||
int size = m_length / FLASH_PAGE_SIZE;
|
||||
|
||||
|
||||
if (file)
|
||||
if (file.is_open())
|
||||
{
|
||||
UINT32 page;
|
||||
file.read(&page, 4);
|
||||
|
@ -571,7 +571,7 @@ bool samples_device::read_flac_sample(emu_file &file, sample_t &sample)
|
||||
file.seek(0, SEEK_SET);
|
||||
|
||||
// create the FLAC decoder and fill in the sample data
|
||||
flac_decoder decoder((core_file&) file);
|
||||
flac_decoder decoder((util::core_file &)file);
|
||||
sample.frequency = decoder.sample_rate();
|
||||
|
||||
// error if more than 1 channel or not 16bpp
|
||||
|
@ -1880,7 +1880,7 @@ void media_identifier::identify_file(const char *name)
|
||||
// load the file and process if it opens and has a valid length
|
||||
UINT32 length;
|
||||
void *data;
|
||||
file_error filerr = core_fload(name, &data, &length);
|
||||
const file_error filerr = util::core_file::load(name, &data, length);
|
||||
if (filerr == FILERR_NONE && length > 0)
|
||||
{
|
||||
identify_data(name, reinterpret_cast<UINT8 *>(data), length);
|
||||
|
@ -57,8 +57,8 @@ const image_device_type_info device_image_interface::m_device_info_array[] =
|
||||
device_image_interface::device_image_interface(const machine_config &mconfig, device_t &device)
|
||||
: device_interface(device, "image"),
|
||||
m_err(),
|
||||
m_file(nullptr),
|
||||
m_mame_file(nullptr),
|
||||
m_file(),
|
||||
m_mame_file(),
|
||||
m_software_info_ptr(nullptr),
|
||||
m_software_part_ptr(nullptr),
|
||||
m_supported(0),
|
||||
@ -611,12 +611,11 @@ bool device_image_interface::is_loaded()
|
||||
|
||||
image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, const char *path)
|
||||
{
|
||||
file_error filerr;
|
||||
image_error_t err;
|
||||
std::string revised_path;
|
||||
|
||||
/* attempt to read the file */
|
||||
filerr = zippath_fopen(path, open_flags, m_file, revised_path);
|
||||
auto const filerr = zippath_fopen(path, open_flags, m_file, revised_path);
|
||||
|
||||
/* did the open succeed? */
|
||||
switch(filerr)
|
||||
@ -662,15 +661,13 @@ image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, cons
|
||||
|
||||
int device_image_interface::reopen_for_write(const char *path)
|
||||
{
|
||||
if(m_file)
|
||||
core_fclose(m_file);
|
||||
m_file.reset();
|
||||
|
||||
file_error filerr;
|
||||
image_error_t err;
|
||||
std::string revised_path;
|
||||
|
||||
/* attempt to open the file for writing*/
|
||||
filerr = zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path);
|
||||
auto const filerr = zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path);
|
||||
|
||||
/* did the open succeed? */
|
||||
switch(filerr)
|
||||
@ -876,10 +873,9 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
|
||||
warningcount += verify_length_and_hash(m_mame_file.get(),ROM_GETNAME(romp),ROM_GETLENGTH(romp),hash_collection(ROM_GETHASHDATA(romp)));
|
||||
|
||||
if (filerr == FILERR_NONE)
|
||||
{
|
||||
m_file = *m_mame_file;
|
||||
filerr = util::core_file::open_proxy(*m_mame_file, m_file);
|
||||
if (filerr == FILERR_NONE)
|
||||
retVal = TRUE;
|
||||
}
|
||||
|
||||
break; // load first item for start
|
||||
}
|
||||
@ -1118,17 +1114,8 @@ bool device_image_interface::create(const char *path, const image_device_format
|
||||
|
||||
void device_image_interface::clear()
|
||||
{
|
||||
if (m_mame_file)
|
||||
{
|
||||
m_mame_file = nullptr;
|
||||
m_file = nullptr;
|
||||
} else {
|
||||
if (m_file)
|
||||
{
|
||||
core_fclose(m_file);
|
||||
m_file = nullptr;
|
||||
}
|
||||
}
|
||||
m_mame_file.reset();
|
||||
m_file.reset();
|
||||
|
||||
m_image_name.clear();
|
||||
m_readonly = false;
|
||||
|
@ -178,21 +178,22 @@ public:
|
||||
const char *basename() { if (m_basename.empty()) return nullptr; else return m_basename.c_str(); }
|
||||
const char *basename_noext() { if (m_basename_noext.empty()) return nullptr; else return m_basename_noext.c_str(); }
|
||||
const char *filetype() { if (m_filetype.empty()) return nullptr; else return m_filetype.c_str(); }
|
||||
core_file *image_core_file() { return m_file; }
|
||||
UINT64 length() { check_for_file(); return core_fsize(m_file); }
|
||||
bool is_open() const { return bool(m_file); }
|
||||
util::core_file &image_core_file() { return *m_file; }
|
||||
UINT64 length() { check_for_file(); return m_file->size(); }
|
||||
bool is_readonly() { return m_readonly; }
|
||||
bool has_been_created() { return m_created; }
|
||||
void make_readonly() { m_readonly = true; }
|
||||
UINT32 fread(void *buffer, UINT32 length) { check_for_file(); return core_fread(m_file, buffer, length); }
|
||||
UINT32 fread(void *buffer, UINT32 length) { check_for_file(); return m_file->read(buffer, length); }
|
||||
UINT32 fread(optional_shared_ptr<UINT8> &ptr, UINT32 length) { ptr.allocate(length); return fread(ptr.target(), length); }
|
||||
UINT32 fread(optional_shared_ptr<UINT8> &ptr, UINT32 length, offs_t offset) { ptr.allocate(length); return fread(ptr + offset, length - offset); }
|
||||
UINT32 fwrite(const void *buffer, UINT32 length) { check_for_file(); return core_fwrite(m_file, buffer, length); }
|
||||
int fseek(INT64 offset, int whence) { check_for_file(); return core_fseek(m_file, offset, whence); }
|
||||
UINT64 ftell() { check_for_file(); return core_ftell(m_file); }
|
||||
UINT32 fwrite(const void *buffer, UINT32 length) { check_for_file(); return m_file->write(buffer, length); }
|
||||
int fseek(INT64 offset, int whence) { check_for_file(); return m_file->seek(offset, whence); }
|
||||
UINT64 ftell() { check_for_file(); return m_file->tell(); }
|
||||
int fgetc() { char ch; if (fread(&ch, 1) != 1) ch = '\0'; return ch; }
|
||||
char *fgets(char *buffer, UINT32 length) { check_for_file(); return core_fgets(buffer, length, m_file); }
|
||||
int image_feof() { check_for_file(); return core_feof(m_file); }
|
||||
void *ptr() {check_for_file(); return (void *) core_fbuffer(m_file); }
|
||||
char *fgets(char *buffer, UINT32 length) { check_for_file(); return m_file->gets(buffer, length); }
|
||||
int image_feof() { check_for_file(); return m_file->eof(); }
|
||||
void *ptr() {check_for_file(); return const_cast<void *>(m_file->buffer()); }
|
||||
// configuration access
|
||||
void set_init_phase() { m_init_phase = TRUE; }
|
||||
|
||||
@ -250,7 +251,7 @@ protected:
|
||||
|
||||
void clear_error();
|
||||
|
||||
void check_for_file() { assert_always(m_file != nullptr, "Illegal operation on unmounted image"); }
|
||||
void check_for_file() { assert_always(m_file, "Illegal operation on unmounted image"); }
|
||||
|
||||
void setup_working_directory();
|
||||
bool try_change_working_directory(const char *subdir);
|
||||
@ -274,7 +275,7 @@ protected:
|
||||
std::string m_err_message;
|
||||
|
||||
/* variables that are only non-zero when an image is mounted */
|
||||
core_file *m_file;
|
||||
util::core_file::ptr m_file;
|
||||
std::unique_ptr<emu_file> m_mame_file;
|
||||
std::string m_image_name;
|
||||
std::string m_basename;
|
||||
|
@ -571,7 +571,7 @@ bool emu_options::parse_one_ini(const char *basename, int priority, std::string
|
||||
// parse the file
|
||||
osd_printf_verbose("Parsing %s.ini\n", basename);
|
||||
std::string error;
|
||||
bool result = parse_ini_file((core_file&)file, priority, OPTION_PRIORITY_DRIVER_INI, error);
|
||||
bool result = parse_ini_file((util::core_file&)file, priority, OPTION_PRIORITY_DRIVER_INI, error);
|
||||
|
||||
// append errors if requested
|
||||
if (!error.empty() && error_string)
|
||||
|
@ -187,21 +187,11 @@ emu_file::~emu_file()
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// operator core_file - automatically convert
|
||||
// ourselves to a core_file pointer
|
||||
// operator util::core_file - automatically
|
||||
// convert ourselves to a core_file reference
|
||||
//-------------------------------------------------
|
||||
|
||||
emu_file::operator core_file *()
|
||||
{
|
||||
// load the ZIP file now if we haven't yet
|
||||
if (compressed_file_ready())
|
||||
return nullptr;
|
||||
|
||||
// return the core file
|
||||
return m_file;
|
||||
}
|
||||
|
||||
emu_file::operator core_file &()
|
||||
emu_file::operator util::core_file &()
|
||||
{
|
||||
// load the ZIP file now if we haven't yet
|
||||
if (compressed_file_ready())
|
||||
@ -251,12 +241,12 @@ hash_collection &emu_file::hashes(const char *types)
|
||||
}
|
||||
|
||||
// read the data if we can
|
||||
const UINT8 *filedata = (const UINT8 *)core_fbuffer(m_file);
|
||||
const UINT8 *filedata = (const UINT8 *)m_file->buffer();
|
||||
if (filedata == nullptr)
|
||||
return m_hashes;
|
||||
|
||||
// compute the hash
|
||||
m_hashes.compute(filedata, core_fsize(m_file), needed.c_str());
|
||||
m_hashes.compute(filedata, m_file->size(), needed.c_str());
|
||||
return m_hashes;
|
||||
}
|
||||
|
||||
@ -348,7 +338,7 @@ file_error emu_file::open_next()
|
||||
while (m_iterator.next(m_fullpath, m_filename.c_str()))
|
||||
{
|
||||
// attempt to open the file directly
|
||||
filerr = core_fopen(m_fullpath.c_str(), m_openflags, &m_file);
|
||||
filerr = util::core_file::open(m_fullpath.c_str(), m_openflags, m_file);
|
||||
if (filerr == FILERR_NONE)
|
||||
break;
|
||||
|
||||
@ -384,7 +374,7 @@ file_error emu_file::open_ram(const void *data, UINT32 length)
|
||||
m_crc = 0;
|
||||
|
||||
// use the core_file's built-in RAM support
|
||||
return core_fopen_ram(data, length, m_openflags, &m_file);
|
||||
return util::core_file::open_ram(data, length, m_openflags, m_file);
|
||||
}
|
||||
|
||||
|
||||
@ -404,9 +394,7 @@ void emu_file::close()
|
||||
zip_file_close(m_zipfile);
|
||||
m_zipfile = nullptr;
|
||||
|
||||
if (m_file != nullptr)
|
||||
core_fclose(m_file);
|
||||
m_file = nullptr;
|
||||
m_file.reset();
|
||||
|
||||
m__7zdata.clear();
|
||||
m_zipdata.clear();
|
||||
@ -429,7 +417,7 @@ void emu_file::close()
|
||||
|
||||
file_error emu_file::compress(int level)
|
||||
{
|
||||
return core_fcompress(m_file, level);
|
||||
return m_file->compress(level);
|
||||
}
|
||||
|
||||
|
||||
@ -461,8 +449,8 @@ int emu_file::seek(INT64 offset, int whence)
|
||||
return 1;
|
||||
|
||||
// seek if we can
|
||||
if (m_file != nullptr)
|
||||
return core_fseek(m_file, offset, whence);
|
||||
if (m_file)
|
||||
return m_file->seek(offset, whence);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -479,8 +467,8 @@ UINT64 emu_file::tell()
|
||||
return 0;
|
||||
|
||||
// tell if we can
|
||||
if (m_file != nullptr)
|
||||
return core_ftell(m_file);
|
||||
if (m_file)
|
||||
return m_file->tell();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -497,8 +485,8 @@ bool emu_file::eof()
|
||||
return 0;
|
||||
|
||||
// return EOF if we can
|
||||
if (m_file != nullptr)
|
||||
return core_feof(m_file);
|
||||
if (m_file)
|
||||
return m_file->eof();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -518,8 +506,8 @@ UINT64 emu_file::size()
|
||||
return m_ziplength;
|
||||
|
||||
// return length if we can
|
||||
if (m_file != nullptr)
|
||||
return core_fsize(m_file);
|
||||
if (m_file)
|
||||
return m_file->size();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -536,8 +524,8 @@ UINT32 emu_file::read(void *buffer, UINT32 length)
|
||||
return 0;
|
||||
|
||||
// read the data if we can
|
||||
if (m_file != nullptr)
|
||||
return core_fread(m_file, buffer, length);
|
||||
if (m_file)
|
||||
return m_file->read(buffer, length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -554,8 +542,8 @@ int emu_file::getc()
|
||||
return EOF;
|
||||
|
||||
// read the data if we can
|
||||
if (m_file != nullptr)
|
||||
return core_fgetc(m_file);
|
||||
if (m_file)
|
||||
return m_file->getc();
|
||||
|
||||
return EOF;
|
||||
}
|
||||
@ -572,8 +560,8 @@ int emu_file::ungetc(int c)
|
||||
return 1;
|
||||
|
||||
// read the data if we can
|
||||
if (m_file != nullptr)
|
||||
return core_ungetc(c, m_file);
|
||||
if (m_file)
|
||||
return m_file->ungetc(c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -590,8 +578,8 @@ char *emu_file::gets(char *s, int n)
|
||||
return nullptr;
|
||||
|
||||
// read the data if we can
|
||||
if (m_file != nullptr)
|
||||
return core_fgets(s, n, m_file);
|
||||
if (m_file)
|
||||
return m_file->gets(s, n);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@ -604,8 +592,8 @@ char *emu_file::gets(char *s, int n)
|
||||
UINT32 emu_file::write(const void *buffer, UINT32 length)
|
||||
{
|
||||
// write the data if we can
|
||||
if (m_file != nullptr)
|
||||
return core_fwrite(m_file, buffer, length);
|
||||
if (m_file)
|
||||
return m_file->write(buffer, length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -618,8 +606,8 @@ UINT32 emu_file::write(const void *buffer, UINT32 length)
|
||||
int emu_file::puts(const char *s)
|
||||
{
|
||||
// write the data if we can
|
||||
if (m_file != nullptr)
|
||||
return core_fputs(m_file, s);
|
||||
if (m_file)
|
||||
return m_file->puts(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -632,7 +620,7 @@ int emu_file::puts(const char *s)
|
||||
int emu_file::vprintf(const char *fmt, va_list va)
|
||||
{
|
||||
// write the data if we can
|
||||
return (m_file != nullptr) ? core_vfprintf(m_file, fmt, va) : 0;
|
||||
return (m_file) ? m_file->vprintf(fmt, va) : 0;
|
||||
}
|
||||
|
||||
|
||||
@ -658,8 +646,8 @@ int CLIB_DECL emu_file::printf(const char *fmt, ...)
|
||||
void emu_file::flush()
|
||||
{
|
||||
// flush the buffers if we can
|
||||
if (m_file != nullptr)
|
||||
core_fflush(m_file);
|
||||
if (m_file)
|
||||
m_file->flush();
|
||||
}
|
||||
|
||||
|
||||
@ -778,7 +766,7 @@ file_error emu_file::load_zipped_file()
|
||||
}
|
||||
|
||||
// convert to RAM file
|
||||
file_error filerr = core_fopen_ram(&m_zipdata[0], m_zipdata.size(), m_openflags, &m_file);
|
||||
file_error filerr = util::core_file::open_ram(&m_zipdata[0], m_zipdata.size(), m_openflags, m_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
m_zipdata.clear();
|
||||
@ -907,7 +895,7 @@ file_error emu_file::load__7zped_file()
|
||||
}
|
||||
|
||||
// convert to RAM file
|
||||
file_error filerr = core_fopen_ram(&m__7zdata[0], m__7zdata.size(), m_openflags, &m_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();
|
||||
|
@ -90,9 +90,8 @@ public:
|
||||
virtual ~emu_file();
|
||||
|
||||
// getters
|
||||
operator core_file *();
|
||||
operator core_file &();
|
||||
bool is_open() const { return (m_file != nullptr); }
|
||||
operator util::core_file &();
|
||||
bool is_open() const { return bool(m_file); }
|
||||
const char *filename() const { return m_filename.c_str(); }
|
||||
const char *fullpath() const { return m_fullpath.c_str(); }
|
||||
UINT32 openflags() const { return m_openflags; }
|
||||
@ -102,7 +101,7 @@ public:
|
||||
|
||||
// setters
|
||||
void remove_on_close() { m_remove_on_close = true; }
|
||||
void set_openflags(UINT32 openflags) { assert(m_file == nullptr); m_openflags = openflags; }
|
||||
void set_openflags(UINT32 openflags) { assert(!m_file); m_openflags = openflags; }
|
||||
void set_restrict_to_mediapath(bool rtmp = true) { m_restrict_to_mediapath = rtmp; }
|
||||
|
||||
// open/close
|
||||
@ -157,9 +156,9 @@ private:
|
||||
// internal state
|
||||
std::string m_filename; // original filename provided
|
||||
std::string m_fullpath; // full filename
|
||||
core_file * m_file; // core file pointer
|
||||
util::core_file::ptr m_file; // core file pointer
|
||||
path_iterator m_iterator; // iterator for paths
|
||||
path_iterator m_mediapaths; // media-path iterator
|
||||
path_iterator m_mediapaths; // media-path iterator
|
||||
UINT32 m_crc; // file's CRC
|
||||
UINT32 m_openflags; // flags we used for the open
|
||||
hash_collection m_hashes; // collection of hashes
|
||||
|
@ -341,7 +341,7 @@ void save_main_option(running_machine &machine)
|
||||
emu_file file(machine.options().ini_path(), OPEN_FLAG_READ);
|
||||
if (file.open(emulator_info::get_configname(), ".ini") == FILERR_NONE)
|
||||
{
|
||||
bool result = options.parse_ini_file((core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error);
|
||||
bool result = options.parse_ini_file((util::core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error);
|
||||
if (!result)
|
||||
{
|
||||
osd_printf_error(_("**Error loading %s.ini**"), emulator_info::get_configname());
|
||||
|
@ -171,7 +171,7 @@ static void load_ui_options(running_machine &machine)
|
||||
emu_file file(machine.options().ini_path(), OPEN_FLAG_READ);
|
||||
if (file.open("ui.ini") == FILERR_NONE)
|
||||
{
|
||||
bool result = machine.ui().options().parse_ini_file((core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error);
|
||||
bool result = machine.ui().options().parse_ini_file((util::core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error);
|
||||
if (!result)
|
||||
osd_printf_error("**Error loading ui.ini**");
|
||||
}
|
||||
|
@ -122,11 +122,11 @@ static const char * CRT_C64_SLOT_NAMES[_CRT_C64_COUNT] =
|
||||
// cbm_crt_get_card - get slot interface card
|
||||
//-------------------------------------------------
|
||||
|
||||
std::string cbm_crt_get_card(core_file *file)
|
||||
std::string cbm_crt_get_card(util::core_file &file)
|
||||
{
|
||||
// read the header
|
||||
cbm_crt_header header;
|
||||
core_fread(file, &header, CRT_HEADER_LENGTH);
|
||||
file.read(&header, CRT_HEADER_LENGTH);
|
||||
|
||||
if (memcmp(header.signature, CRT_SIGNATURE, 16) == 0)
|
||||
{
|
||||
@ -143,11 +143,11 @@ std::string cbm_crt_get_card(core_file *file)
|
||||
// cbm_crt_read_header - read cartridge header
|
||||
//-------------------------------------------------
|
||||
|
||||
bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size, int *exrom, int *game)
|
||||
bool cbm_crt_read_header(util::core_file &file, size_t *roml_size, size_t *romh_size, int *exrom, int *game)
|
||||
{
|
||||
// read the header
|
||||
cbm_crt_header header;
|
||||
core_fread(file, &header, CRT_HEADER_LENGTH);
|
||||
file.read(&header, CRT_HEADER_LENGTH);
|
||||
|
||||
if (memcmp(header.signature, CRT_SIGNATURE, 16) != 0)
|
||||
return false;
|
||||
@ -166,10 +166,10 @@ bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size,
|
||||
}
|
||||
|
||||
// determine ROM region lengths
|
||||
while (!core_feof(file))
|
||||
while (!file.eof())
|
||||
{
|
||||
cbm_crt_chip chip;
|
||||
core_fread(file, &chip, CRT_CHIP_LENGTH);
|
||||
file.read(&chip, CRT_CHIP_LENGTH);
|
||||
|
||||
UINT16 address = pick_integer_be(chip.start_address, 0, 2);
|
||||
UINT16 size = pick_integer_be(chip.image_size, 0, 2);
|
||||
@ -190,7 +190,7 @@ bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size,
|
||||
default: osd_printf_verbose("Invalid CHIP loading address!\n"); break;
|
||||
}
|
||||
|
||||
core_fseek(file, size, SEEK_CUR);
|
||||
file.seek(size, SEEK_CUR);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -201,26 +201,26 @@ bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size,
|
||||
// cbm_crt_read_data - read cartridge data
|
||||
//-------------------------------------------------
|
||||
|
||||
bool cbm_crt_read_data(core_file* file, UINT8 *roml, UINT8 *romh)
|
||||
bool cbm_crt_read_data(util::core_file &file, UINT8 *roml, UINT8 *romh)
|
||||
{
|
||||
UINT32 roml_offset = 0;
|
||||
UINT32 romh_offset = 0;
|
||||
|
||||
core_fseek(file, CRT_HEADER_LENGTH, SEEK_SET);
|
||||
file.seek(CRT_HEADER_LENGTH, SEEK_SET);
|
||||
|
||||
while (!core_feof(file))
|
||||
while (!file.eof())
|
||||
{
|
||||
cbm_crt_chip chip;
|
||||
core_fread(file, &chip, CRT_CHIP_LENGTH);
|
||||
file.read(&chip, CRT_CHIP_LENGTH);
|
||||
|
||||
UINT16 address = pick_integer_be(chip.start_address, 0, 2);
|
||||
UINT16 size = pick_integer_be(chip.image_size, 0, 2);
|
||||
|
||||
switch (address)
|
||||
{
|
||||
case 0x8000: core_fread(file, roml + roml_offset, size); roml_offset += size; break;
|
||||
case 0xa000: core_fread(file, romh + romh_offset, size); romh_offset += size; break;
|
||||
case 0xe000: core_fread(file, romh + romh_offset, size); romh_offset += size; break;
|
||||
case 0x8000: file.read(roml + roml_offset, size); roml_offset += size; break;
|
||||
case 0xa000: file.read(romh + romh_offset, size); romh_offset += size; break;
|
||||
case 0xe000: file.read(romh + romh_offset, size); romh_offset += size; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,9 +135,9 @@ struct cbm_crt_chip
|
||||
// FUNCTION PROTOTYPES
|
||||
//**************************************************************************
|
||||
|
||||
std::string cbm_crt_get_card(core_file *file);
|
||||
bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size, int *exrom, int *game);
|
||||
bool cbm_crt_read_data(core_file* file, UINT8 *roml, UINT8 *romh);
|
||||
std::string cbm_crt_get_card(util::core_file &file);
|
||||
bool cbm_crt_read_header(util::core_file &file, size_t *roml_size, size_t *romh_size, int *exrom, int *game);
|
||||
bool cbm_crt_read_data(util::core_file &file, UINT8 *roml, UINT8 *romh);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -68,34 +68,33 @@ const struct io_procs stdio_ioprocs_noclose =
|
||||
|
||||
static void corefile_closeproc(void *file)
|
||||
{
|
||||
core_fclose((core_file*)file);
|
||||
delete (util::core_file*)file;
|
||||
}
|
||||
|
||||
static int corefile_seekproc(void *file, INT64 offset, int whence)
|
||||
{
|
||||
return core_fseek((core_file*)file, (long) offset, whence);
|
||||
return ((util::core_file*)file)->seek(offset, whence);
|
||||
}
|
||||
|
||||
static size_t corefile_readproc(void *file, void *buffer, size_t length)
|
||||
{
|
||||
return core_fread((core_file*)file, buffer, length);
|
||||
return ((util::core_file*)file)->read(buffer, length);
|
||||
}
|
||||
|
||||
static size_t corefile_writeproc(void *file, const void *buffer, size_t length)
|
||||
{
|
||||
return core_fwrite((core_file*)file, buffer, length);
|
||||
return ((util::core_file*)file)->write(buffer, length);
|
||||
}
|
||||
|
||||
static UINT64 corefile_filesizeproc(void *file)
|
||||
{
|
||||
long l, sz;
|
||||
l = core_ftell((core_file*)file);
|
||||
if (core_fseek((core_file*)file, 0, SEEK_END))
|
||||
const auto l = ((util::core_file*)file)->tell();
|
||||
if (((util::core_file*)file)->seek(0, SEEK_END))
|
||||
return (size_t) -1;
|
||||
sz = core_ftell((core_file*)file);
|
||||
if (core_fseek((core_file*)file, l, SEEK_SET))
|
||||
return (size_t) -1;
|
||||
return (size_t) sz;
|
||||
const auto sz = ((util::core_file*)file)->tell();
|
||||
if (((util::core_file*)file)->seek(l, SEEK_SET))
|
||||
return UINT64(-1);
|
||||
return UINT64(sz);
|
||||
}
|
||||
|
||||
const struct io_procs corefile_ioprocs =
|
||||
|
@ -115,7 +115,7 @@ struct cdrom_file
|
||||
/** @brief Information describing the track. */
|
||||
chdcd_track_input_info track_info; /* track info */
|
||||
/** @brief The fhandle[ CD maximum tracks]. */
|
||||
core_file * fhandle[CD_MAX_TRACKS];/* file handle */
|
||||
util::core_file::ptr fhandle[CD_MAX_TRACKS];/* file handle */
|
||||
};
|
||||
|
||||
|
||||
@ -244,7 +244,7 @@ cdrom_file *cdrom_open(const char *inputfile)
|
||||
|
||||
for (i = 0; i < file->cdtoc.numtrks; i++)
|
||||
{
|
||||
file_error filerr = core_fopen(file->track_info.track[i].fname.c_str(), OPEN_FLAG_READ, &file->fhandle[i]);
|
||||
file_error filerr = util::core_file::open(file->track_info.track[i].fname.c_str(), OPEN_FLAG_READ, file->fhandle[i]);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Unable to open file: %s\n", file->track_info.track[i].fname.c_str());
|
||||
@ -418,7 +418,7 @@ void cdrom_close(cdrom_file *file)
|
||||
{
|
||||
for (int i = 0; i < file->cdtoc.numtrks; i++)
|
||||
{
|
||||
core_fclose(file->fhandle[i]);
|
||||
file->fhandle[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,7 +474,7 @@ chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UI
|
||||
else
|
||||
{
|
||||
// else read from the appropriate file
|
||||
core_file *srcfile = file->fhandle[tracknum];
|
||||
util::core_file &srcfile = *file->fhandle[tracknum];
|
||||
|
||||
UINT64 sourcefileoffset = file->track_info.track[tracknum].offset;
|
||||
int bytespersector = file->cdtoc.tracks[tracknum].datasize + file->cdtoc.tracks[tracknum].subsize;
|
||||
@ -483,8 +483,8 @@ chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UI
|
||||
|
||||
// printf("Reading sector %d from track %d at offset %lld\n", chdsector, tracknum, sourcefileoffset);
|
||||
|
||||
core_fseek(srcfile, sourcefileoffset, SEEK_SET);
|
||||
core_fread(srcfile, dest, length);
|
||||
srcfile.seek(sourcefileoffset, SEEK_SET);
|
||||
srcfile.read(dest, length);
|
||||
|
||||
needswap = file->track_info.track[tracknum].swap;
|
||||
}
|
||||
|
@ -190,8 +190,8 @@ inline void chd_file::file_read(UINT64 offset, void *dest, UINT32 length)
|
||||
throw CHDERR_NOT_OPEN;
|
||||
|
||||
// seek and read
|
||||
core_fseek(m_file, offset, SEEK_SET);
|
||||
UINT32 count = core_fread(m_file, dest, length);
|
||||
m_file->seek(offset, SEEK_SET);
|
||||
UINT32 count = m_file->read(dest, length);
|
||||
if (count != length)
|
||||
throw CHDERR_READ_ERROR;
|
||||
}
|
||||
@ -209,8 +209,8 @@ inline void chd_file::file_write(UINT64 offset, const void *source, UINT32 lengt
|
||||
throw CHDERR_NOT_OPEN;
|
||||
|
||||
// seek and write
|
||||
core_fseek(m_file, offset, SEEK_SET);
|
||||
UINT32 count = core_fwrite(m_file, source, length);
|
||||
m_file->seek(offset, SEEK_SET);
|
||||
UINT32 count = m_file->write(source, length);
|
||||
if (count != length)
|
||||
throw CHDERR_WRITE_ERROR;
|
||||
}
|
||||
@ -229,10 +229,10 @@ inline UINT64 chd_file::file_append(const void *source, UINT32 length, UINT32 al
|
||||
throw CHDERR_NOT_OPEN;
|
||||
|
||||
// seek to the end and align if necessary
|
||||
core_fseek(m_file, 0, SEEK_END);
|
||||
m_file->seek(0, SEEK_END);
|
||||
if (alignment != 0)
|
||||
{
|
||||
UINT64 offset = core_ftell(m_file);
|
||||
UINT64 offset = m_file->tell();
|
||||
UINT32 delta = offset % alignment;
|
||||
if (delta != 0)
|
||||
{
|
||||
@ -243,7 +243,7 @@ inline UINT64 chd_file::file_append(const void *source, UINT32 length, UINT32 al
|
||||
while (delta != 0)
|
||||
{
|
||||
UINT32 bytes_to_write = MIN(sizeof(buffer), delta);
|
||||
UINT32 count = core_fwrite(m_file, buffer, bytes_to_write);
|
||||
UINT32 count = m_file->write(buffer, bytes_to_write);
|
||||
if (count != bytes_to_write)
|
||||
throw CHDERR_WRITE_ERROR;
|
||||
delta -= bytes_to_write;
|
||||
@ -252,8 +252,8 @@ inline UINT64 chd_file::file_append(const void *source, UINT32 length, UINT32 al
|
||||
}
|
||||
|
||||
// write the real data
|
||||
UINT64 offset = core_ftell(m_file);
|
||||
UINT32 count = core_fwrite(m_file, source, length);
|
||||
UINT64 offset = m_file->tell();
|
||||
UINT32 count = m_file->write(source, length);
|
||||
if (count != length)
|
||||
throw CHDERR_READ_ERROR;
|
||||
return offset;
|
||||
@ -567,7 +567,7 @@ void chd_file::set_parent_sha1(sha1_t parent)
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4])
|
||||
* @fn chd_error chd_file::create(util::core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4])
|
||||
*
|
||||
* @brief -------------------------------------------------
|
||||
* create - create a new file with no parent using an existing opened file handle
|
||||
@ -582,7 +582,7 @@ void chd_file::set_parent_sha1(sha1_t parent)
|
||||
* @return A chd_error.
|
||||
*/
|
||||
|
||||
chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4])
|
||||
chd_error chd_file::create(util::core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4])
|
||||
{
|
||||
// make sure we don't already have a file open
|
||||
if (m_file != nullptr)
|
||||
@ -602,7 +602,7 @@ chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbyte
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent)
|
||||
* @fn chd_error chd_file::create(util::core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent)
|
||||
*
|
||||
* @brief -------------------------------------------------
|
||||
* create - create a new file with a parent using an existing opened file handle
|
||||
@ -617,7 +617,7 @@ chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbyte
|
||||
* @return A chd_error.
|
||||
*/
|
||||
|
||||
chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent)
|
||||
chd_error chd_file::create(util::core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent)
|
||||
{
|
||||
// make sure we don't already have a file open
|
||||
if (m_file != nullptr)
|
||||
@ -659,21 +659,25 @@ chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hun
|
||||
return CHDERR_ALREADY_OPEN;
|
||||
|
||||
// create the new file
|
||||
core_file *file = nullptr;
|
||||
file_error filerr = core_fopen(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
|
||||
util::core_file::ptr file;
|
||||
const file_error filerr = util::core_file::open(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
return CHDERR_FILE_NOT_FOUND;
|
||||
|
||||
// create the file normally, then claim the file
|
||||
chd_error chderr = create(*file, logicalbytes, hunkbytes, unitbytes, compression);
|
||||
const chd_error chderr = create(*file, logicalbytes, hunkbytes, unitbytes, compression);
|
||||
m_owns_file = true;
|
||||
|
||||
// if an error happened, close and delete the file
|
||||
if (chderr != CHDERR_NONE)
|
||||
{
|
||||
core_fclose(file);
|
||||
file.reset();
|
||||
osd_rmfile(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
file.release();
|
||||
}
|
||||
return chderr;
|
||||
}
|
||||
|
||||
@ -700,21 +704,25 @@ chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hun
|
||||
return CHDERR_ALREADY_OPEN;
|
||||
|
||||
// create the new file
|
||||
core_file *file = nullptr;
|
||||
file_error filerr = core_fopen(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
|
||||
util::core_file::ptr file;
|
||||
const file_error filerr = util::core_file::open(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
return CHDERR_FILE_NOT_FOUND;
|
||||
|
||||
// create the file normally, then claim the file
|
||||
chd_error chderr = create(*file, logicalbytes, hunkbytes, compression, parent);
|
||||
const chd_error chderr = create(*file, logicalbytes, hunkbytes, compression, parent);
|
||||
m_owns_file = true;
|
||||
|
||||
// if an error happened, close and delete the file
|
||||
if (chderr != CHDERR_NONE)
|
||||
{
|
||||
core_fclose(file);
|
||||
file.reset();
|
||||
osd_rmfile(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
file.release();
|
||||
}
|
||||
return chderr;
|
||||
}
|
||||
|
||||
@ -739,27 +747,25 @@ chd_error chd_file::open(const char *filename, bool writeable, chd_file *parent)
|
||||
return CHDERR_ALREADY_OPEN;
|
||||
|
||||
// open the file
|
||||
UINT32 openflags = writeable ? (OPEN_FLAG_READ | OPEN_FLAG_WRITE) : OPEN_FLAG_READ;
|
||||
core_file *file = nullptr;
|
||||
file_error filerr = core_fopen(filename, openflags, &file);
|
||||
const UINT32 openflags = writeable ? (OPEN_FLAG_READ | OPEN_FLAG_WRITE) : OPEN_FLAG_READ;
|
||||
util::core_file::ptr file;
|
||||
const file_error filerr = util::core_file::open(filename, openflags, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
return CHDERR_FILE_NOT_FOUND;
|
||||
|
||||
// now open the CHD
|
||||
chd_error err = open(*file, writeable, parent);
|
||||
if (err != CHDERR_NONE)
|
||||
{
|
||||
core_fclose(file);
|
||||
return err;
|
||||
}
|
||||
|
||||
// we now own this file
|
||||
file.release();
|
||||
m_owns_file = true;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn chd_error chd_file::open(core_file &file, bool writeable, chd_file *parent)
|
||||
* @fn chd_error chd_file::open(util::core_file &file, bool writeable, chd_file *parent)
|
||||
*
|
||||
* @brief -------------------------------------------------
|
||||
* open - open an existing file for read or read/write
|
||||
@ -772,7 +778,7 @@ chd_error chd_file::open(const char *filename, bool writeable, chd_file *parent)
|
||||
* @return A chd_error.
|
||||
*/
|
||||
|
||||
chd_error chd_file::open(core_file &file, bool writeable, chd_file *parent)
|
||||
chd_error chd_file::open(util::core_file &file, bool writeable, chd_file *parent)
|
||||
{
|
||||
// make sure we don't already have a file open
|
||||
if (m_file != nullptr)
|
||||
@ -796,8 +802,8 @@ chd_error chd_file::open(core_file &file, bool writeable, chd_file *parent)
|
||||
void chd_file::close()
|
||||
{
|
||||
// reset file characteristics
|
||||
if (m_owns_file && m_file != nullptr)
|
||||
core_fclose(m_file);
|
||||
if (m_owns_file && m_file)
|
||||
delete m_file;
|
||||
m_file = nullptr;
|
||||
m_owns_file = false;
|
||||
m_allow_reads = false;
|
||||
|
@ -304,7 +304,7 @@ public:
|
||||
virtual ~chd_file();
|
||||
|
||||
// operators
|
||||
operator core_file *() { return m_file; }
|
||||
operator util::core_file &() { return *m_file; }
|
||||
|
||||
// getters
|
||||
bool opened() const { return (m_file != nullptr); }
|
||||
@ -328,13 +328,13 @@ public:
|
||||
|
||||
// file create
|
||||
chd_error create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4]);
|
||||
chd_error create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4]);
|
||||
chd_error create(util::core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4]);
|
||||
chd_error create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent);
|
||||
chd_error create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent);
|
||||
chd_error create(util::core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent);
|
||||
|
||||
// file open
|
||||
chd_error open(const char *filename, bool writeable = false, chd_file *parent = nullptr);
|
||||
chd_error open(core_file &file, bool writeable = false, chd_file *parent = nullptr);
|
||||
chd_error open(util::core_file &file, bool writeable = false, chd_file *parent = nullptr);
|
||||
|
||||
// file close
|
||||
void close();
|
||||
@ -401,7 +401,7 @@ private:
|
||||
static int CLIB_DECL metadata_hash_compare(const void *elem1, const void *elem2);
|
||||
|
||||
// file characteristics
|
||||
core_file * m_file; // handle to the open core file
|
||||
util::core_file * m_file; // handle to the open core file
|
||||
bool m_owns_file; // flag indicating if this file should be closed on chd_close()
|
||||
bool m_allow_reads; // permit reads from this CHD?
|
||||
bool m_allow_writes; // permit writes to this CHD?
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Aaron Giles
|
||||
// copyright-holders:Aaron Giles, Vas Crabb
|
||||
/***************************************************************************
|
||||
|
||||
corefile.h
|
||||
@ -15,11 +15,15 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "corestr.h"
|
||||
#include <string>
|
||||
#include "coretmpl.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace util {
|
||||
|
||||
/***************************************************************************
|
||||
ADDITIONAL OPEN FLAGS
|
||||
***************************************************************************/
|
||||
@ -32,99 +36,105 @@
|
||||
#define FCOMPRESS_MAX 9 /* maximum compression */
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
TYPE DEFINITIONS
|
||||
***************************************************************************/
|
||||
|
||||
struct core_file;
|
||||
class core_file
|
||||
{
|
||||
public:
|
||||
typedef std::unique_ptr<core_file> ptr;
|
||||
|
||||
|
||||
// ----- file open/close -----
|
||||
|
||||
// open a file with the specified filename
|
||||
static file_error open(const char *filename, std::uint32_t openflags, ptr &file);
|
||||
|
||||
// open a RAM-based "file" using the given data and length (read-only)
|
||||
static file_error open_ram(const void *data, std::size_t length, std::uint32_t openflags, ptr &file);
|
||||
|
||||
// open a RAM-based "file" using the given data and length (read-only), copying the data
|
||||
static file_error open_ram_copy(const void *data, std::size_t length, std::uint32_t openflags, ptr &file);
|
||||
|
||||
// open a proxy "file" that forwards requests to another file object
|
||||
static file_error open_proxy(core_file &file, ptr &proxy);
|
||||
|
||||
// close an open file
|
||||
virtual ~core_file();
|
||||
|
||||
// enable/disable streaming file compression via zlib; level is 0 to disable compression, or up to 9 for max compression
|
||||
virtual file_error compress(int level) = 0;
|
||||
|
||||
|
||||
// ----- file positioning -----
|
||||
|
||||
// adjust the file pointer within the file
|
||||
virtual int seek(std::int64_t offset, int whence) = 0;
|
||||
|
||||
// return the current file pointer
|
||||
virtual std::uint64_t tell() const = 0;
|
||||
|
||||
// return true if we are at the EOF
|
||||
virtual bool eof() const = 0;
|
||||
|
||||
// return the total size of the file
|
||||
virtual std::uint64_t size() const = 0;
|
||||
|
||||
|
||||
// ----- file read -----
|
||||
|
||||
// standard binary read from a file
|
||||
virtual std::uint32_t read(void *buffer, std::uint32_t length) = 0;
|
||||
|
||||
// read one character from the file
|
||||
virtual int getc() = 0;
|
||||
|
||||
// put back one character from the file
|
||||
virtual int ungetc(int c) = 0;
|
||||
|
||||
// read a full line of text from the file
|
||||
virtual char *gets(char *s, int n) = 0;
|
||||
|
||||
// get a pointer to a buffer that holds the full file data in RAM
|
||||
// this function may cause the full file data to be read
|
||||
virtual const void *buffer() = 0;
|
||||
|
||||
// open a file with the specified filename, read it into memory, and return a pointer
|
||||
static file_error load(const char *filename, void **data, std::uint32_t &length);
|
||||
static file_error load(const char *filename, dynamic_buffer &data);
|
||||
|
||||
|
||||
// ----- file write -----
|
||||
|
||||
// standard binary write to a file
|
||||
virtual std::uint32_t write(const void *buffer, std::uint32_t length) = 0;
|
||||
|
||||
// write a line of text to the file
|
||||
virtual int puts(const char *s) = 0;
|
||||
|
||||
// printf-style text write to a file
|
||||
virtual int vprintf(const char *fmt, va_list va) = 0;
|
||||
int CLIB_DECL printf(const char *fmt, ...) ATTR_PRINTF(2,3);
|
||||
|
||||
// file truncation
|
||||
virtual file_error truncate(std::uint64_t offset) = 0;
|
||||
|
||||
// flush file buffers
|
||||
virtual file_error flush() = 0;
|
||||
|
||||
|
||||
protected:
|
||||
core_file();
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
FUNCTION PROTOTYPES
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
/* ----- file open/close ----- */
|
||||
|
||||
/* open a file with the specified filename */
|
||||
file_error core_fopen(const char *filename, UINT32 openflags, core_file **file);
|
||||
|
||||
/* open a RAM-based "file" using the given data and length (read-only) */
|
||||
file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, core_file **file);
|
||||
|
||||
/* open a RAM-based "file" using the given data and length (read-only), copying the data */
|
||||
file_error core_fopen_ram_copy(const void *data, size_t length, UINT32 openflags, core_file **file);
|
||||
|
||||
/* close an open file */
|
||||
void core_fclose(core_file *file);
|
||||
|
||||
/* enable/disable streaming file compression via zlib; level is 0 to disable compression, or up to 9 for max compression */
|
||||
file_error core_fcompress(core_file *file, int level);
|
||||
|
||||
|
||||
|
||||
/* ----- file positioning ----- */
|
||||
|
||||
/* adjust the file pointer within the file */
|
||||
int core_fseek(core_file *file, INT64 offset, int whence);
|
||||
|
||||
/* return the current file pointer */
|
||||
UINT64 core_ftell(core_file *file);
|
||||
|
||||
/* return true if we are at the EOF */
|
||||
int core_feof(core_file *file);
|
||||
|
||||
/* return the total size of the file */
|
||||
UINT64 core_fsize(core_file *file);
|
||||
|
||||
|
||||
|
||||
/* ----- file read ----- */
|
||||
|
||||
/* standard binary read from a file */
|
||||
UINT32 core_fread(core_file *file, void *buffer, UINT32 length);
|
||||
|
||||
/* read one character from the file */
|
||||
int core_fgetc(core_file *file);
|
||||
|
||||
/* put back one character from the file */
|
||||
int core_ungetc(int c, core_file *file);
|
||||
|
||||
/* read a full line of text from the file */
|
||||
char *core_fgets(char *s, int n, core_file *file);
|
||||
|
||||
/* get a pointer to a buffer that holds the full file data in RAM */
|
||||
/* this function may cause the full file data to be read */
|
||||
const void *core_fbuffer(core_file *file);
|
||||
|
||||
/* open a file with the specified filename, read it into memory, and return a pointer */
|
||||
file_error core_fload(const char *filename, void **data, UINT32 *length);
|
||||
file_error core_fload(const char *filename, dynamic_buffer &data);
|
||||
|
||||
|
||||
|
||||
/* ----- file write ----- */
|
||||
|
||||
/* standard binary write to a file */
|
||||
UINT32 core_fwrite(core_file *file, const void *buffer, UINT32 length);
|
||||
|
||||
/* write a line of text to the file */
|
||||
int core_fputs(core_file *f, const char *s);
|
||||
|
||||
/* printf-style text write to a file */
|
||||
int core_vfprintf(core_file *f, const char *fmt, va_list va);
|
||||
int CLIB_DECL core_fprintf(core_file *f, const char *fmt, ...) ATTR_PRINTF(2,3);
|
||||
|
||||
/* file truncation */
|
||||
file_error core_truncate(core_file *f, UINT64 offset);
|
||||
|
||||
/* flush file buffers */
|
||||
file_error core_fflush(core_file *f);
|
||||
|
||||
|
||||
|
||||
/* ----- filename utilities ----- */
|
||||
|
||||
/* extract the base part of a filename (remove extensions and paths) */
|
||||
|
@ -35,7 +35,7 @@ flac_encoder::flac_encoder(void *buffer, UINT32 buflength)
|
||||
}
|
||||
|
||||
|
||||
flac_encoder::flac_encoder(core_file &file)
|
||||
flac_encoder::flac_encoder(util::core_file &file)
|
||||
{
|
||||
init_common();
|
||||
reset(file);
|
||||
@ -100,7 +100,7 @@ bool flac_encoder::reset(void *buffer, UINT32 buflength)
|
||||
// reset - reset state with new file parameters
|
||||
//-------------------------------------------------
|
||||
|
||||
bool flac_encoder::reset(core_file &file)
|
||||
bool flac_encoder::reset(util::core_file &file)
|
||||
{
|
||||
// configure the output
|
||||
m_compressed_start = nullptr;
|
||||
@ -185,7 +185,7 @@ UINT32 flac_encoder::finish()
|
||||
{
|
||||
// process the data and return the amount written
|
||||
FLAC__stream_encoder_finish(m_encoder);
|
||||
return (m_file != nullptr) ? core_ftell(m_file) : m_compressed_offset;
|
||||
return (m_file != nullptr) ? m_file->tell() : m_compressed_offset;
|
||||
}
|
||||
|
||||
|
||||
@ -252,7 +252,7 @@ FLAC__StreamEncoderWriteStatus flac_encoder::write_callback(const FLAC__byte buf
|
||||
{
|
||||
int count = bytes - offset;
|
||||
if (m_file != nullptr)
|
||||
core_fwrite(m_file, buffer, count);
|
||||
m_file->write(buffer, count);
|
||||
else
|
||||
{
|
||||
if (m_compressed_offset + count <= m_compressed_length)
|
||||
@ -308,7 +308,7 @@ flac_decoder::flac_decoder(const void *buffer, UINT32 length, const void *buffer
|
||||
// flac_decoder - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
flac_decoder::flac_decoder(core_file &file)
|
||||
flac_decoder::flac_decoder(util::core_file &file)
|
||||
: m_decoder(FLAC__stream_decoder_new()),
|
||||
m_file(&file),
|
||||
m_compressed_offset(0),
|
||||
@ -414,7 +414,7 @@ bool flac_decoder::reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_si
|
||||
// reset - reset state with new file parameter
|
||||
//-------------------------------------------------
|
||||
|
||||
bool flac_decoder::reset(core_file &file)
|
||||
bool flac_decoder::reset(util::core_file &file)
|
||||
{
|
||||
m_file = &file;
|
||||
m_compressed_start = nullptr;
|
||||
@ -511,7 +511,7 @@ FLAC__StreamDecoderReadStatus flac_decoder::read_callback(FLAC__byte buffer[], s
|
||||
|
||||
// if a file, just read
|
||||
if (m_file != nullptr)
|
||||
*bytes = core_fread(m_file, buffer, expected);
|
||||
*bytes = m_file->read(buffer, expected);
|
||||
|
||||
// otherwise, copy from memory
|
||||
else
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
// construction/destruction
|
||||
flac_encoder();
|
||||
flac_encoder(void *buffer, UINT32 buflength);
|
||||
flac_encoder(core_file &file);
|
||||
flac_encoder(util::core_file &file);
|
||||
~flac_encoder();
|
||||
|
||||
// configuration
|
||||
@ -51,7 +51,7 @@ public:
|
||||
// reset
|
||||
bool reset();
|
||||
bool reset(void *buffer, UINT32 buflength);
|
||||
bool reset(core_file &file);
|
||||
bool reset(util::core_file &file);
|
||||
|
||||
// encode a buffer
|
||||
bool encode_interleaved(const INT16 *samples, UINT32 samples_per_channel, bool swap_endian = false);
|
||||
@ -68,7 +68,7 @@ private:
|
||||
|
||||
// internal state
|
||||
FLAC__StreamEncoder * m_encoder; // actual encoder
|
||||
core_file * m_file; // output file
|
||||
util::core_file * m_file; // output file
|
||||
UINT32 m_compressed_offset; // current offset with the compressed stream
|
||||
FLAC__byte * m_compressed_start; // start of compressed data
|
||||
UINT32 m_compressed_length; // length of the compressed stream
|
||||
@ -93,7 +93,7 @@ public:
|
||||
// construction/destruction
|
||||
flac_decoder();
|
||||
flac_decoder(const void *buffer, UINT32 length, const void *buffer2 = nullptr, UINT32 length2 = 0);
|
||||
flac_decoder(core_file &file);
|
||||
flac_decoder(util::core_file &file);
|
||||
~flac_decoder();
|
||||
|
||||
// getters (valid after reset)
|
||||
@ -108,7 +108,7 @@ public:
|
||||
bool reset();
|
||||
bool reset(const void *buffer, UINT32 length, const void *buffer2 = nullptr, UINT32 length2 = 0);
|
||||
bool reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_size, const void *buffer, UINT32 length);
|
||||
bool reset(core_file &file);
|
||||
bool reset(util::core_file &file);
|
||||
|
||||
// decode to a buffer; num_samples must be a multiple of the block size
|
||||
bool decode_interleaved(INT16 *samples, UINT32 num_samples, bool swap_endian = false);
|
||||
@ -129,7 +129,7 @@ private:
|
||||
|
||||
// output state
|
||||
FLAC__StreamDecoder * m_decoder; // actual encoder
|
||||
core_file * m_file; // output file
|
||||
util::core_file * m_file; // output file
|
||||
UINT32 m_sample_rate; // decoded sample rate
|
||||
UINT8 m_channels; // decoded number of channels
|
||||
UINT8 m_bits_per_sample; // decoded bits per sample
|
||||
|
@ -400,11 +400,11 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std::
|
||||
// an INI file
|
||||
//-------------------------------------------------
|
||||
|
||||
bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_priority, std::string &error_string)
|
||||
bool core_options::parse_ini_file(util::core_file &inifile, int priority, int ignore_priority, std::string &error_string)
|
||||
{
|
||||
// loop over lines in the file
|
||||
char buffer[4096];
|
||||
while (core_fgets(buffer, ARRAY_LENGTH(buffer), &inifile) != nullptr)
|
||||
while (inifile.gets(buffer, ARRAY_LENGTH(buffer)) != nullptr)
|
||||
{
|
||||
// find the extent of the name
|
||||
char *optionname;
|
||||
|
@ -142,7 +142,7 @@ public:
|
||||
|
||||
// parsing/input
|
||||
bool parse_command_line(int argc, char **argv, int priority, std::string &error_string);
|
||||
bool parse_ini_file(core_file &inifile, int priority, int ignore_priority, std::string &error_string);
|
||||
bool parse_ini_file(util::core_file &inifile, int priority, int ignore_priority, std::string &error_string);
|
||||
|
||||
// reverting
|
||||
void revert(int priority = OPTION_PRIORITY_MAXIMUM);
|
||||
|
@ -148,12 +148,12 @@ void png_free(png_info *pnginfo)
|
||||
header at the current file location
|
||||
-------------------------------------------------*/
|
||||
|
||||
static png_error verify_header(core_file *fp)
|
||||
static png_error verify_header(util::core_file &fp)
|
||||
{
|
||||
UINT8 signature[8];
|
||||
|
||||
/* read 8 bytes */
|
||||
if (core_fread(fp, signature, 8) != 8)
|
||||
if (fp.read(signature, 8) != 8)
|
||||
return PNGERR_FILE_TRUNCATED;
|
||||
|
||||
/* return an error if we don't match */
|
||||
@ -168,18 +168,18 @@ static png_error verify_header(core_file *fp)
|
||||
read_chunk - read the next PNG chunk
|
||||
-------------------------------------------------*/
|
||||
|
||||
static png_error read_chunk(core_file *fp, UINT8 **data, UINT32 *type, UINT32 *length)
|
||||
static png_error read_chunk(util::core_file &fp, UINT8 **data, UINT32 *type, UINT32 *length)
|
||||
{
|
||||
UINT32 crc, chunk_crc;
|
||||
UINT8 tempbuff[4];
|
||||
|
||||
/* fetch the length of this chunk */
|
||||
if (core_fread(fp, tempbuff, 4) != 4)
|
||||
if (fp.read(tempbuff, 4) != 4)
|
||||
return PNGERR_FILE_TRUNCATED;
|
||||
*length = fetch_32bit(tempbuff);
|
||||
|
||||
/* fetch the type of this chunk */
|
||||
if (core_fread(fp, tempbuff, 4) != 4)
|
||||
if (fp.read(tempbuff, 4) != 4)
|
||||
return PNGERR_FILE_TRUNCATED;
|
||||
*type = fetch_32bit(tempbuff);
|
||||
|
||||
@ -200,7 +200,7 @@ static png_error read_chunk(core_file *fp, UINT8 **data, UINT32 *type, UINT32 *l
|
||||
return PNGERR_OUT_OF_MEMORY;
|
||||
|
||||
/* read the data from the file */
|
||||
if (core_fread(fp, *data, *length) != *length)
|
||||
if (fp.read(*data, *length) != *length)
|
||||
{
|
||||
free(*data);
|
||||
*data = nullptr;
|
||||
@ -212,7 +212,7 @@ static png_error read_chunk(core_file *fp, UINT8 **data, UINT32 *type, UINT32 *l
|
||||
}
|
||||
|
||||
/* read the CRC */
|
||||
if (core_fread(fp, tempbuff, 4) != 4)
|
||||
if (fp.read(tempbuff, 4) != 4)
|
||||
{
|
||||
free(*data);
|
||||
*data = nullptr;
|
||||
@ -502,7 +502,7 @@ handle_error:
|
||||
png_read_file - read a PNG from a core stream
|
||||
-------------------------------------------------*/
|
||||
|
||||
png_error png_read_file(core_file *fp, png_info *pnginfo)
|
||||
png_error png_read_file(util::core_file &fp, png_info *pnginfo)
|
||||
{
|
||||
UINT8 *chunk_data = nullptr;
|
||||
png_private png;
|
||||
@ -579,7 +579,7 @@ handle_error:
|
||||
bitmap
|
||||
-------------------------------------------------*/
|
||||
|
||||
png_error png_read_bitmap(core_file *fp, bitmap_argb32 &bitmap)
|
||||
png_error png_read_bitmap(util::core_file &fp, bitmap_argb32 &bitmap)
|
||||
{
|
||||
png_error result;
|
||||
png_info png;
|
||||
@ -747,7 +747,7 @@ png_error png_add_text(png_info *pnginfo, const char *keyword, const char *text)
|
||||
the given file
|
||||
-------------------------------------------------*/
|
||||
|
||||
static png_error write_chunk(core_file *fp, const UINT8 *data, UINT32 type, UINT32 length)
|
||||
static png_error write_chunk(util::core_file &fp, const UINT8 *data, UINT32 type, UINT32 length)
|
||||
{
|
||||
UINT8 tempbuff[8];
|
||||
UINT32 crc;
|
||||
@ -758,20 +758,20 @@ static png_error write_chunk(core_file *fp, const UINT8 *data, UINT32 type, UINT
|
||||
crc = crc32(0, tempbuff + 4, 4);
|
||||
|
||||
/* write that data */
|
||||
if (core_fwrite(fp, tempbuff, 8) != 8)
|
||||
if (fp.write(tempbuff, 8) != 8)
|
||||
return PNGERR_FILE_ERROR;
|
||||
|
||||
/* append the actual data */
|
||||
if (length > 0)
|
||||
{
|
||||
if (core_fwrite(fp, data, length) != length)
|
||||
if (fp.write(data, length) != length)
|
||||
return PNGERR_FILE_ERROR;
|
||||
crc = crc32(crc, data, length);
|
||||
}
|
||||
|
||||
/* write the CRC */
|
||||
put_32bit(tempbuff, crc);
|
||||
if (core_fwrite(fp, tempbuff, 4) != 4)
|
||||
if (fp.write(tempbuff, 4) != 4)
|
||||
return PNGERR_FILE_ERROR;
|
||||
|
||||
return PNGERR_NONE;
|
||||
@ -783,9 +783,9 @@ static png_error write_chunk(core_file *fp, const UINT8 *data, UINT32 type, UINT
|
||||
chunk to the given file by deflating it
|
||||
-------------------------------------------------*/
|
||||
|
||||
static png_error write_deflated_chunk(core_file *fp, UINT8 *data, UINT32 type, UINT32 length)
|
||||
static png_error write_deflated_chunk(util::core_file &fp, UINT8 *data, UINT32 type, UINT32 length)
|
||||
{
|
||||
UINT64 lengthpos = core_ftell(fp);
|
||||
UINT64 lengthpos = fp.tell();
|
||||
UINT8 tempbuff[8192];
|
||||
UINT32 zlength = 0;
|
||||
z_stream stream;
|
||||
@ -798,7 +798,7 @@ static png_error write_deflated_chunk(core_file *fp, UINT8 *data, UINT32 type, U
|
||||
crc = crc32(0, tempbuff + 4, 4);
|
||||
|
||||
/* write that data */
|
||||
if (core_fwrite(fp, tempbuff, 8) != 8)
|
||||
if (fp.write(tempbuff, 8) != 8)
|
||||
return PNGERR_FILE_ERROR;
|
||||
|
||||
/* initialize the stream */
|
||||
@ -821,7 +821,7 @@ static png_error write_deflated_chunk(core_file *fp, UINT8 *data, UINT32 type, U
|
||||
if (stream.avail_out < sizeof(tempbuff))
|
||||
{
|
||||
int bytes = sizeof(tempbuff) - stream.avail_out;
|
||||
if (core_fwrite(fp, tempbuff, bytes) != bytes)
|
||||
if (fp.write(tempbuff, bytes) != bytes)
|
||||
{
|
||||
deflateEnd(&stream);
|
||||
return PNGERR_FILE_ERROR;
|
||||
@ -849,17 +849,17 @@ static png_error write_deflated_chunk(core_file *fp, UINT8 *data, UINT32 type, U
|
||||
|
||||
/* write the CRC */
|
||||
put_32bit(tempbuff, crc);
|
||||
if (core_fwrite(fp, tempbuff, 4) != 4)
|
||||
if (fp.write(tempbuff, 4) != 4)
|
||||
return PNGERR_FILE_ERROR;
|
||||
|
||||
/* seek back and update the length */
|
||||
core_fseek(fp, lengthpos, SEEK_SET);
|
||||
fp.seek(lengthpos, SEEK_SET);
|
||||
put_32bit(tempbuff + 0, zlength);
|
||||
if (core_fwrite(fp, tempbuff, 4) != 4)
|
||||
if (fp.write(tempbuff, 4) != 4)
|
||||
return PNGERR_FILE_ERROR;
|
||||
|
||||
/* return to the end */
|
||||
core_fseek(fp, lengthpos + 8 + zlength + 4, SEEK_SET);
|
||||
fp.seek(lengthpos + 8 + zlength + 4, SEEK_SET);
|
||||
return PNGERR_NONE;
|
||||
}
|
||||
|
||||
@ -1006,7 +1006,7 @@ static png_error convert_bitmap_to_image_rgb(png_info *pnginfo, const bitmap_t &
|
||||
chunks to the given file
|
||||
-------------------------------------------------*/
|
||||
|
||||
static png_error write_png_stream(core_file *fp, png_info *pnginfo, const bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
static png_error write_png_stream(util::core_file &fp, png_info *pnginfo, const bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
{
|
||||
UINT8 tempbuff[16];
|
||||
png_text *text;
|
||||
@ -1061,7 +1061,7 @@ handle_error:
|
||||
}
|
||||
|
||||
|
||||
png_error png_write_bitmap(core_file *fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
png_error png_write_bitmap(util::core_file &fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
{
|
||||
png_info pnginfo;
|
||||
png_error error;
|
||||
@ -1074,7 +1074,7 @@ png_error png_write_bitmap(core_file *fp, png_info *info, bitmap_t &bitmap, int
|
||||
}
|
||||
|
||||
/* write the PNG signature */
|
||||
if (core_fwrite(fp, PNG_Signature, 8) != 8)
|
||||
if (fp.write(PNG_Signature, 8) != 8)
|
||||
{
|
||||
if (info == &pnginfo)
|
||||
png_free(&pnginfo);
|
||||
@ -1097,7 +1097,7 @@ png_error png_write_bitmap(core_file *fp, png_info *info, bitmap_t &bitmap, int
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @fn png_error mng_capture_start(core_file *fp, bitmap_t &bitmap, double rate)
|
||||
* @fn png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, double rate)
|
||||
*
|
||||
* @brief Mng capture start.
|
||||
*
|
||||
@ -1108,12 +1108,12 @@ png_error png_write_bitmap(core_file *fp, png_info *info, bitmap_t &bitmap, int
|
||||
* @return A png_error.
|
||||
*/
|
||||
|
||||
png_error mng_capture_start(core_file *fp, bitmap_t &bitmap, double rate)
|
||||
png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, double rate)
|
||||
{
|
||||
UINT8 mhdr[28];
|
||||
png_error error;
|
||||
|
||||
if (core_fwrite(fp, MNG_Signature, 8) != 8)
|
||||
if (fp.write(MNG_Signature, 8) != 8)
|
||||
return PNGERR_FILE_ERROR;
|
||||
|
||||
memset(mhdr, 0, 28);
|
||||
@ -1131,7 +1131,7 @@ png_error mng_capture_start(core_file *fp, bitmap_t &bitmap, double rate)
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn png_error mng_capture_frame(core_file *fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
* @fn png_error mng_capture_frame(util::core_file &fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
*
|
||||
* @brief Mng capture frame.
|
||||
*
|
||||
@ -1144,13 +1144,13 @@ png_error mng_capture_start(core_file *fp, bitmap_t &bitmap, double rate)
|
||||
* @return A png_error.
|
||||
*/
|
||||
|
||||
png_error mng_capture_frame(core_file *fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
png_error mng_capture_frame(util::core_file &fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette)
|
||||
{
|
||||
return write_png_stream(fp, info, bitmap, palette_length, palette);
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn png_error mng_capture_stop(core_file *fp)
|
||||
* @fn png_error mng_capture_stop(util::core_file &fp)
|
||||
*
|
||||
* @brief Mng capture stop.
|
||||
*
|
||||
@ -1159,7 +1159,7 @@ png_error mng_capture_frame(core_file *fp, png_info *info, bitmap_t &bitmap, int
|
||||
* @return A png_error.
|
||||
*/
|
||||
|
||||
png_error mng_capture_stop(core_file *fp)
|
||||
png_error mng_capture_stop(util::core_file &fp)
|
||||
{
|
||||
return write_chunk(fp, nullptr, MNG_CN_MEND, 0);
|
||||
}
|
||||
|
@ -119,15 +119,15 @@ struct png_info
|
||||
|
||||
void png_free(png_info *pnginfo);
|
||||
|
||||
png_error png_read_file(core_file *fp, png_info *pnginfo);
|
||||
png_error png_read_bitmap(core_file *fp, bitmap_argb32 &bitmap);
|
||||
png_error png_read_file(util::core_file &fp, png_info *pnginfo);
|
||||
png_error png_read_bitmap(util::core_file &fp, bitmap_argb32 &bitmap);
|
||||
png_error png_expand_buffer_8bit(png_info *p);
|
||||
|
||||
png_error png_add_text(png_info *pnginfo, const char *keyword, const char *text);
|
||||
png_error png_write_bitmap(core_file *fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette);
|
||||
png_error png_write_bitmap(util::core_file &fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette);
|
||||
|
||||
png_error mng_capture_start(core_file *fp, bitmap_t &bitmap, double rate);
|
||||
png_error mng_capture_frame(core_file *fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette);
|
||||
png_error mng_capture_stop(core_file *fp);
|
||||
png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, double rate);
|
||||
png_error mng_capture_frame(util::core_file &fp, png_info *info, bitmap_t &bitmap, int palette_length, const rgb_t *palette);
|
||||
png_error mng_capture_stop(util::core_file &fp);
|
||||
|
||||
#endif /* __PNG_H__ */
|
||||
|
@ -52,7 +52,7 @@ static xml_data_node *add_child(xml_data_node *parent, const char *name, const c
|
||||
static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, const char *value);
|
||||
|
||||
/* recursive tree operations */
|
||||
static void write_node_recursive(xml_data_node *node, int indent, core_file *file);
|
||||
static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file);
|
||||
static void free_node_recursive(xml_data_node *node);
|
||||
|
||||
|
||||
@ -139,7 +139,7 @@ xml_data_node *xml_file_create(void)
|
||||
nodes
|
||||
-------------------------------------------------*/
|
||||
|
||||
xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts)
|
||||
xml_data_node *xml_file_read(util::core_file &file, xml_parse_options *opts)
|
||||
{
|
||||
xml_parse_info parse_info;
|
||||
int done;
|
||||
@ -154,8 +154,8 @@ xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts)
|
||||
char tempbuf[TEMP_BUFFER_SIZE];
|
||||
|
||||
/* read as much as we can */
|
||||
int bytes = core_fread(file, tempbuf, sizeof(tempbuf));
|
||||
done = core_feof(file);
|
||||
int bytes = file.read(tempbuf, sizeof(tempbuf));
|
||||
done = file.eof();
|
||||
|
||||
/* parse the data */
|
||||
if (XML_Parse(parse_info.parser, tempbuf, bytes, done) == XML_STATUS_ERROR)
|
||||
@ -223,15 +223,15 @@ xml_data_node *xml_string_read(const char *string, xml_parse_options *opts)
|
||||
xml_file_write - write an XML tree to a file
|
||||
-------------------------------------------------*/
|
||||
|
||||
void xml_file_write(xml_data_node *node, core_file *file)
|
||||
void xml_file_write(xml_data_node *node, util::core_file &file)
|
||||
{
|
||||
/* ensure this is a root node */
|
||||
if (node->name != nullptr)
|
||||
return;
|
||||
|
||||
/* output a simple header */
|
||||
core_fprintf(file, "<?xml version=\"1.0\"?>\n");
|
||||
core_fprintf(file, "<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");
|
||||
file.printf("<?xml version=\"1.0\"?>\n");
|
||||
file.printf("<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");
|
||||
|
||||
/* loop over children of the root and output */
|
||||
for (node = node->child; node; node = node->next)
|
||||
@ -1002,7 +1002,7 @@ static xml_attribute_node *add_attribute(xml_data_node *node, const char *name,
|
||||
-------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @fn static void write_node_recursive(xml_data_node *node, int indent, core_file *file)
|
||||
* @fn static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file)
|
||||
*
|
||||
* @brief Writes a node recursive.
|
||||
*
|
||||
@ -1011,30 +1011,30 @@ static xml_attribute_node *add_attribute(xml_data_node *node, const char *name,
|
||||
* @param [in,out] file If non-null, the file.
|
||||
*/
|
||||
|
||||
static void write_node_recursive(xml_data_node *node, int indent, core_file *file)
|
||||
static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file)
|
||||
{
|
||||
xml_attribute_node *anode;
|
||||
xml_data_node *child;
|
||||
|
||||
/* output this tag */
|
||||
core_fprintf(file, "%*s<%s", indent, "", node->name);
|
||||
file.printf("%*s<%s", indent, "", node->name);
|
||||
|
||||
/* output any attributes */
|
||||
for (anode = node->attribute; anode; anode = anode->next)
|
||||
core_fprintf(file, " %s=\"%s\"", anode->name, anode->value);
|
||||
file.printf(" %s=\"%s\"", anode->name, anode->value);
|
||||
|
||||
/* if there are no children and no value, end the tag here */
|
||||
if (node->child == nullptr && node->value == nullptr)
|
||||
core_fprintf(file, " />\n");
|
||||
file.printf(" />\n");
|
||||
|
||||
/* otherwise, close this tag and output more stuff */
|
||||
else
|
||||
{
|
||||
core_fprintf(file, ">\n");
|
||||
file.printf(">\n");
|
||||
|
||||
/* if there is a value, output that here */
|
||||
if (node->value != nullptr)
|
||||
core_fprintf(file, "%*s%s\n", indent + 4, "", node->value);
|
||||
file.printf("%*s%s\n", indent + 4, "", node->value);
|
||||
|
||||
/* loop over children and output them as well */
|
||||
if (node->child != nullptr)
|
||||
@ -1044,7 +1044,7 @@ static void write_node_recursive(xml_data_node *node, int indent, core_file *fil
|
||||
}
|
||||
|
||||
/* write a closing tag */
|
||||
core_fprintf(file, "%*s</%s>\n", indent, "", node->name);
|
||||
file.printf("%*s</%s>\n", indent, "", node->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,13 +97,13 @@ struct xml_parse_options
|
||||
xml_data_node *xml_file_create(void);
|
||||
|
||||
/* parse an XML file into its nodes */
|
||||
xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts);
|
||||
xml_data_node *xml_file_read(util::core_file &file, xml_parse_options *opts);
|
||||
|
||||
/* parse an XML string into its nodes */
|
||||
xml_data_node *xml_string_read(const char *string, xml_parse_options *opts);
|
||||
|
||||
/* write an XML tree to a file */
|
||||
void xml_file_write(xml_data_node *node, core_file *file);
|
||||
void xml_file_write(xml_data_node *node, util::core_file &file);
|
||||
|
||||
/* free an XML file object */
|
||||
void xml_file_free(xml_data_node *node);
|
||||
|
@ -298,7 +298,7 @@ static file_error file_error_from_zip_error(zip_error ziperr)
|
||||
-------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @fn static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header *header, core_file *&file)
|
||||
* @fn static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header *header, util::core_file::ptr &file)
|
||||
*
|
||||
* @brief Creates core file from zip.
|
||||
*
|
||||
@ -309,7 +309,7 @@ static file_error file_error_from_zip_error(zip_error ziperr)
|
||||
* @return The new core file from zip.
|
||||
*/
|
||||
|
||||
static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header *header, core_file *&file)
|
||||
static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header *header, util::core_file::ptr &file)
|
||||
{
|
||||
file_error filerr;
|
||||
zip_error ziperr;
|
||||
@ -329,7 +329,7 @@ static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header
|
||||
goto done;
|
||||
}
|
||||
|
||||
filerr = core_fopen_ram_copy(ptr, header->uncompressed_length, OPEN_FLAG_READ, &file);
|
||||
filerr = util::core_file::open_ram_copy(ptr, header->uncompressed_length, OPEN_FLAG_READ, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
goto done;
|
||||
|
||||
@ -345,7 +345,7 @@ done:
|
||||
-------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @fn file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&file, std::string &revised_path)
|
||||
* @fn file_error zippath_fopen(const char *filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path)
|
||||
*
|
||||
* @brief Zippath fopen.
|
||||
*
|
||||
@ -357,7 +357,7 @@ done:
|
||||
* @return A file_error.
|
||||
*/
|
||||
|
||||
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&file, std::string &revised_path)
|
||||
file_error zippath_fopen(const char *filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path)
|
||||
{
|
||||
file_error filerr = FILERR_NOT_FOUND;
|
||||
zip_error ziperr;
|
||||
@ -421,7 +421,7 @@ file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&fil
|
||||
}
|
||||
|
||||
if (subpath.length() == 0)
|
||||
filerr = core_fopen(filename, openflags, &file);
|
||||
filerr = util::core_file::open(filename, openflags, file);
|
||||
else
|
||||
filerr = FILERR_NOT_FOUND;
|
||||
|
||||
|
@ -45,7 +45,7 @@ std::string &zippath_combine(std::string &dst, const char *path1, const char *pa
|
||||
/* ----- file operations ----- */
|
||||
|
||||
/* opens a zip path file */
|
||||
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&file, std::string &revised_path);
|
||||
file_error zippath_fopen(const char *filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path);
|
||||
|
||||
|
||||
/* ----- directory operations ----- */
|
||||
|
@ -187,10 +187,10 @@ class chd_rawfile_compressor : public chd_file_compressor
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
chd_rawfile_compressor(core_file *file, UINT64 offset = 0, UINT64 maxoffset = ~0)
|
||||
chd_rawfile_compressor(util::core_file &file, UINT64 offset = 0, UINT64 maxoffset = ~0)
|
||||
: m_file(file),
|
||||
m_offset(offset),
|
||||
m_maxoffset(MIN(maxoffset, (file != nullptr) ? core_fsize(file) : 0)) { }
|
||||
m_maxoffset((std::min)(maxoffset, file.size())) { }
|
||||
|
||||
// read interface
|
||||
virtual UINT32 read_data(void *dest, UINT64 offset, UINT32 length)
|
||||
@ -200,15 +200,15 @@ public:
|
||||
return 0;
|
||||
if (offset + length > m_maxoffset)
|
||||
length = m_maxoffset - offset;
|
||||
core_fseek(m_file, offset, SEEK_SET);
|
||||
return core_fread(m_file, dest, length);
|
||||
m_file.seek(offset, SEEK_SET);
|
||||
return m_file.read(dest, length);
|
||||
}
|
||||
|
||||
private:
|
||||
// internal state
|
||||
core_file * m_file;
|
||||
UINT64 m_offset;
|
||||
UINT64 m_maxoffset;
|
||||
util::core_file & m_file;
|
||||
UINT64 m_offset;
|
||||
UINT64 m_maxoffset;
|
||||
};
|
||||
|
||||
|
||||
@ -290,14 +290,12 @@ class chd_cd_compressor : public chd_file_compressor
|
||||
public:
|
||||
// construction/destruction
|
||||
chd_cd_compressor(cdrom_toc &toc, chdcd_track_input_info &info)
|
||||
: m_file(nullptr),
|
||||
: m_file(),
|
||||
m_toc(toc),
|
||||
m_info(info) { }
|
||||
|
||||
~chd_cd_compressor()
|
||||
{
|
||||
if (m_file != nullptr)
|
||||
core_fclose(m_file);
|
||||
}
|
||||
|
||||
// read interface
|
||||
@ -321,12 +319,11 @@ public:
|
||||
if (offset >= startoffs && offset < endoffs)
|
||||
{
|
||||
// if we don't already have this file open, open it now
|
||||
if (m_file == nullptr || m_lastfile.compare(m_info.track[tracknum].fname)!=0)
|
||||
if (!m_file || m_lastfile.compare(m_info.track[tracknum].fname)!=0)
|
||||
{
|
||||
if (m_file != nullptr)
|
||||
core_fclose(m_file);
|
||||
m_file.reset();
|
||||
m_lastfile = m_info.track[tracknum].fname;
|
||||
file_error filerr = core_fopen(m_lastfile.c_str(), OPEN_FLAG_READ, &m_file);
|
||||
file_error filerr = util::core_file::open(m_lastfile.c_str(), OPEN_FLAG_READ, m_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Error opening input file (%s)'", m_lastfile.c_str());
|
||||
}
|
||||
@ -349,8 +346,8 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
core_fseek(m_file, src_frame_start, SEEK_SET);
|
||||
UINT32 count = core_fread(m_file, dest, bytesperframe);
|
||||
m_file->seek(src_frame_start, SEEK_SET);
|
||||
UINT32 count = m_file->read(dest, bytesperframe);
|
||||
if (count != bytesperframe)
|
||||
report_error(1, "Error reading input file (%s)'", m_lastfile.c_str());
|
||||
}
|
||||
@ -383,7 +380,7 @@ public:
|
||||
private:
|
||||
// internal state
|
||||
std::string m_lastfile;
|
||||
core_file * m_file;
|
||||
util::core_file::ptr m_file;
|
||||
cdrom_toc & m_toc;
|
||||
chdcd_track_input_info & m_info;
|
||||
};
|
||||
@ -1008,11 +1005,11 @@ static void check_existing_output_file(const parameters_t ¶ms, const char *f
|
||||
{
|
||||
if (params.find(OPTION_OUTPUT_FORCE) == params.end())
|
||||
{
|
||||
core_file *file;
|
||||
file_error filerr = core_fopen(filename, OPEN_FLAG_READ, &file);
|
||||
util::core_file::ptr file;
|
||||
file_error filerr = util::core_file::open(filename, OPEN_FLAG_READ, file);
|
||||
if (filerr == FILERR_NONE)
|
||||
{
|
||||
core_fclose(file);
|
||||
file.reset();
|
||||
report_error(1, "Error: file already exists (%s)\nUse --force (or -f) to force overwriting", filename);
|
||||
}
|
||||
}
|
||||
@ -1185,7 +1182,7 @@ static void compress_common(chd_file_compressor &chd)
|
||||
// to a CUE file
|
||||
//-------------------------------------------------
|
||||
|
||||
void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_track_info &info, const char *filename, UINT32 frameoffs, UINT64 discoffs)
|
||||
void output_track_metadata(int mode, util::core_file &file, int tracknum, const cdrom_track_info &info, const char *filename, UINT32 frameoffs, UINT64 discoffs)
|
||||
{
|
||||
if (mode == MODE_GDI)
|
||||
{
|
||||
@ -1234,13 +1231,13 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
|
||||
break;
|
||||
}
|
||||
bool needquote = strchr(filename, ' ') != nullptr;
|
||||
core_fprintf(file, "%d %d %d %d %s%s%s %" I64FMT "d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs);
|
||||
file.printf("%d %d %d %d %s%s%s %" I64FMT "d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs);
|
||||
}
|
||||
else if (mode == MODE_CUEBIN)
|
||||
{
|
||||
// first track specifies the file
|
||||
if (tracknum == 0)
|
||||
core_fprintf(file, "FILE \"%s\" BINARY\n", filename);
|
||||
file.printf("FILE \"%s\" BINARY\n", filename);
|
||||
|
||||
// determine submode
|
||||
std::string tempstr;
|
||||
@ -1265,37 +1262,37 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
|
||||
}
|
||||
|
||||
// output TRACK entry
|
||||
core_fprintf(file, " TRACK %02d %s\n", tracknum + 1, tempstr.c_str());
|
||||
file.printf(" TRACK %02d %s\n", tracknum + 1, tempstr.c_str());
|
||||
|
||||
// output PREGAP tag if pregap sectors are not in the file
|
||||
if ((info.pregap > 0) && (info.pgdatasize == 0))
|
||||
{
|
||||
core_fprintf(file, " PREGAP %s\n", msf_string_from_frames(tempstr, info.pregap));
|
||||
core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
|
||||
file.printf(" PREGAP %s\n", msf_string_from_frames(tempstr, info.pregap));
|
||||
file.printf(" INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
|
||||
}
|
||||
else if ((info.pregap > 0) && (info.pgdatasize > 0))
|
||||
{
|
||||
core_fprintf(file, " INDEX 00 %s\n", msf_string_from_frames(tempstr, frameoffs));
|
||||
core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs+info.pregap));
|
||||
file.printf(" INDEX 00 %s\n", msf_string_from_frames(tempstr, frameoffs));
|
||||
file.printf(" INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs+info.pregap));
|
||||
}
|
||||
|
||||
// if no pregap at all, output index 01 only
|
||||
if (info.pregap == 0)
|
||||
{
|
||||
core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
|
||||
file.printf(" INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
|
||||
}
|
||||
|
||||
// output POSTGAP
|
||||
if (info.postgap > 0)
|
||||
core_fprintf(file, " POSTGAP %s\n", msf_string_from_frames(tempstr, info.postgap));
|
||||
file.printf(" POSTGAP %s\n", msf_string_from_frames(tempstr, info.postgap));
|
||||
}
|
||||
// non-CUE mode
|
||||
else if (mode == MODE_NORMAL)
|
||||
{
|
||||
// header on the first track
|
||||
if (tracknum == 0)
|
||||
core_fprintf(file, "CD_ROM\n\n\n");
|
||||
core_fprintf(file, "// Track %d\n", tracknum + 1);
|
||||
file.printf("CD_ROM\n\n\n");
|
||||
file.printf("// Track %d\n", tracknum + 1);
|
||||
|
||||
// write out the track type
|
||||
std::string modesubmode;
|
||||
@ -1303,32 +1300,32 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
|
||||
modesubmode = string_format("%s %s", cdrom_get_type_string(info.trktype), cdrom_get_subtype_string(info.subtype));
|
||||
else
|
||||
modesubmode = string_format("%s", cdrom_get_type_string(info.trktype));
|
||||
core_fprintf(file, "TRACK %s\n", modesubmode.c_str());
|
||||
file.printf("TRACK %s\n", modesubmode.c_str());
|
||||
|
||||
// write out the attributes
|
||||
core_fprintf(file, "NO COPY\n");
|
||||
file.printf("NO COPY\n");
|
||||
if (info.trktype == CD_TRACK_AUDIO)
|
||||
{
|
||||
core_fprintf(file, "NO PRE_EMPHASIS\n");
|
||||
core_fprintf(file, "TWO_CHANNEL_AUDIO\n");
|
||||
file.printf("NO PRE_EMPHASIS\n");
|
||||
file.printf("TWO_CHANNEL_AUDIO\n");
|
||||
}
|
||||
|
||||
// output pregap
|
||||
std::string tempstr;
|
||||
if (info.pregap > 0)
|
||||
core_fprintf(file, "ZERO %s %s\n", modesubmode.c_str(), msf_string_from_frames(tempstr, info.pregap));
|
||||
file.printf("ZERO %s %s\n", modesubmode.c_str(), msf_string_from_frames(tempstr, info.pregap));
|
||||
|
||||
// all tracks but the first one have a file offset
|
||||
if (tracknum > 0)
|
||||
core_fprintf(file, "DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename, UINT32(discoffs), msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
|
||||
file.printf("DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename, UINT32(discoffs), msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
|
||||
else
|
||||
core_fprintf(file, "DATAFILE \"%s\" %s // length in bytes: %d\n", filename, msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
|
||||
file.printf("DATAFILE \"%s\" %s // length in bytes: %d\n", filename, msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
|
||||
|
||||
// tracks with pregaps get a START marker too
|
||||
if (info.pregap > 0)
|
||||
core_fprintf(file, "START %s\n", msf_string_from_frames(tempstr, info.pregap));
|
||||
file.printf("START %s\n", msf_string_from_frames(tempstr, info.pregap));
|
||||
|
||||
core_fprintf(file, "\n\n");
|
||||
file.printf("\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1361,9 +1358,9 @@ static void do_info(parameters_t ¶ms)
|
||||
printf("Unit Size: %s bytes\n", big_int_string(tempstr, input_chd.unit_bytes()));
|
||||
printf("Total Units: %s\n", big_int_string(tempstr, input_chd.unit_count()));
|
||||
printf("Compression: %s\n", compression_string(tempstr, compression));
|
||||
printf("CHD size: %s bytes\n", big_int_string(tempstr, core_fsize(input_chd)));
|
||||
printf("CHD size: %s bytes\n", big_int_string(tempstr, static_cast<util::core_file &>(input_chd).size()));
|
||||
if (compression[0] != CHD_CODEC_NONE)
|
||||
printf("Ratio: %.1f%%\n", 100.0 * double(core_fsize(input_chd)) / double(input_chd.logical_bytes()));
|
||||
printf("Ratio: %.1f%%\n", 100.0 * double(static_cast<util::core_file &>(input_chd).size()) / double(input_chd.logical_bytes()));
|
||||
|
||||
// add SHA1 output
|
||||
sha1_t overall = input_chd.sha1();
|
||||
@ -1570,11 +1567,11 @@ static void do_verify(parameters_t ¶ms)
|
||||
static void do_create_raw(parameters_t ¶ms)
|
||||
{
|
||||
// process input file
|
||||
core_file *input_file = nullptr;
|
||||
util::core_file::ptr input_file;
|
||||
auto input_file_str = params.find(OPTION_INPUT);
|
||||
if (input_file_str != params.end())
|
||||
{
|
||||
file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file);
|
||||
file_error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Unable to open file (%s)", input_file_str->second->c_str());
|
||||
}
|
||||
@ -1600,7 +1597,7 @@ static void do_create_raw(parameters_t ¶ms)
|
||||
// process input start/end (needs to know hunk_size)
|
||||
UINT64 input_start;
|
||||
UINT64 input_end;
|
||||
parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
|
||||
parse_input_start_end(params, input_file->size(), hunk_size, hunk_size, input_start, input_end);
|
||||
|
||||
// process compression
|
||||
chd_codec_type compression[4];
|
||||
@ -1616,7 +1613,7 @@ static void do_create_raw(parameters_t ¶ms)
|
||||
if (output_parent.opened())
|
||||
printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
|
||||
printf("Input file: %s\n", input_file_str->second->c_str());
|
||||
if (input_start != 0 || input_end != core_fsize(input_file))
|
||||
if (input_start != 0 || input_end != input_file->size())
|
||||
{
|
||||
printf("Input start: %s\n", big_int_string(tempstr, input_start));
|
||||
printf("Input length: %s\n", big_int_string(tempstr, input_end - input_start));
|
||||
@ -1630,7 +1627,7 @@ static void do_create_raw(parameters_t ¶ms)
|
||||
try
|
||||
{
|
||||
// create the new CHD
|
||||
chd = new chd_rawfile_compressor(input_file, input_start, input_end);
|
||||
chd = new chd_rawfile_compressor(*input_file, input_start, input_end);
|
||||
chd_error err;
|
||||
if (output_parent.opened())
|
||||
err = chd->create(output_chd_str->c_str(), input_end - input_start, hunk_size, compression, output_parent);
|
||||
@ -1667,11 +1664,11 @@ static void do_create_raw(parameters_t ¶ms)
|
||||
static void do_create_hd(parameters_t ¶ms)
|
||||
{
|
||||
// process input file
|
||||
core_file *input_file = nullptr;
|
||||
util::core_file::ptr input_file;
|
||||
auto input_file_str = params.find(OPTION_INPUT);
|
||||
if (input_file_str != params.end())
|
||||
{
|
||||
file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file);
|
||||
file_error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Unable to open file (%s)", input_file_str->second->c_str());
|
||||
}
|
||||
@ -1698,9 +1695,9 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
UINT64 filesize = 0;
|
||||
UINT64 input_start = 0;
|
||||
UINT64 input_end = 0;
|
||||
if (input_file != nullptr)
|
||||
if (input_file)
|
||||
{
|
||||
parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
|
||||
parse_input_start_end(params, input_file->size(), hunk_size, hunk_size, input_start, input_end);
|
||||
filesize = input_end - input_start;
|
||||
}
|
||||
else
|
||||
@ -1716,10 +1713,10 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
// process compression
|
||||
chd_codec_type compression[4];
|
||||
memcpy(compression, s_default_hd_compression, sizeof(compression));
|
||||
if (input_file == nullptr)
|
||||
if (!input_file)
|
||||
compression[0] = compression[1] = compression[2] = compression[3] = CHD_CODEC_NONE;
|
||||
parse_compression(params, compression);
|
||||
if (input_file == nullptr && compression[0] != CHD_CODEC_NONE)
|
||||
if (!input_file && compression[0] != CHD_CODEC_NONE)
|
||||
report_error(1, "Blank hard disks must be uncompressed");
|
||||
|
||||
// process numprocessors
|
||||
@ -1746,7 +1743,7 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
if (ident_str != params.end())
|
||||
{
|
||||
// load the file
|
||||
file_error filerr = core_fload(ident_str->second->c_str(), identdata);
|
||||
file_error filerr = util::core_file::load(ident_str->second->c_str(), identdata);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Error reading ident file (%s)", ident_str->second->c_str());
|
||||
|
||||
@ -1775,7 +1772,7 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
// if no CHS values, try to guess them
|
||||
if (cylinders == 0)
|
||||
{
|
||||
if (input_file == nullptr && filesize == 0)
|
||||
if (!input_file && filesize == 0)
|
||||
report_error(1, "Blank hard drives must specify either a length or a set of CHS values");
|
||||
guess_chs((input_file_str != params.end()) ? input_file_str->second : nullptr, filesize, sector_size, cylinders, heads, sectors, sector_size);
|
||||
}
|
||||
@ -1786,10 +1783,10 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
printf("Output CHD: %s\n", output_chd_str->c_str());
|
||||
if (output_parent.opened())
|
||||
printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
|
||||
if (input_file != nullptr)
|
||||
if (input_file)
|
||||
{
|
||||
printf("Input file: %s\n", input_file_str->second->c_str());
|
||||
if (input_start != 0 || input_end != core_fsize(input_file))
|
||||
if (input_start != 0 || input_end != input_file->size())
|
||||
{
|
||||
printf("Input start: %s\n", big_int_string(tempstr, input_start));
|
||||
printf("Input length: %s\n", big_int_string(tempstr, filesize));
|
||||
@ -1808,7 +1805,7 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
try
|
||||
{
|
||||
// create the new hard drive
|
||||
chd = new chd_rawfile_compressor(input_file, input_start, input_end);
|
||||
chd = new chd_rawfile_compressor(*input_file, input_start, input_end);
|
||||
chd_error err;
|
||||
if (output_parent.opened())
|
||||
err = chd->create(output_chd_str->c_str(), UINT64(totalsectors) * UINT64(sector_size), hunk_size, compression, output_parent);
|
||||
@ -1832,7 +1829,7 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
}
|
||||
|
||||
// compress it generically
|
||||
if (input_file != nullptr)
|
||||
if (input_file)
|
||||
compress_common(*chd);
|
||||
delete chd;
|
||||
}
|
||||
@ -2236,11 +2233,11 @@ static void do_extract_raw(parameters_t ¶ms)
|
||||
}
|
||||
|
||||
// catch errors so we can close & delete the output file
|
||||
core_file *output_file = nullptr;
|
||||
util::core_file::ptr output_file;
|
||||
try
|
||||
{
|
||||
// process output file
|
||||
file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
|
||||
file_error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
|
||||
|
||||
@ -2257,7 +2254,7 @@ static void do_extract_raw(parameters_t ¶ms)
|
||||
report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
|
||||
|
||||
// write to the output
|
||||
UINT32 count = core_fwrite(output_file, &buffer[0], bytes_to_read);
|
||||
UINT32 count = output_file->write(&buffer[0], bytes_to_read);
|
||||
if (count != bytes_to_read)
|
||||
report_error(1, "Error writing to file; check disk space (%s)", output_file_str->second->c_str());
|
||||
|
||||
@ -2266,7 +2263,7 @@ static void do_extract_raw(parameters_t ¶ms)
|
||||
}
|
||||
|
||||
// finish up
|
||||
core_fclose(output_file);
|
||||
output_file.reset();
|
||||
printf("Extraction complete \n");
|
||||
}
|
||||
catch (...)
|
||||
@ -2274,7 +2271,7 @@ static void do_extract_raw(parameters_t ¶ms)
|
||||
// delete the output file
|
||||
if (output_file != nullptr)
|
||||
{
|
||||
core_fclose(output_file);
|
||||
output_file.reset();
|
||||
osd_rmfile(output_file_str->second->c_str());
|
||||
}
|
||||
throw;
|
||||
@ -2329,8 +2326,8 @@ static void do_extract_cd(parameters_t ¶ms)
|
||||
printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str());
|
||||
|
||||
// catch errors so we can close & delete the output file
|
||||
core_file *output_bin_file = nullptr;
|
||||
core_file *output_toc_file = nullptr;
|
||||
util::core_file::ptr output_bin_file;
|
||||
util::core_file::ptr output_toc_file;
|
||||
try
|
||||
{
|
||||
int mode = MODE_NORMAL;
|
||||
@ -2345,14 +2342,14 @@ static void do_extract_cd(parameters_t ¶ms)
|
||||
}
|
||||
|
||||
// process output file
|
||||
file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &output_toc_file);
|
||||
file_error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, output_toc_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
|
||||
|
||||
// process output BIN file
|
||||
if (mode != MODE_GDI)
|
||||
{
|
||||
filerr = core_fopen(output_bin_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_bin_file);
|
||||
filerr = util::core_file::open(output_bin_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_bin_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Unable to open file (%s)", output_bin_file_str->c_str());
|
||||
}
|
||||
@ -2365,7 +2362,7 @@ static void do_extract_cd(parameters_t ¶ms)
|
||||
// GDI must start with the # of tracks
|
||||
if (mode == MODE_GDI)
|
||||
{
|
||||
core_fprintf(output_toc_file, "%d\n", toc->numtrks);
|
||||
output_toc_file->printf("%d\n", toc->numtrks);
|
||||
}
|
||||
|
||||
// iterate over tracks and copy all data
|
||||
@ -2386,13 +2383,9 @@ static void do_extract_cd(parameters_t ¶ms)
|
||||
else
|
||||
trackbin_name.append(".bin");
|
||||
|
||||
if (output_bin_file)
|
||||
{
|
||||
core_fclose(output_bin_file);
|
||||
output_bin_file = nullptr;
|
||||
}
|
||||
output_bin_file.reset();
|
||||
|
||||
filerr = core_fopen(trackbin_name.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_bin_file);
|
||||
filerr = util::core_file::open(trackbin_name.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_bin_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Unable to open file (%s)", trackbin_name.c_str());
|
||||
|
||||
@ -2403,11 +2396,11 @@ static void do_extract_cd(parameters_t ¶ms)
|
||||
const cdrom_track_info &trackinfo = toc->tracks[tracknum];
|
||||
if (mode == MODE_GDI)
|
||||
{
|
||||
output_track_metadata(mode, output_toc_file, tracknum, trackinfo, core_filename_extract_base(trackbin_name.c_str()).c_str(), discoffs, outputoffs);
|
||||
output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, core_filename_extract_base(trackbin_name.c_str()).c_str(), discoffs, outputoffs);
|
||||
}
|
||||
else
|
||||
{
|
||||
output_track_metadata(mode, output_toc_file, tracknum, trackinfo, core_filename_extract_base(output_bin_file_str->c_str()).c_str(), discoffs, outputoffs);
|
||||
output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, core_filename_extract_base(output_bin_file_str->c_str()).c_str(), discoffs, outputoffs);
|
||||
}
|
||||
|
||||
// If this is bin/cue output and the CHD contains subdata, warn the user and don't include
|
||||
@ -2455,8 +2448,8 @@ static void do_extract_cd(parameters_t ¶ms)
|
||||
// write it out if we need to
|
||||
if (bufferoffs == buffer.size() || frame == actualframes - 1)
|
||||
{
|
||||
core_fseek(output_bin_file, outputoffs, SEEK_SET);
|
||||
UINT32 byteswritten = core_fwrite(output_bin_file, &buffer[0], bufferoffs);
|
||||
output_bin_file->seek(outputoffs, SEEK_SET);
|
||||
UINT32 byteswritten = output_bin_file->write(&buffer[0], bufferoffs);
|
||||
if (byteswritten != bufferoffs)
|
||||
report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->second->c_str(), chd_file::error_string(CHDERR_WRITE_ERROR));
|
||||
outputoffs += bufferoffs;
|
||||
@ -2468,17 +2461,15 @@ static void do_extract_cd(parameters_t ¶ms)
|
||||
}
|
||||
|
||||
// finish up
|
||||
core_fclose(output_bin_file);
|
||||
core_fclose(output_toc_file);
|
||||
output_bin_file.reset();
|
||||
output_toc_file.reset();
|
||||
printf("Extraction complete \n");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// delete the output files
|
||||
if (output_bin_file != nullptr)
|
||||
core_fclose(output_bin_file);
|
||||
if (output_toc_file != nullptr)
|
||||
core_fclose(output_toc_file);
|
||||
output_bin_file.reset();
|
||||
output_toc_file.reset();
|
||||
osd_rmfile(output_bin_file_str->c_str());
|
||||
osd_rmfile(output_file_str->second->c_str());
|
||||
throw;
|
||||
@ -2600,7 +2591,7 @@ static void do_extract_ld(parameters_t ¶ms)
|
||||
chd_error err = input_chd.read_hunk(framenum, nullptr);
|
||||
if (err != CHDERR_NONE)
|
||||
{
|
||||
UINT64 filepos = core_ftell(input_chd);
|
||||
UINT64 filepos = static_cast<util::core_file &>(input_chd).tell();
|
||||
report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
|
||||
}
|
||||
|
||||
@ -2678,7 +2669,7 @@ static void do_add_metadata(parameters_t ¶ms)
|
||||
dynamic_buffer file;
|
||||
if (file_str != params.end())
|
||||
{
|
||||
file_error filerr = core_fload(file_str->second->c_str(), file);
|
||||
file_error filerr = util::core_file::load(file_str->second->c_str(), file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Error reading metadata file (%s)", file_str->second->c_str());
|
||||
}
|
||||
@ -2796,21 +2787,21 @@ static void do_dump_metadata(parameters_t ¶ms)
|
||||
report_error(1, "Error reading metadata: %s", chd_file::error_string(err));
|
||||
|
||||
// catch errors so we can close & delete the output file
|
||||
core_file *output_file = nullptr;
|
||||
util::core_file::ptr output_file;
|
||||
try
|
||||
{
|
||||
// create the file
|
||||
if (output_file_str != params.end())
|
||||
{
|
||||
file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
|
||||
file_error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_file);
|
||||
if (filerr != FILERR_NONE)
|
||||
report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
|
||||
|
||||
// output the metadata
|
||||
UINT32 count = core_fwrite(output_file, &buffer[0], buffer.size());
|
||||
UINT32 count = output_file->write(&buffer[0], buffer.size());
|
||||
if (count != buffer.size())
|
||||
report_error(1, "Error writing file (%s)", output_file_str->second->c_str());
|
||||
core_fclose(output_file);
|
||||
output_file.reset();
|
||||
|
||||
// provide some feedback
|
||||
std::string tempstr;
|
||||
@ -2827,8 +2818,7 @@ static void do_dump_metadata(parameters_t ¶ms)
|
||||
catch (...)
|
||||
{
|
||||
// delete the output file
|
||||
if (output_file != nullptr)
|
||||
core_fclose(output_file);
|
||||
output_file.reset();
|
||||
osd_rmfile(output_file_str->second->c_str());
|
||||
throw;
|
||||
}
|
||||
|
@ -24,78 +24,112 @@ enum imgtype_t
|
||||
|
||||
struct imgtool_stream
|
||||
{
|
||||
imgtype_t imgtype;
|
||||
int write_protect;
|
||||
const char *name; // needed for clear
|
||||
UINT64 position;
|
||||
UINT64 filesize;
|
||||
typedef std::unique_ptr<imgtool_stream> ptr;
|
||||
|
||||
union
|
||||
imgtool_stream(bool wp)
|
||||
: imgtype(IMG_FILE)
|
||||
, write_protect(wp)
|
||||
, name(nullptr)
|
||||
, position(0)
|
||||
, filesize(0)
|
||||
, file()
|
||||
, buffer(nullptr)
|
||||
{
|
||||
core_file *file;
|
||||
UINT8 *buffer;
|
||||
} u;
|
||||
}
|
||||
|
||||
imgtool_stream(
|
||||
bool wp,
|
||||
util::core_file::ptr &&f)
|
||||
: imgtype(IMG_FILE)
|
||||
, write_protect(wp)
|
||||
, name(nullptr)
|
||||
, position(0)
|
||||
, filesize(f->size())
|
||||
, file(std::move(f))
|
||||
, buffer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
imgtool_stream(bool wp, std::size_t size)
|
||||
: imgtype(IMG_MEM)
|
||||
, write_protect(wp)
|
||||
, name(nullptr)
|
||||
, position(0)
|
||||
, filesize(size)
|
||||
, file()
|
||||
, buffer(reinterpret_cast<std::uint8_t *>(malloc(size)))
|
||||
{
|
||||
}
|
||||
|
||||
imgtool_stream(bool wp, std::size_t size, void *buf)
|
||||
: imgtype(IMG_MEM)
|
||||
, write_protect(wp)
|
||||
, name(nullptr)
|
||||
, position(0)
|
||||
, filesize(size)
|
||||
, file()
|
||||
, buffer(reinterpret_cast<std::uint8_t *>(buf))
|
||||
{
|
||||
}
|
||||
|
||||
~imgtool_stream()
|
||||
{
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
imgtype_t imgtype;
|
||||
bool write_protect;
|
||||
const char *name; // needed for clear
|
||||
std::uint64_t position;
|
||||
std::uint64_t filesize;
|
||||
|
||||
util::core_file::ptr file;
|
||||
std::uint8_t *buffer;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static imgtool_stream *stream_open_zip(const char *zipname, const char *subname, int read_or_write)
|
||||
{
|
||||
imgtool_stream *imgfile = nullptr;
|
||||
// zip_error ziperr;
|
||||
zip_file *z = nullptr;
|
||||
const zip_file_header *zipent;
|
||||
FILE *f;
|
||||
|
||||
if (read_or_write)
|
||||
goto error;
|
||||
return nullptr;
|
||||
|
||||
/* check to see if the file exists */
|
||||
f = fopen(zipname, "r");
|
||||
FILE *f = fopen(zipname, "r");
|
||||
if (!f)
|
||||
goto error;
|
||||
return nullptr;
|
||||
fclose(f);
|
||||
|
||||
imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
|
||||
if (!imgfile)
|
||||
goto error;
|
||||
imgtool_stream::ptr imgfile(new imgtool_stream(true));
|
||||
|
||||
memset(imgfile, 0, sizeof(*imgfile));
|
||||
imgfile->imgtype = IMG_MEM;
|
||||
imgfile->write_protect = 1;
|
||||
imgfile->position = 0;
|
||||
|
||||
// ziperr =
|
||||
zip_file *z = nullptr;
|
||||
const zip_file_header *zipent = nullptr;
|
||||
zip_file_open(zipname, &z);
|
||||
if (!z)
|
||||
goto error;
|
||||
|
||||
zipent = zip_file_first_file(z);
|
||||
while(zipent && subname && strcmp(subname, zipent->filename))
|
||||
while (zipent && subname && strcmp(subname, zipent->filename))
|
||||
zipent = zip_file_next_file(z);
|
||||
if (!zipent)
|
||||
goto error;
|
||||
|
||||
imgfile->filesize = zipent->uncompressed_length;
|
||||
imgfile->u.buffer = (UINT8*)malloc(zipent->uncompressed_length);
|
||||
if (!imgfile->u.buffer)
|
||||
imgfile->buffer = reinterpret_cast<std::uint8_t *>(malloc(zipent->uncompressed_length));
|
||||
if (!imgfile->buffer)
|
||||
goto error;
|
||||
|
||||
if (zip_file_decompress(z, imgfile->u.buffer, zipent->uncompressed_length))
|
||||
if (zip_file_decompress(z, imgfile->buffer, zipent->uncompressed_length))
|
||||
goto error;
|
||||
|
||||
zip_file_close(z);
|
||||
return imgfile;
|
||||
return imgfile.release();
|
||||
|
||||
error:
|
||||
if (z)
|
||||
zip_file_close(z);
|
||||
if (imgfile)
|
||||
{
|
||||
if (imgfile->u.buffer)
|
||||
free(imgfile->u.buffer);
|
||||
free(imgfile);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -103,9 +137,6 @@ error:
|
||||
|
||||
imgtool_stream *stream_open(const char *fname, int read_or_write)
|
||||
{
|
||||
file_error filerr;
|
||||
const char *ext;
|
||||
imgtool_stream *imgfile = nullptr;
|
||||
static const UINT32 write_modes[] =
|
||||
{
|
||||
OPEN_FLAG_READ,
|
||||
@ -113,118 +144,70 @@ imgtool_stream *stream_open(const char *fname, int read_or_write)
|
||||
OPEN_FLAG_READ | OPEN_FLAG_WRITE,
|
||||
OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE
|
||||
};
|
||||
core_file *f = nullptr;
|
||||
char *buf = nullptr;
|
||||
int len, i;
|
||||
imgtool_stream *s = nullptr;
|
||||
char c;
|
||||
|
||||
/* maybe we are just a ZIP? */
|
||||
ext = strrchr(fname, '.');
|
||||
const char *ext = strrchr(fname, '.');
|
||||
if (ext && !core_stricmp(ext, ".zip"))
|
||||
return stream_open_zip(fname, nullptr, read_or_write);
|
||||
|
||||
filerr = core_fopen(fname, write_modes[read_or_write], &f);
|
||||
util::core_file::ptr f = nullptr;
|
||||
auto const filerr = util::core_file::open(fname, write_modes[read_or_write], f);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
if (!read_or_write)
|
||||
{
|
||||
len = strlen(fname);
|
||||
int const len = strlen(fname);
|
||||
|
||||
/* can't open the file; try opening ZIP files with other names */
|
||||
buf = (char*)malloc(len + 1);
|
||||
if (!buf)
|
||||
goto error;
|
||||
strcpy(buf, fname);
|
||||
std::vector<char> buf(len + 1);
|
||||
strcpy(&buf[0], fname);
|
||||
|
||||
for(i = len-1; !s && (i >= 0); i--)
|
||||
for (int i = len-1; !s && (i >= 0); i--)
|
||||
{
|
||||
if ((buf[i] == '\\') || (buf[i] == '/'))
|
||||
{
|
||||
c = buf[i];
|
||||
buf[i] = '\0';
|
||||
s = stream_open_zip(buf, buf + i + 1, read_or_write);
|
||||
s = stream_open_zip(&buf[0], &buf[i + 1], read_or_write);
|
||||
buf[i] = c;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
buf = nullptr;
|
||||
|
||||
if (s)
|
||||
return s;
|
||||
}
|
||||
|
||||
/* ah well, it was worth a shot */
|
||||
goto error;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
|
||||
if (!imgfile)
|
||||
goto error;
|
||||
imgtool_stream::ptr imgfile(new imgtool_stream(read_or_write ? false : true, std::move(f)));
|
||||
|
||||
/* Normal file */
|
||||
memset(imgfile, 0, sizeof(*imgfile));
|
||||
imgfile->imgtype = IMG_FILE;
|
||||
imgfile->position = 0;
|
||||
imgfile->filesize = core_fsize(f);
|
||||
imgfile->write_protect = read_or_write ? 0 : 1;
|
||||
imgfile->u.file = f;
|
||||
imgfile->name = fname;
|
||||
return imgfile;
|
||||
|
||||
error:
|
||||
if (imgfile != nullptr)
|
||||
free((void *) imgfile);
|
||||
if (f != nullptr)
|
||||
core_fclose(f);
|
||||
if (buf)
|
||||
free(buf);
|
||||
return (imgtool_stream *) nullptr;
|
||||
return imgfile.release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
imgtool_stream *stream_open_write_stream(int size)
|
||||
{
|
||||
imgtool_stream *imgfile;
|
||||
|
||||
imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
|
||||
if (!imgfile)
|
||||
imgtool_stream::ptr imgfile(new imgtool_stream(false, size));
|
||||
if (!imgfile->buffer)
|
||||
return nullptr;
|
||||
|
||||
imgfile->imgtype = IMG_MEM;
|
||||
imgfile->write_protect = 0;
|
||||
imgfile->position = 0;
|
||||
imgfile->filesize = size;
|
||||
imgfile->u.buffer = (UINT8*)malloc(size);
|
||||
|
||||
if (!imgfile->u.buffer)
|
||||
{
|
||||
free(imgfile);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return imgfile;
|
||||
return imgfile.release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
imgtool_stream *stream_open_mem(void *buf, size_t sz)
|
||||
{
|
||||
imgtool_stream *imgfile;
|
||||
imgtool_stream::ptr imgfile(new imgtool_stream(false, sz, buf));
|
||||
|
||||
imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
|
||||
if (!imgfile)
|
||||
return nullptr;
|
||||
|
||||
memset(imgfile, 0, sizeof(*imgfile));
|
||||
imgfile->imgtype = IMG_MEM;
|
||||
imgfile->position = 0;
|
||||
imgfile->write_protect = 0;
|
||||
|
||||
imgfile->filesize = sz;
|
||||
imgfile->u.buffer = (UINT8*)buf;
|
||||
return imgfile;
|
||||
return imgfile.release();
|
||||
}
|
||||
|
||||
|
||||
@ -233,36 +216,14 @@ void stream_close(imgtool_stream *s)
|
||||
{
|
||||
assert(s != nullptr);
|
||||
|
||||
switch(s->imgtype)
|
||||
{
|
||||
case IMG_FILE:
|
||||
if (s->u.file != nullptr)
|
||||
{
|
||||
core_fclose(s->u.file);
|
||||
s->u.file = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case IMG_MEM:
|
||||
if (s->u.buffer != nullptr)
|
||||
{
|
||||
free(s->u.buffer);
|
||||
s->u.buffer = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
free((void *) s);
|
||||
delete s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
core_file *stream_core_file(imgtool_stream *stream)
|
||||
util::core_file *stream_core_file(imgtool_stream *stream)
|
||||
{
|
||||
return (stream->imgtype == IMG_FILE) ? stream->u.file : nullptr;
|
||||
return (stream->imgtype == IMG_FILE) ? stream->file.get() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -275,8 +236,8 @@ UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz)
|
||||
{
|
||||
case IMG_FILE:
|
||||
assert(sz == (UINT32) sz);
|
||||
core_fseek(stream->u.file, stream->position, SEEK_SET);
|
||||
result = core_fread(stream->u.file, buf, (UINT32) sz);
|
||||
stream->file->seek(stream->position, SEEK_SET);
|
||||
result = stream->file->read(buf, (UINT32) sz);
|
||||
break;
|
||||
|
||||
case IMG_MEM:
|
||||
@ -284,7 +245,7 @@ UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz)
|
||||
if (sz > (stream->filesize - stream->position))
|
||||
sz = (UINT32) (stream->filesize - stream->position);
|
||||
|
||||
memcpy(buf, stream->u.buffer + stream->position, sz);
|
||||
memcpy(buf, stream->buffer + stream->position, sz);
|
||||
result = sz;
|
||||
break;
|
||||
|
||||
@ -312,11 +273,11 @@ UINT32 stream_write(imgtool_stream *s, const void *buf, UINT32 sz)
|
||||
if (s->filesize < s->position + sz)
|
||||
{
|
||||
/* try to expand the buffer */
|
||||
if (s->u.buffer) free(s->u.buffer);
|
||||
if (s->buffer) free(s->buffer);
|
||||
new_buffer = malloc(s->position + sz);
|
||||
if (new_buffer)
|
||||
{
|
||||
s->u.buffer = (UINT8*)new_buffer;
|
||||
s->buffer = (UINT8*)new_buffer;
|
||||
s->filesize = s->position + sz;
|
||||
}
|
||||
}
|
||||
@ -325,14 +286,14 @@ UINT32 stream_write(imgtool_stream *s, const void *buf, UINT32 sz)
|
||||
if (sz > (s->filesize - s->position))
|
||||
sz = (UINT32) (s->filesize - s->position);
|
||||
|
||||
memcpy(s->u.buffer + s->position, buf, sz);
|
||||
memcpy(s->buffer + s->position, buf, sz);
|
||||
result = sz;
|
||||
}
|
||||
break;
|
||||
|
||||
case IMG_FILE:
|
||||
core_fseek(s->u.file, s->position, SEEK_SET);
|
||||
result = core_fwrite(s->u.file, buf, sz);
|
||||
s->file->seek(s->position, SEEK_SET);
|
||||
result = s->file->write(buf, sz);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -365,7 +326,7 @@ void *stream_getptr(imgtool_stream *f)
|
||||
switch(f->imgtype)
|
||||
{
|
||||
case IMG_MEM:
|
||||
ptr = f->u.buffer;
|
||||
ptr = f->buffer;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -445,7 +406,7 @@ int stream_crc(imgtool_stream *s, unsigned long *result)
|
||||
switch(s->imgtype)
|
||||
{
|
||||
case IMG_MEM:
|
||||
*result = crc32(0, (unsigned char *) s->u.buffer, (size_t) s->filesize);
|
||||
*result = crc32(0, (unsigned char *) s->buffer, (size_t) s->filesize);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -20,7 +20,7 @@ imgtool_stream *stream_open(const char *fname, int read_or_write); /* similar p
|
||||
imgtool_stream *stream_open_write_stream(int filesize);
|
||||
imgtool_stream *stream_open_mem(void *buf, size_t sz);
|
||||
void stream_close(imgtool_stream *stream);
|
||||
core_file *stream_core_file(imgtool_stream *stream);
|
||||
util::core_file *stream_core_file(imgtool_stream *stream);
|
||||
UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz);
|
||||
UINT32 stream_write(imgtool_stream *stream, const void *buf, UINT32 sz);
|
||||
UINT64 stream_size(imgtool_stream *stream);
|
||||
|
@ -554,7 +554,7 @@ int main(int argc, char *argv[])
|
||||
// open the destination file
|
||||
chd_resample_compressor dstfile(srcfile, info, INT64(offset * 65536.0 * 256.0), INT64(slope * 65536.0 * 256.0));
|
||||
err = create_chd(dstfile, dstfilename, srcfile, info);
|
||||
if (dstfile == nullptr)
|
||||
if (!dstfile.opened())
|
||||
{
|
||||
fprintf(stderr, "Unable to create file '%s'\n", dstfilename);
|
||||
return 1;
|
||||
|
@ -72,7 +72,7 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
|
||||
bitmap_argb32 bitmap2;
|
||||
bitmap_argb32 finalbitmap;
|
||||
int width, height, maxwidth;
|
||||
core_file *file = nullptr;
|
||||
util::core_file::ptr file;
|
||||
file_error filerr;
|
||||
png_error pngerr;
|
||||
int error = 100;
|
||||
@ -80,7 +80,7 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
|
||||
int x, y;
|
||||
|
||||
/* open the source image */
|
||||
filerr = core_fopen(imgfile1.c_str(), OPEN_FLAG_READ, &file);
|
||||
filerr = util::core_file::open(imgfile1.c_str(), OPEN_FLAG_READ, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
printf("Could not open %s (%d)\n", imgfile1.c_str(), filerr);
|
||||
@ -88,8 +88,8 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
|
||||
}
|
||||
|
||||
/* load the source image */
|
||||
pngerr = png_read_bitmap(file, bitmap1);
|
||||
core_fclose(file);
|
||||
pngerr = png_read_bitmap(*file, bitmap1);
|
||||
file.reset();
|
||||
if (pngerr != PNGERR_NONE)
|
||||
{
|
||||
printf("Could not read %s (%d)\n", imgfile1.c_str(), pngerr);
|
||||
@ -97,7 +97,7 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
|
||||
}
|
||||
|
||||
/* open the source image */
|
||||
filerr = core_fopen(imgfile2.c_str(), OPEN_FLAG_READ, &file);
|
||||
filerr = util::core_file::open(imgfile2.c_str(), OPEN_FLAG_READ, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
printf("Could not open %s (%d)\n", imgfile2.c_str(), filerr);
|
||||
@ -105,8 +105,8 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
|
||||
}
|
||||
|
||||
/* load the source image */
|
||||
pngerr = png_read_bitmap(file, bitmap2);
|
||||
core_fclose(file);
|
||||
pngerr = png_read_bitmap(*file, bitmap2);
|
||||
file.reset();
|
||||
if (pngerr != PNGERR_NONE)
|
||||
{
|
||||
printf("Could not read %s (%d)\n", imgfile2.c_str(), pngerr);
|
||||
@ -170,14 +170,14 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
|
||||
}
|
||||
|
||||
/* write the final PNG */
|
||||
filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
|
||||
filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
printf("Could not open %s (%d)\n", outfilename.c_str(), filerr);
|
||||
goto error;
|
||||
}
|
||||
pngerr = png_write_bitmap(file, nullptr, finalbitmap, 0, nullptr);
|
||||
core_fclose(file);
|
||||
pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr);
|
||||
file.reset();
|
||||
if (pngerr != PNGERR_NONE)
|
||||
{
|
||||
printf("Could not write %s (%d)\n", outfilename.c_str(), pngerr);
|
||||
|
@ -148,15 +148,15 @@ static int CLIB_DECL compare_file(const void *file0ptr, const void *file1ptr);
|
||||
static summary_file *sort_file_list(void);
|
||||
|
||||
/* HTML helpers */
|
||||
static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title);
|
||||
static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &title);
|
||||
static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title);
|
||||
static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &title);
|
||||
|
||||
/* report generators */
|
||||
static void output_report(std::string &dirname, std::string &tempheader, std::string &tempfooter, summary_file *filelist);
|
||||
static int compare_screenshots(summary_file *curfile);
|
||||
static int generate_png_diff(const summary_file *curfile, std::string &destdir, const char *destname);
|
||||
static void create_linked_file(std::string &dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile, std::string &tempheader, std::string &tempfooter);
|
||||
static void append_driver_list_table(const char *header, std::string &dirname, core_file *indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter);
|
||||
static void append_driver_list_table(const char *header, std::string &dirname, util::core_file &indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter);
|
||||
|
||||
|
||||
|
||||
@ -235,7 +235,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* read the template file into an astring */
|
||||
std::string tempheader;
|
||||
if (core_fload(tempfilename.c_str(), &buffer, &bufsize) == FILERR_NONE)
|
||||
if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == FILERR_NONE)
|
||||
{
|
||||
tempheader.assign((const char *)buffer, bufsize);
|
||||
osd_free(buffer);
|
||||
@ -560,18 +560,18 @@ static summary_file *sort_file_list(void)
|
||||
HTML file with a standard header
|
||||
-------------------------------------------------*/
|
||||
|
||||
static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title)
|
||||
static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title)
|
||||
{
|
||||
core_file *file;
|
||||
util::core_file::ptr file;
|
||||
|
||||
/* create the indexfile */
|
||||
if (core_fopen(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE)
|
||||
return nullptr;
|
||||
if (util::core_file::open(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file) != FILERR_NONE)
|
||||
return util::core_file::ptr();
|
||||
|
||||
/* print a header */
|
||||
std::string modified(templatefile);
|
||||
strreplace(modified, "<!--TITLE-->", title.c_str());
|
||||
core_fwrite(file, modified.c_str(), modified.length());
|
||||
file->write(modified.c_str(), modified.length());
|
||||
|
||||
/* return the file */
|
||||
return file;
|
||||
@ -583,12 +583,12 @@ static core_file *create_file_and_output_header(std::string &filename, std::stri
|
||||
standard footer to an HTML file and close it
|
||||
-------------------------------------------------*/
|
||||
|
||||
static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &title)
|
||||
static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &title)
|
||||
{
|
||||
std::string modified(templatefile);
|
||||
strreplace(modified, "<!--TITLE-->", title.c_str());
|
||||
core_fwrite(file, modified.c_str(), modified.length());
|
||||
core_fclose(file);
|
||||
file->write(modified.c_str(), modified.length());
|
||||
file.reset();
|
||||
}
|
||||
|
||||
|
||||
@ -609,7 +609,7 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st
|
||||
std::string title("MAME Regressions");
|
||||
std::string tempname;
|
||||
int listnum, bucknum;
|
||||
core_file *indexfile;
|
||||
util::core_file::ptr indexfile;
|
||||
int count = 0, total;
|
||||
|
||||
/* initialize the lists */
|
||||
@ -688,7 +688,7 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st
|
||||
/* output header */
|
||||
tempname = string_format("%s" PATH_SEPARATOR "%s", dirname.c_str(), "index.html");
|
||||
indexfile = create_file_and_output_header(tempname, tempheader, title);
|
||||
if (indexfile == nullptr)
|
||||
if (!indexfile)
|
||||
{
|
||||
fprintf(stderr, "Error creating file '%s'\n", tempname.c_str());
|
||||
return;
|
||||
@ -702,12 +702,12 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st
|
||||
if (buckethead[curbucket] != nullptr)
|
||||
{
|
||||
fprintf(stderr, "Outputting bucket: %s\n", bucket_name[curbucket]);
|
||||
append_driver_list_table(bucket_name[curbucket], dirname, indexfile, buckethead[curbucket], tempheader, tempfooter);
|
||||
append_driver_list_table(bucket_name[curbucket], dirname, *indexfile, buckethead[curbucket], tempheader, tempfooter);
|
||||
}
|
||||
}
|
||||
|
||||
/* output footer */
|
||||
output_footer_and_close_file(indexfile, tempfooter, title);
|
||||
output_footer_and_close_file(std::move(indexfile), tempfooter, title);
|
||||
}
|
||||
|
||||
|
||||
@ -729,13 +729,13 @@ static int compare_screenshots(summary_file *curfile)
|
||||
{
|
||||
std::string fullname;
|
||||
file_error filerr;
|
||||
core_file *file;
|
||||
util::core_file::ptr file;
|
||||
|
||||
/* get the filename for the image */
|
||||
fullname = string_format("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", lists[listnum].dir, curfile->name);
|
||||
|
||||
/* open the file */
|
||||
filerr = core_fopen(fullname.c_str(), OPEN_FLAG_READ, &file);
|
||||
filerr = util::core_file::open(fullname.c_str(), OPEN_FLAG_READ, file);
|
||||
|
||||
/* if that failed, look in the old location */
|
||||
if (filerr != FILERR_NONE)
|
||||
@ -744,14 +744,14 @@ static int compare_screenshots(summary_file *curfile)
|
||||
fullname = string_format("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "_%s.png", lists[listnum].dir, curfile->name);
|
||||
|
||||
/* open the file */
|
||||
filerr = core_fopen(fullname.c_str(), OPEN_FLAG_READ, &file);
|
||||
filerr = util::core_file::open(fullname.c_str(), OPEN_FLAG_READ, file);
|
||||
}
|
||||
|
||||
/* if that worked, load the file */
|
||||
if (filerr == FILERR_NONE)
|
||||
{
|
||||
png_read_bitmap(file, bitmaps[listnum]);
|
||||
core_fclose(file);
|
||||
png_read_bitmap(*file, bitmaps[listnum]);
|
||||
file.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -836,7 +836,7 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir,
|
||||
int width, height, maxwidth;
|
||||
int bitmapcount = 0;
|
||||
int listnum, bmnum;
|
||||
core_file *file = nullptr;
|
||||
util::core_file::ptr file;
|
||||
file_error filerr;
|
||||
png_error pngerr;
|
||||
int error = -1;
|
||||
@ -853,13 +853,13 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir,
|
||||
tempname = string_format("%s" PATH_SEPARATOR "%s", lists[listnum].dir, srcimgname.c_str());
|
||||
|
||||
/* open the source image */
|
||||
filerr = core_fopen(tempname.c_str(), OPEN_FLAG_READ, &file);
|
||||
filerr = util::core_file::open(tempname.c_str(), OPEN_FLAG_READ, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
goto error;
|
||||
|
||||
/* load the source image */
|
||||
pngerr = png_read_bitmap(file, bitmaps[bitmapcount++]);
|
||||
core_fclose(file);
|
||||
pngerr = png_read_bitmap(*file, bitmaps[bitmapcount++]);
|
||||
file.reset();
|
||||
if (pngerr != PNGERR_NONE)
|
||||
goto error;
|
||||
}
|
||||
@ -925,11 +925,11 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir,
|
||||
}
|
||||
|
||||
/* write the final PNG */
|
||||
filerr = core_fopen(dstfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
|
||||
filerr = util::core_file::open(dstfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file);
|
||||
if (filerr != FILERR_NONE)
|
||||
goto error;
|
||||
pngerr = png_write_bitmap(file, nullptr, finalbitmap, 0, nullptr);
|
||||
core_fclose(file);
|
||||
pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr);
|
||||
file.reset();
|
||||
if (pngerr != PNGERR_NONE)
|
||||
goto error;
|
||||
|
||||
@ -953,7 +953,7 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
|
||||
std::string linkname;
|
||||
std::string filename;
|
||||
std::string title;
|
||||
core_file *linkfile;
|
||||
util::core_file::ptr linkfile;
|
||||
int listnum;
|
||||
|
||||
/* create the filename */
|
||||
@ -970,19 +970,19 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
|
||||
}
|
||||
|
||||
/* link to the previous/next entries */
|
||||
core_fprintf(linkfile, "\t<p>\n");
|
||||
core_fprintf(linkfile, "\t<table width=\"100%%\">\n");
|
||||
core_fprintf(linkfile, "\t\t<td align=\"left\" width=\"40%%\" style=\"border:none\">");
|
||||
linkfile->printf("\t<p>\n");
|
||||
linkfile->printf("\t<table width=\"100%%\">\n");
|
||||
linkfile->printf("\t\t<td align=\"left\" width=\"40%%\" style=\"border:none\">");
|
||||
if (prevfile != nullptr)
|
||||
core_fprintf(linkfile, "<a href=\"%s.html\"><< %s (%s)</a>", prevfile->name, prevfile->name, prevfile->source);
|
||||
core_fprintf(linkfile, "</td>\n");
|
||||
core_fprintf(linkfile, "\t\t<td align=\"center\" width=\"20%%\" style=\"border:none\"><a href=\"index.html\">Home</a></td>\n");
|
||||
core_fprintf(linkfile, "\t\t<td align=\"right\" width=\"40%%\" style=\"border:none\">");
|
||||
linkfile->printf("<a href=\"%s.html\"><< %s (%s)</a>", prevfile->name, prevfile->name, prevfile->source);
|
||||
linkfile->printf("</td>\n");
|
||||
linkfile->printf("\t\t<td align=\"center\" width=\"20%%\" style=\"border:none\"><a href=\"index.html\">Home</a></td>\n");
|
||||
linkfile->printf("\t\t<td align=\"right\" width=\"40%%\" style=\"border:none\">");
|
||||
if (nextfile != nullptr)
|
||||
core_fprintf(linkfile, "<a href=\"%s.html\">%s (%s) >></a>", nextfile->name, nextfile->name, nextfile->source);
|
||||
core_fprintf(linkfile, "</td>\n");
|
||||
core_fprintf(linkfile, "\t</table>\n");
|
||||
core_fprintf(linkfile, "\t</p>\n");
|
||||
linkfile->printf("<a href=\"%s.html\">%s (%s) >></a>", nextfile->name, nextfile->name, nextfile->source);
|
||||
linkfile->printf("</td>\n");
|
||||
linkfile->printf("\t</table>\n");
|
||||
linkfile->printf("\t</p>\n");
|
||||
|
||||
/* output data for each one */
|
||||
for (listnum = 0; listnum < list_count; listnum++)
|
||||
@ -990,34 +990,34 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
|
||||
int imageindex = -1;
|
||||
|
||||
/* generate the HTML */
|
||||
core_fprintf(linkfile, "\n\t<h2>%s</h2>\n", lists[listnum].version);
|
||||
core_fprintf(linkfile, "\t<p>\n");
|
||||
core_fprintf(linkfile, "\t<b>Status:</b> %s\n", status_text[curfile->status[listnum]]);
|
||||
linkfile->printf("\n\t<h2>%s</h2>\n", lists[listnum].version);
|
||||
linkfile->printf("\t<p>\n");
|
||||
linkfile->printf("\t<b>Status:</b> %s\n", status_text[curfile->status[listnum]]);
|
||||
if (pngfile != nullptr)
|
||||
imageindex = get_unique_index(curfile, listnum);
|
||||
if (imageindex != -1)
|
||||
core_fprintf(linkfile, " [%d]", imageindex);
|
||||
core_fprintf(linkfile, "\t</p>\n");
|
||||
linkfile->printf(" [%d]", imageindex);
|
||||
linkfile->printf("\t</p>\n");
|
||||
if (curfile->text[listnum].length() != 0)
|
||||
{
|
||||
core_fprintf(linkfile, "\t<p>\n");
|
||||
core_fprintf(linkfile, "\t<b>Errors:</b>\n");
|
||||
core_fprintf(linkfile, "\t<pre>%s</pre>\n", curfile->text[listnum].c_str());
|
||||
core_fprintf(linkfile, "\t</p>\n");
|
||||
linkfile->printf("\t<p>\n");
|
||||
linkfile->printf("\t<b>Errors:</b>\n");
|
||||
linkfile->printf("\t<pre>%s</pre>\n", curfile->text[listnum].c_str());
|
||||
linkfile->printf("\t</p>\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* output link to the image */
|
||||
if (pngfile != nullptr)
|
||||
{
|
||||
core_fprintf(linkfile, "\n\t<h2>Screenshot Comparisons</h2>\n");
|
||||
core_fprintf(linkfile, "\t<p>\n");
|
||||
core_fprintf(linkfile, "\t<img src=\"%s\" />\n", pngfile);
|
||||
core_fprintf(linkfile, "\t</p>\n");
|
||||
linkfile->printf("\n\t<h2>Screenshot Comparisons</h2>\n");
|
||||
linkfile->printf("\t<p>\n");
|
||||
linkfile->printf("\t<img src=\"%s\" />\n", pngfile);
|
||||
linkfile->printf("\t</p>\n");
|
||||
}
|
||||
|
||||
/* output footer */
|
||||
output_footer_and_close_file(linkfile, tempfooter, title);
|
||||
output_footer_and_close_file(std::move(linkfile), tempfooter, title);
|
||||
}
|
||||
|
||||
|
||||
@ -1026,28 +1026,28 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
|
||||
of drivers from a list to an HTML file
|
||||
-------------------------------------------------*/
|
||||
|
||||
static void append_driver_list_table(const char *header, std::string &dirname, core_file *indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter)
|
||||
static void append_driver_list_table(const char *header, std::string &dirname, util::core_file &indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter)
|
||||
{
|
||||
const summary_file *curfile, *prevfile;
|
||||
int width = 100 / (2 + list_count);
|
||||
int listnum;
|
||||
|
||||
/* output a header */
|
||||
core_fprintf(indexfile, "\t<h2>%s</h2>\n", header);
|
||||
indexfile.printf("\t<h2>%s</h2>\n", header);
|
||||
|
||||
/* start the table */
|
||||
core_fprintf(indexfile, "\t<p><table width=\"90%%\">\n");
|
||||
core_fprintf(indexfile, "\t\t<tr>\n\t\t\t<th width=\"%d%%\">Source</th><th width=\"%d%%\">Driver</th>", width, width);
|
||||
indexfile.printf("\t<p><table width=\"90%%\">\n");
|
||||
indexfile.printf("\t\t<tr>\n\t\t\t<th width=\"%d%%\">Source</th><th width=\"%d%%\">Driver</th>", width, width);
|
||||
for (listnum = 0; listnum < list_count; listnum++)
|
||||
core_fprintf(indexfile, "<th width=\"%d%%\">%s</th>", width, lists[listnum].version);
|
||||
core_fprintf(indexfile, "\n\t\t</tr>\n");
|
||||
indexfile.printf("<th width=\"%d%%\">%s</th>", width, lists[listnum].version);
|
||||
indexfile.printf("\n\t\t</tr>\n");
|
||||
|
||||
/* if nothing, print a default message */
|
||||
if (listhead == nullptr)
|
||||
{
|
||||
core_fprintf(indexfile, "\t\t<tr>\n\t\t\t");
|
||||
core_fprintf(indexfile, "<td colspan=\"%d\" align=\"center\">(No regressions detected)</td>", list_count + 2);
|
||||
core_fprintf(indexfile, "\n\t\t</tr>\n");
|
||||
indexfile.printf("\t\t<tr>\n\t\t\t");
|
||||
indexfile.printf("<td colspan=\"%d\" align=\"center\">(No regressions detected)</td>", list_count + 2);
|
||||
indexfile.printf("\n\t\t</tr>\n");
|
||||
}
|
||||
|
||||
/* iterate over files */
|
||||
@ -1083,10 +1083,10 @@ static void append_driver_list_table(const char *header, std::string &dirname, c
|
||||
create_linked_file(dirname, curfile, prevfile, curfile->next, (pngdiffname[0] == 0) ? nullptr : pngdiffname, tempheader, tempfooter);
|
||||
|
||||
/* create a row */
|
||||
core_fprintf(indexfile, "\t\t<tr>\n\t\t\t");
|
||||
indexfile.printf("\t\t<tr>\n\t\t\t");
|
||||
if (rowspan > 0)
|
||||
core_fprintf(indexfile, "<td rowspan=\"%d\">%s</td>", rowspan, curfile->source);
|
||||
core_fprintf(indexfile, "<td><a href=\"%s.html\">%s</a></td>", curfile->name, curfile->name);
|
||||
indexfile.printf("<td rowspan=\"%d\">%s</td>", rowspan, curfile->source);
|
||||
indexfile.printf("<td><a href=\"%s.html\">%s</a></td>", curfile->name, curfile->name);
|
||||
for (listnum = 0; listnum < list_count; listnum++)
|
||||
{
|
||||
int unique_index = -1;
|
||||
@ -1094,16 +1094,16 @@ static void append_driver_list_table(const char *header, std::string &dirname, c
|
||||
if (pngdiffname[0] != 0)
|
||||
unique_index = get_unique_index(curfile, listnum);
|
||||
if (unique_index != -1)
|
||||
core_fprintf(indexfile, "<td><span style=\"%s\"> </span> %s [<a href=\"%s\" target=\"blank\">%d</a>]</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]], pngdiffname, unique_index);
|
||||
indexfile.printf("<td><span style=\"%s\"> </span> %s [<a href=\"%s\" target=\"blank\">%d</a>]</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]], pngdiffname, unique_index);
|
||||
else
|
||||
core_fprintf(indexfile, "<td><span style=\"%s\"> </span> %s</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]]);
|
||||
indexfile.printf("<td><span style=\"%s\"> </span> %s</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]]);
|
||||
}
|
||||
core_fprintf(indexfile, "\n\t\t</tr>\n");
|
||||
indexfile.printf("\n\t\t</tr>\n");
|
||||
|
||||
/* also print the name and source file */
|
||||
printf("%s %s\n", curfile->name, curfile->source);
|
||||
}
|
||||
|
||||
/* end of table */
|
||||
core_fprintf(indexfile, "</table></p>\n");
|
||||
indexfile.printf("</table></p>\n");
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ static void compute_hash_as_string(std::string &buffer, void *data, UINT32 lengt
|
||||
static int split_file(const char *filename, const char *basename, UINT32 splitsize)
|
||||
{
|
||||
std::string outfilename, basefilename, splitfilename;
|
||||
core_file *outfile = nullptr, *infile = nullptr, *splitfile = nullptr;
|
||||
util::core_file::ptr outfile, infile, splitfile;
|
||||
std::string computedhash;
|
||||
void *splitbuffer = nullptr;
|
||||
int index, partnum;
|
||||
@ -81,7 +81,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
splitsize *= 1024 * 1024;
|
||||
|
||||
// open the file for read
|
||||
filerr = core_fopen(filename, OPEN_FLAG_READ, &infile);
|
||||
filerr = util::core_file::open(filename, OPEN_FLAG_READ, infile);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Fatal error: unable to open file '%s'\n", filename);
|
||||
@ -89,7 +89,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
}
|
||||
|
||||
// get the total length
|
||||
totallength = core_fsize(infile);
|
||||
totallength = infile->size();
|
||||
if (totallength < splitsize)
|
||||
{
|
||||
fprintf(stderr, "Fatal error: file is smaller than the split size\n");
|
||||
@ -119,7 +119,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
splitfilename.assign(basename).append(".split");
|
||||
|
||||
// create the split file
|
||||
filerr = core_fopen(splitfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &splitfile);
|
||||
filerr = util::core_file::open(splitfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, splitfile);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Fatal error: unable to create split file '%s'\n", splitfilename.c_str());
|
||||
@ -127,8 +127,8 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
}
|
||||
|
||||
// write the basics out
|
||||
core_fprintf(splitfile, "splitfile=%s\n", basefilename.c_str());
|
||||
core_fprintf(splitfile, "splitsize=%d\n", splitsize);
|
||||
splitfile->printf("splitfile=%s\n", basefilename.c_str());
|
||||
splitfile->printf("splitsize=%d\n", splitsize);
|
||||
|
||||
printf("Split file is '%s'\n", splitfilename.c_str());
|
||||
printf("Splitting file %s into chunks of %dMB...\n", basefilename.c_str(), splitsize / (1024 * 1024));
|
||||
@ -141,7 +141,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
printf("Reading part %d...", partnum);
|
||||
|
||||
// read as much as we can from the file
|
||||
length = core_fread(infile, splitbuffer, splitsize);
|
||||
length = infile->read(splitbuffer, splitsize);
|
||||
if (length == 0)
|
||||
break;
|
||||
|
||||
@ -149,13 +149,13 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
compute_hash_as_string(computedhash, splitbuffer, length);
|
||||
|
||||
// write that info to the split file
|
||||
core_fprintf(splitfile, "hash=%s file=%s.%03d\n", computedhash.c_str(), basefilename.c_str(), partnum);
|
||||
splitfile->printf("hash=%s file=%s.%03d\n", computedhash.c_str(), basefilename.c_str(), partnum);
|
||||
|
||||
// compute the full filename for this guy
|
||||
outfilename = string_format("%s.%03d", basename, partnum);
|
||||
|
||||
// create it
|
||||
filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
|
||||
filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, outfile);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
printf("\n");
|
||||
@ -166,15 +166,14 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
printf(" writing %s.%03d...", basefilename.c_str(), partnum);
|
||||
|
||||
// write the data
|
||||
actual = core_fwrite(outfile, splitbuffer, length);
|
||||
actual = outfile->write(splitbuffer, length);
|
||||
if (actual != length)
|
||||
{
|
||||
printf("\n");
|
||||
fprintf(stderr, "Fatal error: Error writing output file (out of space?)\n");
|
||||
goto cleanup;
|
||||
}
|
||||
core_fclose(outfile);
|
||||
outfile = nullptr;
|
||||
outfile.reset();
|
||||
|
||||
printf(" done\n");
|
||||
|
||||
@ -188,17 +187,17 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
|
||||
error = 0;
|
||||
|
||||
cleanup:
|
||||
if (splitfile != nullptr)
|
||||
if (splitfile)
|
||||
{
|
||||
core_fclose(splitfile);
|
||||
splitfile.reset();
|
||||
if (error != 0)
|
||||
remove(splitfilename.c_str());
|
||||
}
|
||||
if (infile != nullptr)
|
||||
core_fclose(infile);
|
||||
if (outfile != nullptr)
|
||||
if (infile)
|
||||
infile.reset();
|
||||
if (outfile)
|
||||
{
|
||||
core_fclose(outfile);
|
||||
outfile.reset();
|
||||
if (error != 0)
|
||||
remove(outfilename.c_str());
|
||||
}
|
||||
@ -218,7 +217,7 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
std::string expectedhash, computedhash;
|
||||
std::string outfilename, infilename;
|
||||
std::string basepath;
|
||||
core_file *outfile = nullptr, *infile = nullptr, *splitfile = nullptr;
|
||||
util::core_file::ptr outfile, infile, splitfile;
|
||||
void *splitbuffer = nullptr;
|
||||
file_error filerr;
|
||||
UINT32 splitsize;
|
||||
@ -227,7 +226,7 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
int index;
|
||||
|
||||
// open the file for read
|
||||
filerr = core_fopen(filename, OPEN_FLAG_READ, &splitfile);
|
||||
filerr = util::core_file::open(filename, OPEN_FLAG_READ, splitfile);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Fatal error: unable to open file '%s'\n", filename);
|
||||
@ -235,7 +234,7 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
}
|
||||
|
||||
// read the first line and verify this is a split file
|
||||
if (!core_fgets(buffer, sizeof(buffer), splitfile) || strncmp(buffer, "splitfile=", 10) != 0)
|
||||
if (!splitfile->gets(buffer, sizeof(buffer)) || strncmp(buffer, "splitfile=", 10) != 0)
|
||||
{
|
||||
fprintf(stderr, "Fatal error: corrupt or incomplete split file at line:\n%s\n", buffer);
|
||||
goto cleanup;
|
||||
@ -258,7 +257,7 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
outfilename.insert(0, basepath);
|
||||
|
||||
// read the split size
|
||||
if (!core_fgets(buffer, sizeof(buffer), splitfile) || sscanf(buffer, "splitsize=%d", &splitsize) != 1)
|
||||
if (!splitfile->gets(buffer, sizeof(buffer)) || sscanf(buffer, "splitsize=%d", &splitsize) != 1)
|
||||
{
|
||||
fprintf(stderr, "Fatal error: corrupt or incomplete split file at line:\n%s\n", buffer);
|
||||
goto cleanup;
|
||||
@ -268,17 +267,16 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
if (write_output)
|
||||
{
|
||||
// don't overwrite the original!
|
||||
filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_READ, &outfile);
|
||||
filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_READ, outfile);
|
||||
if (filerr == FILERR_NONE)
|
||||
{
|
||||
core_fclose(outfile);
|
||||
outfile = nullptr;
|
||||
outfile.reset();
|
||||
fprintf(stderr, "Fatal error: output file '%s' already exists\n", outfilename.c_str());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// open the output for write
|
||||
filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
|
||||
filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, outfile);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Fatal error: unable to create file '%s'\n", outfilename.c_str());
|
||||
@ -289,7 +287,7 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
printf("%s file '%s'...\n", write_output ? "Joining" : "Verifying", outfilename.c_str());
|
||||
|
||||
// now iterate through each file
|
||||
while (core_fgets(buffer, sizeof(buffer), splitfile))
|
||||
while (splitfile->gets(buffer, sizeof(buffer)))
|
||||
{
|
||||
UINT32 length, actual;
|
||||
|
||||
@ -307,7 +305,7 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
|
||||
// read the file's contents
|
||||
infilename.insert(0, basepath);
|
||||
filerr = core_fload(infilename.c_str(), &splitbuffer, &length);
|
||||
filerr = util::core_file::load(infilename.c_str(), &splitbuffer, length);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
printf("\n");
|
||||
@ -331,7 +329,7 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
{
|
||||
printf(" writing...");
|
||||
|
||||
actual = core_fwrite(outfile, splitbuffer, length);
|
||||
actual = outfile->write(splitbuffer, length);
|
||||
if (actual != length)
|
||||
{
|
||||
printf("\n");
|
||||
@ -357,13 +355,13 @@ static int join_file(const char *filename, const char *outname, int write_output
|
||||
error = 0;
|
||||
|
||||
cleanup:
|
||||
if (splitfile != nullptr)
|
||||
core_fclose(splitfile);
|
||||
if (infile != nullptr)
|
||||
core_fclose(infile);
|
||||
if (outfile != nullptr)
|
||||
if (splitfile)
|
||||
splitfile.reset();
|
||||
if (infile)
|
||||
infile.reset();
|
||||
if (outfile)
|
||||
{
|
||||
core_fclose(outfile);
|
||||
outfile.reset();
|
||||
if (error != 0)
|
||||
remove(outfilename.c_str());
|
||||
}
|
||||
|
@ -206,12 +206,12 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
|
||||
static int output_file(file_type type, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, bool link_to_file, std::string &tempheader, std::string &tempfooter);
|
||||
|
||||
// HTML helpers
|
||||
static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path);
|
||||
static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &path);
|
||||
static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path);
|
||||
static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &path);
|
||||
|
||||
// path helpers
|
||||
static std::string &normalized_subpath(std::string &dest, std::string &path, int start);
|
||||
static void output_path_as_links(core_file *file, std::string &path, bool end_is_directory, bool link_to_file);
|
||||
static void output_path_as_links(util::core_file &file, std::string &path, bool end_is_directory, bool link_to_file);
|
||||
static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, std::string &filename);
|
||||
|
||||
|
||||
@ -279,7 +279,7 @@ int main(int argc, char *argv[])
|
||||
// read the template file into an std::string
|
||||
UINT32 bufsize;
|
||||
void *buffer;
|
||||
if (core_fload(tempfilename.c_str(), &buffer, &bufsize) == FILERR_NONE)
|
||||
if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == FILERR_NONE)
|
||||
{
|
||||
tempheader.assign((const char *)buffer, bufsize);
|
||||
osd_free(buffer);
|
||||
@ -333,12 +333,12 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
|
||||
// create an index file
|
||||
std::string indexname;
|
||||
indexname = string_format("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], "index.html");
|
||||
core_file *indexfile = create_file_and_output_header(indexname, tempheader, srcdir_subpath);
|
||||
util::core_file::ptr indexfile = create_file_and_output_header(indexname, tempheader, srcdir_subpath);
|
||||
|
||||
// output the directory navigation
|
||||
core_fprintf(indexfile, "<h3>Viewing Directory: ");
|
||||
output_path_as_links(indexfile, srcdir_subpath, true, false);
|
||||
core_fprintf(indexfile, "</h3>");
|
||||
indexfile->printf("<h3>Viewing Directory: ");
|
||||
output_path_as_links(*indexfile, srcdir_subpath, true, false);
|
||||
indexfile->printf("</h3>");
|
||||
|
||||
// iterate first over directories, then over files
|
||||
int result = 0;
|
||||
@ -398,7 +398,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
|
||||
{
|
||||
// add a header
|
||||
if (curlist == list)
|
||||
core_fprintf(indexfile, "\t<h2>%s</h2>\n\t<ul>\n", (entry_type == ENTTYPE_DIR) ? "Directories" : "Files");
|
||||
indexfile->printf("\t<h2>%s</h2>\n\t<ul>\n", (entry_type == ENTTYPE_DIR) ? "Directories" : "Files");
|
||||
|
||||
// build the source filename
|
||||
std::string srcfile;
|
||||
@ -422,7 +422,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
|
||||
{
|
||||
dstfile = string_format("%s%c%s.html", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
|
||||
if (indexfile != nullptr)
|
||||
core_fprintf(indexfile, "\t<li><a href=\"%s.html\">%s</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
|
||||
indexfile->printf("\t<li><a href=\"%s.html\">%s</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
|
||||
result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, srcdir.compare(dstdir) == 0, tempheader, tempfooter);
|
||||
}
|
||||
}
|
||||
@ -432,14 +432,14 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
|
||||
{
|
||||
dstfile = string_format("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
|
||||
if (indexfile != nullptr)
|
||||
core_fprintf(indexfile, "\t<li><a href=\"%s/index.html\">%s/</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
|
||||
indexfile->printf("\t<li><a href=\"%s/index.html\">%s/</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
|
||||
result = recurse_dir(srcrootlen, dstrootlen, srcfile, dstfile, tempheader, tempfooter);
|
||||
}
|
||||
}
|
||||
|
||||
// close the list if we found some stuff
|
||||
if (list != nullptr)
|
||||
core_fprintf(indexfile, "\t</ul>\n");
|
||||
indexfile->printf("\t</ul>\n");
|
||||
|
||||
// free all the allocated entries
|
||||
while (list != nullptr)
|
||||
@ -451,7 +451,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
|
||||
}
|
||||
|
||||
if (indexfile != nullptr)
|
||||
output_footer_and_close_file(indexfile, tempfooter, srcdir_subpath);
|
||||
output_footer_and_close_file(std::move(indexfile), tempfooter, srcdir_subpath);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -516,36 +516,35 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri
|
||||
is_token[(UINT8)token_chars[toknum]] = true;
|
||||
|
||||
// open the source file
|
||||
core_file *src;
|
||||
if (core_fopen(srcfile.c_str(), OPEN_FLAG_READ, &src) != FILERR_NONE)
|
||||
util::core_file::ptr src;
|
||||
if (util::core_file::open(srcfile.c_str(), OPEN_FLAG_READ, src) != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Unable to read file '%s'\n", srcfile.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// open the output file
|
||||
core_file *dst = create_file_and_output_header(dstfile, tempheader, srcfile_subpath);
|
||||
util::core_file::ptr dst = create_file_and_output_header(dstfile, tempheader, srcfile_subpath);
|
||||
if (dst == nullptr)
|
||||
{
|
||||
fprintf(stderr, "Unable to write file '%s'\n", dstfile.c_str());
|
||||
core_fclose(src);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// output the directory navigation
|
||||
core_fprintf(dst, "<h3>Viewing File: ");
|
||||
output_path_as_links(dst, srcfile_subpath, false, link_to_file);
|
||||
core_fprintf(dst, "</h3>");
|
||||
dst->printf("<h3>Viewing File: ");
|
||||
output_path_as_links(*dst, srcfile_subpath, false, link_to_file);
|
||||
dst->printf("</h3>");
|
||||
|
||||
// start with some tags
|
||||
core_fprintf(dst, "\t<pre class=\"source\">\n");
|
||||
dst->printf("\t<pre class=\"source\">\n");
|
||||
|
||||
// iterate over lines in the source file
|
||||
int linenum = 1;
|
||||
bool in_comment = false;
|
||||
char srcline[4096];
|
||||
std::ostringstream dstline;
|
||||
while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != nullptr)
|
||||
while (src->gets(srcline, ARRAY_LENGTH(srcline)) != nullptr)
|
||||
{
|
||||
// start with the line number
|
||||
dstline.str("");
|
||||
@ -707,15 +706,14 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri
|
||||
|
||||
// append a break and move on
|
||||
dstline.put('\n');
|
||||
core_fputs(dst, dstline.str().c_str());
|
||||
dst->puts(dstline.str().c_str());
|
||||
}
|
||||
|
||||
// close tags
|
||||
core_fprintf(dst, "\t</pre>\n");
|
||||
dst->printf("\t</pre>\n");
|
||||
|
||||
// close the file
|
||||
output_footer_and_close_file(dst, tempfooter, srcfile_subpath);
|
||||
core_fclose(src);
|
||||
output_footer_and_close_file(std::move(dst), tempfooter, srcfile_subpath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -730,17 +728,17 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri
|
||||
HTML file with a standard header
|
||||
-------------------------------------------------*/
|
||||
|
||||
static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path)
|
||||
static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path)
|
||||
{
|
||||
// create the indexfile
|
||||
core_file *file;
|
||||
if (core_fopen(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE)
|
||||
return nullptr;
|
||||
util::core_file::ptr file;
|
||||
if (util::core_file::open(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file) != FILERR_NONE)
|
||||
return util::core_file::ptr();
|
||||
|
||||
// print a header
|
||||
std::string modified(templatefile);
|
||||
strreplace(modified, "<!--PATH-->", path.c_str());
|
||||
core_fwrite(file, modified.c_str(), modified.length());
|
||||
file->write(modified.c_str(), modified.length());
|
||||
|
||||
// return the file
|
||||
return file;
|
||||
@ -752,12 +750,12 @@ static core_file *create_file_and_output_header(std::string &filename, std::stri
|
||||
standard footer to an HTML file and close it
|
||||
-------------------------------------------------*/
|
||||
|
||||
static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &path)
|
||||
static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &path)
|
||||
{
|
||||
std::string modified(templatefile);
|
||||
strreplace(modified, "<!--PATH-->", path.c_str());
|
||||
core_fwrite(file, modified.c_str(), modified.length());
|
||||
core_fclose(file);
|
||||
file->write(modified.c_str(), modified.length());
|
||||
file.reset();
|
||||
}
|
||||
|
||||
|
||||
@ -783,7 +781,7 @@ static std::string &normalized_subpath(std::string &dest, std::string &path, int
|
||||
series of links
|
||||
-------------------------------------------------*/
|
||||
|
||||
static void output_path_as_links(core_file *file, std::string &path, bool end_is_directory, bool link_to_file)
|
||||
static void output_path_as_links(util::core_file &file, std::string &path, bool end_is_directory, bool link_to_file)
|
||||
{
|
||||
// first count how deep we are
|
||||
int srcdepth = 0;
|
||||
@ -793,10 +791,10 @@ static void output_path_as_links(core_file *file, std::string &path, bool end_is
|
||||
srcdepth++;
|
||||
|
||||
// output a link to the root
|
||||
core_fprintf(file, "<a href=\"");
|
||||
file.printf("<a href=\"");
|
||||
for (int depth = 0; depth < srcdepth; depth++)
|
||||
core_fprintf(file, "../");
|
||||
core_fprintf(file, "index.html\"><root></a>/");
|
||||
file.printf("../");
|
||||
file.printf("index.html\"><root></a>/");
|
||||
|
||||
// now output links to each path up the chain
|
||||
int curdepth = 0;
|
||||
@ -806,10 +804,10 @@ static void output_path_as_links(core_file *file, std::string &path, bool end_is
|
||||
std::string substr(path, lastslash, slashindex - lastslash);
|
||||
|
||||
curdepth++;
|
||||
core_fprintf(file, "<a href=\"");
|
||||
file.printf("<a href=\"");
|
||||
for (int depth = curdepth; depth < srcdepth; depth++)
|
||||
core_fprintf(file, "../");
|
||||
core_fprintf(file, "index.html\">%s</a>/", substr.c_str());
|
||||
file.printf("../");
|
||||
file.printf("index.html\">%s</a>/", substr.c_str());
|
||||
|
||||
lastslash = slashindex + 1;
|
||||
}
|
||||
@ -817,11 +815,11 @@ static void output_path_as_links(core_file *file, std::string &path, bool end_is
|
||||
// and a final link to the current directory
|
||||
std::string substr(path, lastslash, -1);
|
||||
if (end_is_directory)
|
||||
core_fprintf(file, "<a href=\"index.html\">%s</a>", substr.c_str());
|
||||
file.printf("<a href=\"index.html\">%s</a>", substr.c_str());
|
||||
else if (link_to_file)
|
||||
core_fprintf(file, "<a href=\"%s\">%s</a>", substr.c_str(), substr.c_str());
|
||||
file.printf("<a href=\"%s\">%s</a>", substr.c_str(), substr.c_str());
|
||||
else
|
||||
core_fprintf(file, "<a href=\"%s.html\">%s</a>", substr.c_str(), substr.c_str());
|
||||
file.printf("<a href=\"%s.html\">%s</a>", substr.c_str(), substr.c_str());
|
||||
}
|
||||
|
||||
|
||||
@ -866,11 +864,11 @@ static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstro
|
||||
srcincpath.append(PATH_SEPARATOR).append(filename.substr(lastsepindex, -1));
|
||||
|
||||
// see if we can open it
|
||||
core_file *testfile;
|
||||
if (core_fopen(srcincpath.c_str(), OPEN_FLAG_READ, &testfile) == FILERR_NONE)
|
||||
util::core_file::ptr testfile;
|
||||
if (util::core_file::open(srcincpath.c_str(), OPEN_FLAG_READ, testfile) == FILERR_NONE)
|
||||
{
|
||||
// close the file
|
||||
core_fclose(testfile);
|
||||
testfile.reset();
|
||||
|
||||
// find the longest matching directory substring between the include and source file
|
||||
lastsepindex = 0;
|
||||
|
@ -512,7 +512,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
|
||||
// load the file
|
||||
filerr = core_fload(opts.filename, &data, &length);
|
||||
filerr = util::core_file::load(opts.filename, &data, length);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Error opening file '%s'\n", opts.filename);
|
||||
|
Loading…
Reference in New Issue
Block a user