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/chdman.cpp | |
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/chdman.cpp')
-rw-r--r-- | src/tools/chdman.cpp | 121 |
1 files changed, 60 insertions, 61 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; } } |