Exemplo n.º 1
0
std::wstring LyricSourceLRC::getSavePath(const metadb_handle_ptr &track)
{
    std::string path = track->get_path();
    std::wstring wpath = EncodingFunc::ToUTF16(path.substr(boost::find_last(path, "://").end() - path.begin()));
    wpath = wpath.substr(0, wpath.find_last_of(L"."));
    if(track->get_subsong_index() != 0)
        wpath += boost::lexical_cast<std::wstring>(track->get_subsong_index());
    wpath += L".lrc";
    if(m_config["lrcsavepath"].length())
    {
        class LRCTitleFormatCallback : public main_thread_callback
        {
        private:
            HANDLE m_event;
            std::string *m_out;
            const std::string &m_format;
            const metadb_handle_ptr &m_track;
        public:
            LRCTitleFormatCallback(HANDLE event, std::string *out, const std::string &format, const metadb_handle_ptr &track) : m_event(event), m_format(format), m_out(out), m_track(track) {}

            virtual void callback_run()
            {
                core_api::ensure_main_thread();
                pfc::string8 out;
                service_ptr_t<titleformat_object> script;
                static_api_ptr_t<titleformat_compiler>()->compile(script, m_format.c_str());
                m_track->format_title(NULL, out, script, NULL);
                m_out->assign(out.get_ptr());
                SetEvent(m_event);
            }
        };
        std::wstring dirname = wpath.substr(0, wpath.find_last_of(L'\\') + 1);
        std::wstring filename = wpath.substr(wpath.find_last_of(L"\\") + 1);
        HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL);
        std::string out;
        std::string pathtmp = m_config["lrcsavepath"];
        if(pathtmp.at(pathtmp.length() - 1) != '\\')
            pathtmp += '\\';
        service_ptr_t<LRCTitleFormatCallback> p_callback = new service_impl_t<LRCTitleFormatCallback>(event, &out, pathtmp, track);
        static_api_ptr_t<main_thread_callback_manager>()->add_callback(p_callback);
        p_callback.release();
        WaitForSingleObject(event, INFINITE);
        CloseHandle(event);
        wpath = EncodingFunc::ToUTF16(out);
        if(PathIsRelative(wpath.c_str()))
            wpath = dirname + wpath;
        if(GetFileAttributes(wpath.c_str()) & FILE_ATTRIBUTE_DIRECTORY && (GetLastError() != ERROR_FILE_NOT_FOUND && GetLastError() != ERROR_PATH_NOT_FOUND))
            wpath += filename;
        return wpath;
    }

    if(path.find_first_of("file://") == std::string::npos)
        return std::wstring(L"");
    if(path.find_first_of("unpack://") == std::string::npos)
        return std::wstring(L"");
    return wpath;
}
Exemplo n.º 2
0
void metadb::handle_create_replace_path_canonical(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path) {
	handle_create(p_out,make_playable_location(p_new_path,p_source->get_subsong_index()));
}