diff options
| author | 2016-03-13 13:54:57 +1100 | |
|---|---|---|
| committer | 2016-03-14 18:55:00 +1100 | |
| commit | 42fbb9c3967fcda37f2d9ae17d5796a79cf027b9 (patch) | |
| tree | a43047ee00431e5e22bfc5f8f612ff775586e415 /src/tools | |
| parent | 5fc27747031b6ed6f6c0582502098ebfb960be67 (diff) | |
Make osd_file a polymorphic class that's held with smart pointers
Make avi_file a class that's held with smart pointers, encapsulate various AVI I/O structures
Make zip_file and _7z_file classes rather than having free functions everywhere
Hide zip/7z class implementation behind an interface, no longer need to call close() to send back to the cache
Don't dump as much crap in global namespace
Add solaris PTY implementation
Improve variable expansion for SDL OSD - supports ~/$FOO/${BAR} syntax
Rearrange stuff so the same things are in file module for all OSDs
Move file stuff into its own module
7z/zip open and destruct are still not thread-safe due to lack of interlocks around cache access
Directory functions still need to be moved to file module
SDL OSD may not initialise WinSock on Windows
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/chdman.cpp | 121 | ||||
| -rw-r--r-- | src/tools/imgtool/stream.cpp | 28 | ||||
| -rw-r--r-- | src/tools/ldverify.cpp | 42 | ||||
| -rw-r--r-- | src/tools/pngcmp.cpp | 16 | ||||
| -rw-r--r-- | src/tools/regrep.cpp | 18 | ||||
| -rw-r--r-- | src/tools/romcmp.cpp | 36 | ||||
| -rw-r--r-- | src/tools/split.cpp | 18 | ||||
| -rw-r--r-- | src/tools/src2html.cpp | 8 | ||||
| -rw-r--r-- | src/tools/unidasm.cpp | 4 |
9 files changed, 140 insertions, 151 deletions
diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp index 1a80bc76e13..6029f481e07 100644 --- a/src/tools/chdman.cpp +++ b/src/tools/chdman.cpp @@ -331,8 +331,8 @@ public: { m_file.reset(); m_lastfile = m_info.track[tracknum].fname; - file_error filerr = util::core_file::open(m_lastfile.c_str(), OPEN_FLAG_READ, m_file); - if (filerr != FILERR_NONE) + osd_file::error filerr = util::core_file::open(m_lastfile.c_str(), OPEN_FLAG_READ, m_file); + if (filerr != osd_file::error::NONE) report_error(1, "Error opening input file (%s)'", m_lastfile.c_str()); } @@ -438,15 +438,15 @@ public: // read the sound samples m_audio[chnum].resize(samples); samplesptr[chnum] = &m_audio[chnum][0]; - avi_error avierr = avi_read_sound_samples(&m_file, chnum, first_sample, samples, &m_audio[chnum][0]); - if (avierr != AVIERR_NONE) - report_error(1, "Error reading audio samples %d-%d from channel %d: %s", first_sample, samples, chnum, avi_error_string(avierr)); + avi_file::error avierr = m_file.read_sound_samples(chnum, first_sample, samples, &m_audio[chnum][0]); + if (avierr != avi_file::error::NONE) + report_error(1, "Error reading audio samples %d-%d from channel %d: %s", first_sample, samples, chnum, avi_file::error_string(avierr)); } // read the video data - avi_error avierr = avi_read_video_frame(&m_file, effframe / interlace_factor, m_bitmap); - if (avierr != AVIERR_NONE) - report_error(1, "Error reading AVI frame %d: %s", effframe / interlace_factor, avi_error_string(avierr)); + avi_file::error avierr = m_file.read_video_frame(effframe / interlace_factor, m_bitmap); + if (avierr != avi_file::error::NONE) + report_error(1, "Error reading AVI frame %d: %s", effframe / interlace_factor, avi_file::error_string(avierr)); bitmap_yuy16 subbitmap(&m_bitmap.pix(effframe % interlace_factor), m_bitmap.width(), m_bitmap.height() / interlace_factor, m_bitmap.rowpixels() * interlace_factor); // update metadata for this frame @@ -1007,8 +1007,8 @@ static void check_existing_output_file(const parameters_t ¶ms, const char *f if (params.find(OPTION_OUTPUT_FORCE) == params.end()) { util::core_file::ptr file; - file_error filerr = util::core_file::open(filename, OPEN_FLAG_READ, file); - if (filerr == FILERR_NONE) + osd_file::error filerr = util::core_file::open(filename, OPEN_FLAG_READ, file); + if (filerr == osd_file::error::NONE) { file.reset(); report_error(1, "Error: file already exists (%s)\nUse --force (or -f) to force overwriting", filename); @@ -1572,8 +1572,8 @@ static void do_create_raw(parameters_t ¶ms) auto input_file_str = params.find(OPTION_INPUT); if (input_file_str != params.end()) { - file_error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file); - if (filerr != FILERR_NONE) + osd_file::error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file); + if (filerr != osd_file::error::NONE) report_error(1, "Unable to open file (%s)", input_file_str->second->c_str()); } @@ -1651,7 +1651,7 @@ static void do_create_raw(parameters_t ¶ms) // delete the output file auto output_chd_str = params.find(OPTION_OUTPUT); if (output_chd_str != params.end()) - osd_rmfile(output_chd_str->second->c_str()); + osd_file::remove(*output_chd_str->second); throw; } } @@ -1669,8 +1669,8 @@ static void do_create_hd(parameters_t ¶ms) auto input_file_str = params.find(OPTION_INPUT); if (input_file_str != params.end()) { - file_error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file); - if (filerr != FILERR_NONE) + osd_file::error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file); + if (filerr != osd_file::error::NONE) report_error(1, "Unable to open file (%s)", input_file_str->second->c_str()); } @@ -1744,8 +1744,8 @@ static void do_create_hd(parameters_t ¶ms) if (ident_str != params.end()) { // load the file - file_error filerr = util::core_file::load(ident_str->second->c_str(), identdata); - if (filerr != FILERR_NONE) + osd_file::error filerr = util::core_file::load(ident_str->second->c_str(), identdata); + if (filerr != osd_file::error::NONE) report_error(1, "Error reading ident file (%s)", ident_str->second->c_str()); // must be at least 14 bytes; extract CHS data from there @@ -1840,7 +1840,7 @@ static void do_create_hd(parameters_t ¶ms) // delete the output file auto output_chd_str = params.find(OPTION_OUTPUT); if (output_chd_str != params.end()) - osd_rmfile(output_chd_str->second->c_str()); + osd_file::remove(*output_chd_str->second); throw; } } @@ -1932,7 +1932,7 @@ static void do_create_cd(parameters_t ¶ms) // delete the output file auto output_chd_str = params.find(OPTION_OUTPUT); if (output_chd_str != params.end()) - osd_rmfile(output_chd_str->second->c_str()); + osd_file::remove(*output_chd_str->second); throw; } } @@ -1946,15 +1946,15 @@ static void do_create_cd(parameters_t ¶ms) static void do_create_ld(parameters_t ¶ms) { // process input file - avi_file *input_file = nullptr; + avi_file::ptr input_file; auto input_file_str = params.find(OPTION_INPUT); if (input_file_str != params.end()) { - avi_error avierr = avi_open(input_file_str->second->c_str(), &input_file); - if (avierr != AVIERR_NONE) - report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->second->c_str(), avi_error_string(avierr)); + avi_file::error avierr = avi_file::open(*input_file_str->second, input_file); + if (avierr != avi_file::error::NONE) + report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->second->c_str(), avi_file::error_string(avierr)); } - const avi_movie_info *aviinfo = avi_get_movie_info(input_file); + const avi_file::movie_info &aviinfo = input_file->get_movie_info(); // process output CHD chd_file output_parent; @@ -1963,16 +1963,16 @@ static void do_create_ld(parameters_t ¶ms) // process input start/end UINT64 input_start; UINT64 input_end; - parse_input_start_end(params, aviinfo->video_numsamples, 0, 1, input_start, input_end); + parse_input_start_end(params, aviinfo.video_numsamples, 0, 1, input_start, input_end); // determine parameters of the incoming video stream avi_info info; - info.fps_times_1million = UINT64(aviinfo->video_timescale) * 1000000 / aviinfo->video_sampletime; - info.width = aviinfo->video_width; - info.height = aviinfo->video_height; + info.fps_times_1million = UINT64(aviinfo.video_timescale) * 1000000 / aviinfo.video_sampletime; + info.width = aviinfo.video_width; + info.height = aviinfo.video_height; info.interlaced = ((info.fps_times_1million / 1000000) <= 30) && (info.height % 2 == 0) && (info.height > 288); - info.channels = aviinfo->audio_channels; - info.rate = aviinfo->audio_samplerate; + info.channels = aviinfo.audio_channels; + info.rate = aviinfo.audio_samplerate; // adjust for interlacing if (info.interlaced) @@ -2008,7 +2008,7 @@ static void do_create_ld(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 != aviinfo->video_numsamples) + if (input_start != 0 && input_end != aviinfo.video_numsamples) printf("Input start: %s\n", big_int_string(tempstr, input_start)); printf("Input length: %s (%02d:%02d:%02d)\n", big_int_string(tempstr, input_end - input_start), UINT32((UINT64(input_end - input_start) * 1000000 / info.fps_times_1million / 60 / 60)), @@ -2059,7 +2059,7 @@ static void do_create_ld(parameters_t ¶ms) // delete the output file auto output_chd_str = params.find(OPTION_OUTPUT); if (output_chd_str != params.end()) - osd_rmfile(output_chd_str->second->c_str()); + osd_file::remove(*output_chd_str->second); throw; } } @@ -2195,7 +2195,7 @@ static void do_copy(parameters_t ¶ms) // delete the output file auto output_chd_str = params.find(OPTION_OUTPUT); if (output_chd_str != params.end()) - osd_rmfile(output_chd_str->second->c_str()); + osd_file::remove(*output_chd_str->second); throw; } } @@ -2238,8 +2238,8 @@ static void do_extract_raw(parameters_t ¶ms) try { // process 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) + osd_file::error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_file); + if (filerr != osd_file::error::NONE) report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // copy all data @@ -2273,7 +2273,7 @@ static void do_extract_raw(parameters_t ¶ms) if (output_file != nullptr) { output_file.reset(); - osd_rmfile(output_file_str->second->c_str()); + osd_file::remove(*output_file_str->second); } throw; } @@ -2343,15 +2343,15 @@ static void do_extract_cd(parameters_t ¶ms) } // process output 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) + osd_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 != osd_file::error::NONE) report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // process output BIN file if (mode != MODE_GDI) { filerr = util::core_file::open(output_bin_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_bin_file); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) report_error(1, "Unable to open file (%s)", output_bin_file_str->c_str()); } @@ -2387,7 +2387,7 @@ static void do_extract_cd(parameters_t ¶ms) output_bin_file.reset(); filerr = util::core_file::open(trackbin_name.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_bin_file); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) report_error(1, "Unable to open file (%s)", trackbin_name.c_str()); outputoffs = 0; @@ -2471,8 +2471,8 @@ static void do_extract_cd(parameters_t ¶ms) // delete the output files output_bin_file.reset(); output_toc_file.reset(); - osd_rmfile(output_bin_file_str->c_str()); - osd_rmfile(output_file_str->second->c_str()); + osd_file::remove(*output_bin_file_str); + osd_file::remove(*output_file_str->second); throw; } } @@ -2528,7 +2528,7 @@ static void do_extract_ld(parameters_t ¶ms) input_end *= interlace_factor; // build up the movie info - avi_movie_info info; + avi_file::movie_info info; info.video_format = FORMAT_YUY2; info.video_timescale = fps_times_1million / interlace_factor; info.video_sampletime = 1000000; @@ -2558,12 +2558,12 @@ static void do_extract_ld(parameters_t ¶ms) } // catch errors so we can close & delete the output file - avi_file *output_file = nullptr; + avi_file::ptr output_file; try { // process output file - avi_error avierr = avi_create(output_file_str->second->c_str(), &info, &output_file); - if (avierr != AVIERR_NONE) + avi_file::error avierr = avi_file::create(*output_file_str->second, info, output_file); + if (avierr != avi_file::error::NONE) report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // create the codec configuration @@ -2599,30 +2599,29 @@ static void do_extract_ld(parameters_t ¶ms) // write audio for (int chnum = 0; chnum < channels; chnum++) { - avi_error avierr = avi_append_sound_samples(output_file, chnum, avconfig.audio[chnum], actsamples, 0); - if (avierr != AVIERR_NONE) - report_error(1, "Error writing samples for hunk %d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr)); + avi_file::error avierr = output_file->append_sound_samples(chnum, avconfig.audio[chnum], actsamples, 0); + if (avierr != avi_file::error::NONE) + report_error(1, "Error writing samples for hunk %d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_file::error_string(avierr)); } // write video if ((framenum + 1) % interlace_factor == 0) { - avi_error avierr = avi_append_video_frame(output_file, fullbitmap); - if (avierr != AVIERR_NONE) - report_error(1, "Error writing video for hunk %d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr)); + avi_file::error avierr = output_file->append_video_frame(fullbitmap); + if (avierr != avi_file::error::NONE) + report_error(1, "Error writing video for hunk %d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_file::error_string(avierr)); } } // close and return - avi_close(output_file); + output_file.reset(); printf("Extraction complete \n"); } catch (...) { // delete the output file - if (output_file != nullptr) - avi_close(output_file); - osd_rmfile(output_file_str->second->c_str()); + output_file.reset(); + osd_file::remove(*output_file_str->second); throw; } } @@ -2670,8 +2669,8 @@ static void do_add_metadata(parameters_t ¶ms) dynamic_buffer file; if (file_str != params.end()) { - file_error filerr = util::core_file::load(file_str->second->c_str(), file); - if (filerr != FILERR_NONE) + osd_file::error filerr = util::core_file::load(file_str->second->c_str(), file); + if (filerr != osd_file::error::NONE) report_error(1, "Error reading metadata file (%s)", file_str->second->c_str()); } @@ -2794,8 +2793,8 @@ static void do_dump_metadata(parameters_t ¶ms) // create the file if (output_file_str != params.end()) { - 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) + osd_file::error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_file); + if (filerr != osd_file::error::NONE) report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // output the metadata @@ -2820,7 +2819,7 @@ static void do_dump_metadata(parameters_t ¶ms) { // delete the output file output_file.reset(); - osd_rmfile(output_file_str->second->c_str()); + osd_file::remove(*output_file_str->second); throw; } } diff --git a/src/tools/imgtool/stream.cpp b/src/tools/imgtool/stream.cpp index 4cc4c9ec2db..d96cf325a7a 100644 --- a/src/tools/imgtool/stream.cpp +++ b/src/tools/imgtool/stream.cpp @@ -104,33 +104,27 @@ static imgtool_stream *stream_open_zip(const char *zipname, const char *subname, imgfile->imgtype = IMG_MEM; - zip_file *z = nullptr; - const zip_file_header *zipent = nullptr; - zip_file_open(zipname, &z); + zip_file::ptr z; + const zip_file::file_header *zipent = nullptr; + zip_file::open(zipname, z); if (!z) - goto error; + return nullptr; - zipent = zip_file_first_file(z); + zipent = z->first_file(); while (zipent && subname && strcmp(subname, zipent->filename)) - zipent = zip_file_next_file(z); + zipent = z->next_file(); if (!zipent) - goto error; + return nullptr; imgfile->filesize = zipent->uncompressed_length; imgfile->buffer = reinterpret_cast<std::uint8_t *>(malloc(zipent->uncompressed_length)); if (!imgfile->buffer) - goto error; + return nullptr; - if (zip_file_decompress(z, imgfile->buffer, zipent->uncompressed_length)) - goto error; + if (z->decompress(imgfile->buffer, zipent->uncompressed_length) != zip_file::error::NONE) + return nullptr; - zip_file_close(z); return imgfile.release(); - -error: - if (z) - zip_file_close(z); - return nullptr; } @@ -154,7 +148,7 @@ imgtool_stream *stream_open(const char *fname, int read_or_write) 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 (filerr != osd_file::error::NONE) { if (!read_or_write) { diff --git a/src/tools/ldverify.cpp b/src/tools/ldverify.cpp index ab3947dfaea..45c20d9d70c 100644 --- a/src/tools/ldverify.cpp +++ b/src/tools/ldverify.cpp @@ -102,23 +102,23 @@ static bool chdinterlaced; static void *open_avi(const char *filename, movie_info &info) { // open the file - avi_file *avi; - avi_error avierr = avi_open(filename, &avi); - if (avierr != AVIERR_NONE) + avi_file::ptr avi; + avi_file::error avierr = avi_file::open(filename, avi); + if (avierr != avi_file::error::NONE) { - fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr)); + fprintf(stderr, "Error opening AVI file: %s\n", avi_file::error_string(avierr)); return nullptr; } // extract movie info - const avi_movie_info *aviinfo = avi_get_movie_info(avi); - info.framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime; - info.numframes = aviinfo->video_numsamples; - info.width = aviinfo->video_width; - info.height = aviinfo->video_height; - info.samplerate = aviinfo->audio_samplerate; - info.channels = aviinfo->audio_channels; - return avi; + const avi_file::movie_info &aviinfo = avi->get_movie_info(); + info.framerate = (double)aviinfo.video_timescale / (double)aviinfo.video_sampletime; + info.numframes = aviinfo.video_numsamples; + info.width = aviinfo.video_width; + info.height = aviinfo.video_height; + info.samplerate = aviinfo.audio_samplerate; + info.channels = aviinfo.audio_channels; + return avi.release(); } @@ -131,17 +131,17 @@ static bool read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, avi_file *avifile = reinterpret_cast<avi_file *>(file); // read the frame - avi_error avierr = avi_read_video_frame(avifile, frame, bitmap); - if (avierr != AVIERR_NONE) + avi_file::error avierr = avifile->read_video_frame(frame, bitmap); + if (avierr != avi_file::error::NONE) return FALSE; // read the samples - const avi_movie_info *aviinfo = avi_get_movie_info(avifile); - UINT32 firstsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); - UINT32 lastsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame + 1) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); - avierr = avi_read_sound_samples(avifile, 0, firstsample, lastsample - firstsample, lsound); - avierr = avi_read_sound_samples(avifile, 1, firstsample, lastsample - firstsample, rsound); - if (avierr != AVIERR_NONE) + const avi_file::movie_info &aviinfo = avifile->get_movie_info(); + UINT32 firstsample = (UINT64(aviinfo.audio_samplerate) * UINT64(frame) * UINT64(aviinfo.video_sampletime) + aviinfo.video_timescale - 1) / UINT64(aviinfo.video_timescale); + UINT32 lastsample = (UINT64(aviinfo.audio_samplerate) * UINT64(frame + 1) * UINT64(aviinfo.video_sampletime) + aviinfo.video_timescale - 1) / UINT64(aviinfo.video_timescale); + avierr = avifile->read_sound_samples(0, firstsample, lastsample - firstsample, lsound); + avierr = avifile->read_sound_samples(1, firstsample, lastsample - firstsample, rsound); + if (avierr != avi_file::error::NONE) return false; samples = lastsample - firstsample; return true; @@ -155,7 +155,7 @@ static bool read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, static void close_avi(void *file) { avi_file *avifile = reinterpret_cast<avi_file *>(file); - avi_close(avifile); + delete avifile; } diff --git a/src/tools/pngcmp.cpp b/src/tools/pngcmp.cpp index 5103740389b..aa33a421e5d 100644 --- a/src/tools/pngcmp.cpp +++ b/src/tools/pngcmp.cpp @@ -73,7 +73,7 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img bitmap_argb32 finalbitmap; int width, height, maxwidth; util::core_file::ptr file; - file_error filerr; + osd_file::error filerr; png_error pngerr; int error = 100; bool bitmaps_differ; @@ -81,9 +81,9 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img /* open the source image */ filerr = util::core_file::open(imgfile1.c_str(), OPEN_FLAG_READ, file); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { - printf("Could not open %s (%d)\n", imgfile1.c_str(), filerr); + printf("Could not open %s (%d)\n", imgfile1.c_str(), int(filerr)); goto error; } @@ -98,9 +98,9 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img /* open the source image */ filerr = util::core_file::open(imgfile2.c_str(), OPEN_FLAG_READ, file); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { - printf("Could not open %s (%d)\n", imgfile2.c_str(), filerr); + printf("Could not open %s (%d)\n", imgfile2.c_str(), int(filerr)); goto error; } @@ -171,9 +171,9 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img /* write the final PNG */ filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { - printf("Could not open %s (%d)\n", outfilename.c_str(), filerr); + printf("Could not open %s (%d)\n", outfilename.c_str(), int(filerr)); goto error; } pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr); @@ -193,6 +193,6 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img error: if (error == -1) - osd_rmfile(outfilename.c_str()); + osd_file::remove(outfilename); return error; } diff --git a/src/tools/regrep.cpp b/src/tools/regrep.cpp index b0cad2497ae..4d02151672b 100644 --- a/src/tools/regrep.cpp +++ b/src/tools/regrep.cpp @@ -235,7 +235,7 @@ int main(int argc, char *argv[]) /* read the template file into an astring */ std::string tempheader; - if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == FILERR_NONE) + if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == osd_file::error::NONE) { tempheader.assign((const char *)buffer, bufsize); osd_free(buffer); @@ -565,7 +565,7 @@ static util::core_file::ptr create_file_and_output_header(std::string &filename, util::core_file::ptr file; /* create the indexfile */ - 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) + if (util::core_file::open(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file) != osd_file::error::NONE) return util::core_file::ptr(); /* print a header */ @@ -728,7 +728,7 @@ static int compare_screenshots(summary_file *curfile) if (curfile->status[listnum] == STATUS_SUCCESS) { std::string fullname; - file_error filerr; + osd_file::error filerr; util::core_file::ptr file; /* get the filename for the image */ @@ -738,7 +738,7 @@ static int compare_screenshots(summary_file *curfile) filerr = util::core_file::open(fullname.c_str(), OPEN_FLAG_READ, file); /* if that failed, look in the old location */ - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { /* get the filename for the image */ fullname = string_format("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "_%s.png", lists[listnum].dir, curfile->name); @@ -748,7 +748,7 @@ static int compare_screenshots(summary_file *curfile) } /* if that worked, load the file */ - if (filerr == FILERR_NONE) + if (filerr == osd_file::error::NONE) { png_read_bitmap(*file, bitmaps[listnum]); file.reset(); @@ -837,7 +837,7 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir, int bitmapcount = 0; int listnum, bmnum; util::core_file::ptr file; - file_error filerr; + osd_file::error filerr; png_error pngerr; int error = -1; int starty; @@ -854,7 +854,7 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir, /* open the source image */ filerr = util::core_file::open(tempname.c_str(), OPEN_FLAG_READ, file); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) goto error; /* load the source image */ @@ -926,7 +926,7 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir, /* write the final PNG */ filerr = util::core_file::open(dstfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) goto error; pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr); file.reset(); @@ -938,7 +938,7 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir, error: if (error) - osd_rmfile(dstfilename.c_str()); + osd_file::remove(dstfilename); return error; } diff --git a/src/tools/romcmp.cpp b/src/tools/romcmp.cpp index 4d89718abe9..a6919631cd8 100644 --- a/src/tools/romcmp.cpp +++ b/src/tools/romcmp.cpp @@ -393,11 +393,11 @@ static float filecompare(const fileinfo *file1,const fileinfo *file2,int mode1,i static void readfile(const char *path,fileinfo *file) { - file_error filerr; + osd_file::error filerr; UINT64 filesize; UINT32 actual; char fullname[256]; - osd_file *f = nullptr; + osd_file::ptr f; if (path) { @@ -414,22 +414,19 @@ static void readfile(const char *path,fileinfo *file) return; } - filerr = osd_open(fullname, OPEN_FLAG_READ, &f, &filesize); - if (filerr != FILERR_NONE) + filerr = osd_file::open(fullname, OPEN_FLAG_READ, f, filesize); + if (filerr != osd_file::error::NONE) { - printf("%s: error %d\n", fullname, filerr); + printf("%s: error %d\n", fullname, int(filerr)); return; } - filerr = osd_read(f, file->buf, 0, file->size, &actual); - if (filerr != FILERR_NONE) + filerr = f->read(file->buf, 0, file->size, actual); + if (filerr != osd_file::error::NONE) { - printf("%s: error %d\n", fullname, filerr); - osd_close(f); + printf("%s: error %d\n", fullname, int(filerr)); return; } - - osd_close(f); } @@ -493,20 +490,20 @@ static int load_files(int i, int *found, const char *path) /* if not, try to open as a ZIP file */ else { - zip_file *zip; - const zip_file_header* zipent; - zip_error ziperr; + zip_file::ptr zip; + const zip_file::file_header* zipent; + zip_file::error ziperr; /* wasn't a directory, so try to open it as a zip file */ - ziperr = zip_file_open(path, &zip); - if (ziperr != ZIPERR_NONE) + ziperr = zip_file::open(path, zip); + if (ziperr != zip_file::error::NONE) { printf("Error, cannot open zip file '%s' !\n", path); return 1; } /* load all files in zip file */ - for (zipent = zip_file_first_file(zip); zipent != nullptr; zipent = zip_file_next_file(zip)) + for (zipent = zip->first_file(); zipent != nullptr; zipent = zip->next_file()) { int size; @@ -529,7 +526,7 @@ static int load_files(int i, int *found, const char *path) printf("%s: out of memory!\n",file->name); else { - if (zip_file_decompress(zip, (char *)file->buf, file->size) != ZIPERR_NONE) + if (zip->decompress(file->buf, file->size) != zip_file::error::NONE) { free(file->buf); file->buf = nullptr; @@ -545,7 +542,6 @@ static int load_files(int i, int *found, const char *path) found[i]++; } } - zip_file_close(zip); } return 0; } @@ -747,6 +743,6 @@ int CLIB_DECL main(int argc,char *argv[]) } } - zip_file_cache_clear(); + zip_file::cache_clear(); return 0; } diff --git a/src/tools/split.cpp b/src/tools/split.cpp index f942e1481c2..5151229edd8 100644 --- a/src/tools/split.cpp +++ b/src/tools/split.cpp @@ -69,7 +69,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi void *splitbuffer = nullptr; int index, partnum; UINT64 totallength; - file_error filerr; + osd_file::error filerr; int error = 1; // convert split size to MB @@ -82,7 +82,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi // open the file for read filerr = util::core_file::open(filename, OPEN_FLAG_READ, infile); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { fprintf(stderr, "Fatal error: unable to open file '%s'\n", filename); goto cleanup; @@ -120,7 +120,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi // create the split file filerr = util::core_file::open(splitfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, splitfile); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { fprintf(stderr, "Fatal error: unable to create split file '%s'\n", splitfilename.c_str()); goto cleanup; @@ -156,7 +156,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi // create it filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, outfile); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { printf("\n"); fprintf(stderr, "Fatal error: unable to create output file '%s'\n", outfilename.c_str()); @@ -219,7 +219,7 @@ static int join_file(const char *filename, const char *outname, int write_output std::string basepath; util::core_file::ptr outfile, infile, splitfile; void *splitbuffer = nullptr; - file_error filerr; + osd_file::error filerr; UINT32 splitsize; char buffer[256]; int error = 1; @@ -227,7 +227,7 @@ static int join_file(const char *filename, const char *outname, int write_output // open the file for read filerr = util::core_file::open(filename, OPEN_FLAG_READ, splitfile); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { fprintf(stderr, "Fatal error: unable to open file '%s'\n", filename); goto cleanup; @@ -268,7 +268,7 @@ static int join_file(const char *filename, const char *outname, int write_output { // don't overwrite the original! filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_READ, outfile); - if (filerr == FILERR_NONE) + if (filerr == osd_file::error::NONE) { outfile.reset(); fprintf(stderr, "Fatal error: output file '%s' already exists\n", outfilename.c_str()); @@ -277,7 +277,7 @@ static int join_file(const char *filename, const char *outname, int write_output // open the output for write filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, outfile); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { fprintf(stderr, "Fatal error: unable to create file '%s'\n", outfilename.c_str()); goto cleanup; @@ -306,7 +306,7 @@ static int join_file(const char *filename, const char *outname, int write_output // read the file's contents infilename.insert(0, basepath); filerr = util::core_file::load(infilename.c_str(), &splitbuffer, length); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { printf("\n"); fprintf(stderr, "Fatal error: unable to load file '%s'\n", infilename.c_str()); diff --git a/src/tools/src2html.cpp b/src/tools/src2html.cpp index e95cbe11764..9b3110a212f 100644 --- a/src/tools/src2html.cpp +++ b/src/tools/src2html.cpp @@ -279,7 +279,7 @@ int main(int argc, char *argv[]) // read the template file into an std::string UINT32 bufsize; void *buffer; - if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == FILERR_NONE) + if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == osd_file::error::NONE) { tempheader.assign((const char *)buffer, bufsize); osd_free(buffer); @@ -517,7 +517,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri // open the source file util::core_file::ptr src; - if (util::core_file::open(srcfile.c_str(), OPEN_FLAG_READ, src) != FILERR_NONE) + if (util::core_file::open(srcfile.c_str(), OPEN_FLAG_READ, src) != osd_file::error::NONE) { fprintf(stderr, "Unable to read file '%s'\n", srcfile.c_str()); return 1; @@ -732,7 +732,7 @@ static util::core_file::ptr create_file_and_output_header(std::string &filename, { // create the indexfile 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) + if (util::core_file::open(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file) != osd_file::error::NONE) return util::core_file::ptr(); // print a header @@ -865,7 +865,7 @@ static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstro // see if we can open it util::core_file::ptr testfile; - if (util::core_file::open(srcincpath.c_str(), OPEN_FLAG_READ, testfile) == FILERR_NONE) + if (util::core_file::open(srcincpath.c_str(), OPEN_FLAG_READ, testfile) == osd_file::error::NONE) { // close the file testfile.reset(); diff --git a/src/tools/unidasm.cpp b/src/tools/unidasm.cpp index f69de2b0864..bf0d7c42959 100644 --- a/src/tools/unidasm.cpp +++ b/src/tools/unidasm.cpp @@ -494,7 +494,7 @@ usage: int main(int argc, char *argv[]) { - file_error filerr; + osd_file::error filerr; int displayendian; int displaychunk; UINT32 curbyte; @@ -513,7 +513,7 @@ int main(int argc, char *argv[]) // load the file filerr = util::core_file::load(opts.filename, &data, length); - if (filerr != FILERR_NONE) + if (filerr != osd_file::error::NONE) { fprintf(stderr, "Error opening file '%s'\n", opts.filename); return 1; |
