void input_helper::open(service_ptr_t<file> p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) { p_abort.check(); if (m_input.is_empty() || metadb::path_compare(p_location.get_path(),m_path) != 0) { m_input.release(); service_ptr_t<file> l_file = p_filehint; process_fullbuffer(l_file,p_location.get_path(),m_fullbuffer,p_abort); TRACK_CODE("input_entry::g_open_for_decoding", input_entry::g_open_for_decoding(m_input,l_file,p_location.get_path(),p_abort,p_from_redirect) ); if (!p_skip_hints) { try { static_api_ptr_t<metadb_io>()->hint_reader(m_input.get_ptr(),p_location.get_path(),p_abort); } catch(exception_io_data) { //don't fail to decode when this barfs m_input.release(); if (l_file.is_valid()) l_file->reopen(p_abort); TRACK_CODE("input_entry::g_open_for_decoding", input_entry::g_open_for_decoding(m_input,l_file,p_location.get_path(),p_abort,p_from_redirect) ); } } m_path = p_location.get_path(); } TRACK_CODE("input_decoder::initialize",m_input->initialize(p_location.get_subsong_index(),p_flags,p_abort)); }
bool input_helper::open_path(file::ptr p_filehint,const char * path,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) { p_abort.check(); if (!need_file_reopen(path)) return false; m_input.release(); service_ptr_t<file> l_file = p_filehint; process_fullbuffer(l_file,path,m_fullbuffer,p_abort); TRACK_CODE("input_entry::g_open_for_decoding", input_entry::g_open_for_decoding(m_input,l_file,path,p_abort,p_from_redirect) ); if (!p_skip_hints) { try { static_api_ptr_t<metadb_io>()->hint_reader(m_input.get_ptr(),path,p_abort); } catch(exception_io_data) { //Don't fail to decode when this barfs, might be barfing when reading info from another subsong than the one we're trying to decode etc. m_input.release(); if (l_file.is_valid()) l_file->reopen(p_abort); TRACK_CODE("input_entry::g_open_for_decoding", input_entry::g_open_for_decoding(m_input,l_file,path,p_abort,p_from_redirect) ); } } m_path = path; return true; }
void playlist_loader::g_load_playlist_filehint(file::ptr fileHint,const char * p_path,playlist_loader_callback & p_callback) { TRACK_CALL_TEXT("playlist_loader::g_load_playlist_filehint"); pfc::string8 filepath; filesystem::g_get_canonical_path(p_path,filepath); pfc::string_extension extension(filepath); service_ptr_t<file> l_file = fileHint; if (l_file.is_empty()) { filesystem::ptr fs; if (filesystem::g_get_interface(fs,filepath)) { if (fs->supports_content_types()) { fs->open(l_file,filepath,filesystem::open_mode_read,p_callback); } } } { service_enum_t<playlist_loader> e; if (l_file.is_valid()) { pfc::string8 content_type; if (l_file->get_content_type(content_type)) { service_ptr_t<playlist_loader> l; e.reset(); while(e.next(l)) { if (l->is_our_content_type(content_type)) { try { TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback)); return; } catch(exception_io_unsupported_format) { l_file->reopen(p_callback); } } } } } if (extension.length()>0) { service_ptr_t<playlist_loader> l; e.reset(); while(e.next(l)) { if (stricmp_utf8(l->get_extension(),extension) == 0) { if (l_file.is_empty()) filesystem::g_open_read(l_file,filepath,p_callback); try { TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback)); return; } catch(exception_io_unsupported_format) { l_file->reopen(p_callback); } } } } } throw exception_io_unsupported_format(); }
void playlist_loader::g_save_playlist(const char * p_filename,const pfc::list_base_const_t<metadb_handle_ptr> & data,abort_callback & p_abort) { TRACK_CALL_TEXT("playlist_loader::g_save_playlist"); pfc::string8 filename; filesystem::g_get_canonical_path(p_filename,filename); try { service_ptr_t<file> r; filesystem::g_open(r,filename,filesystem::open_mode_write_new,p_abort); pfc::string_extension ext(filename); service_enum_t<playlist_loader> e; service_ptr_t<playlist_loader> l; if (e.first(l)) do { if (l->can_write() && !stricmp_utf8(ext,l->get_extension())) { try { TRACK_CODE("playlist_loader::write",l->write(filename,r,data,p_abort)); return; } catch(exception_io_data) {} } } while(e.next(l)); throw exception_io_data(); } catch(...) { try {filesystem::g_remove(filename,p_abort);} catch(...) {} throw; } }
void open_path_helper(input_decoder::ptr & p_input, file::ptr p_file, const char * path,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) { p_abort.check(); p_input.release(); TRACK_CODE("input_entry::g_open_for_decoding", input_entry::g_open_for_decoding(p_input,p_file,path,p_abort,p_from_redirect) ); if (!p_skip_hints) { try { static_api_ptr_t<metadb_io>()->hint_reader(p_input.get_ptr(),path,p_abort); } catch(exception_io_data) { //Don't fail to decode when this barfs, might be barfing when reading info from another subsong than the one we're trying to decode etc. p_input.release(); if (p_file.is_valid()) p_file->reopen(p_abort); TRACK_CODE("input_entry::g_open_for_decoding", input_entry::g_open_for_decoding(p_input,p_file,path,p_abort,p_from_redirect) ); } } }
CMutexScope::CMutexScope(CMutex & mutex, DWORD timeOutMS, const char * timeOutBugMsg) : m_mutex(mutex) { SetLastError(0); const unsigned div = 4; for(unsigned walk = 0; walk < div; ++walk) { switch(WaitForSingleObject( m_mutex.Handle(), timeOutMS/div ) ) { case WAIT_FAILED: WIN32_OP_FAIL_CRITICAL("WaitForSingleObject"); case WAIT_OBJECT_0: return; case WAIT_TIMEOUT: break; default: uBugCheck(); } } TRACK_CODE(timeOutBugMsg, uBugCheck()); }
static void index_tracks_helper(const char * p_path,const service_ptr_t<file> & p_reader,const t_filestats & p_stats,playlist_loader_callback::t_entry_type p_type,playlist_loader_callback::ptr p_callback, abort_callback & p_abort,bool & p_got_input) { TRACK_CALL_TEXT("index_tracks_helper"); if (p_reader.is_empty() && filesystem::g_is_remote_safe(p_path)) { TRACK_CALL_TEXT("remote"); metadb_handle_ptr handle; p_callback->handle_create(handle,make_playable_location(p_path,0)); p_got_input = true; p_callback->on_entry(handle,p_type,p_stats,true); } else { TRACK_CALL_TEXT("hintable"); service_ptr_t<input_info_reader> instance; input_entry::g_open_for_info_read(instance,p_reader,p_path,p_abort); t_filestats stats = instance->get_file_stats(p_abort); t_uint32 subsong,subsong_count = instance->get_subsong_count(); bool bInfoGetError = false; for(subsong=0;subsong<subsong_count;subsong++) { TRACK_CALL_TEXT("subsong-loop"); p_abort.check(); metadb_handle_ptr handle; t_uint32 index = instance->get_subsong(subsong); p_callback->handle_create(handle,make_playable_location(p_path,index)); p_got_input = true; if (! bInfoGetError && p_callback->want_info(handle,p_type,stats,true) ) { file_info_impl info; try { TRACK_CODE("get_info",instance->get_info(index,info,p_abort)); } catch(std::exception const & e) { bInfoGetError = true; } p_callback->on_entry_info(handle,p_type,stats,info,true); } else { p_callback->on_entry(handle,p_type,stats,true); } } } }
void input_helper::open_decoding(t_uint32 subsong, t_uint32 flags, abort_callback & p_abort) { TRACK_CODE("input_decoder::initialize",m_input->initialize(subsong,flags,p_abort)); }
static void process_path_internal(const char * p_path,const service_ptr_t<file> & p_reader,playlist_loader_callback_v2 & p_callback,playlist_loader_callback::t_entry_type p_type,const t_filestats & p_stats) { //p_path must be canonical p_callback.check(); p_callback.on_progress(p_path); { if (p_reader.is_empty()) { directory_callback_impl directory_results(true); try { filesystem::g_list_directory(p_path,directory_results,p_callback); for(t_size n=0;n<directory_results.get_count();n++) { process_path_internal(directory_results.get_item(n),0,p_callback,playlist_loader_callback::entry_directory_enumerated,directory_results.get_item_stats(n)); } return; } catch(exception_aborted) {throw;} catch(...) { //do nothing, fall thru //fixme - catch only filesystem exceptions? } } bool found = false; { archive_callback_impl archive_results(p_callback); service_enum_t<filesystem> e; service_ptr_t<filesystem> f; while(e.next(f)) { p_callback.check(); service_ptr_t<archive> arch; if (f->service_query_t(arch)) { if (p_reader.is_valid()) p_reader->reopen(p_callback); try { TRACK_CODE("archive::archive_list",arch->archive_list(p_path,p_reader,archive_results,true)); return; } catch(exception_aborted) {throw;} catch(...) {} } } } } { service_ptr_t<link_resolver> ptr; if (link_resolver::g_find(ptr,p_path)) { if (p_reader.is_valid()) p_reader->reopen(p_callback); pfc::string8 temp; try { TRACK_CODE("link_resolver::resolve",ptr->resolve(p_reader,p_path,temp,p_callback)); track_indexer__g_get_tracks_wrap(temp,0,filestats_invalid,playlist_loader_callback::entry_from_playlist,p_callback); return;//success } catch(exception_aborted) {throw;} catch(...) {} } } if (p_callback.is_path_wanted(p_path,p_type)) { track_indexer__g_get_tracks_wrap(p_path,p_reader,p_stats,p_type,p_callback); } }
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL() { const DWORD code = GetLastError(); PFC_ASSERT( code != NO_ERROR ); pfc::string_fixed_t<32> debugMsg; debugMsg << "Win32 error #" << (t_uint32)code; TRACK_CODE( debugMsg, throw exception_win32(code) ); }
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL_CRITICAL(const char * what) { const DWORD code = GetLastError(); PFC_ASSERT( code != NO_ERROR ); pfc::string_formatter msg; msg << what << " failure #" << (uint32_t)code; TRACK_CODE(msg.get_ptr(), uBugCheck()); }