void make_path(const char * parent,const char * filename,const char * extension,bool allow_new_dirs,pfc::string8 & out,bool really_create_dirs,abort_callback & p_abort)
{
    out.reset();
    if (parent && *parent)
    {
        out = parent;
        out.fix_dir_separator('\\');
    }
    bool last_char_is_dir_sep = true;
    while(*filename)
    {
#ifdef WIN32
        if (allow_new_dirs && is_bad_dirchar(*filename))
        {
            const char * ptr = filename+1;
            while(is_bad_dirchar(*ptr)) ptr++;
            if (*ptr!='\\' && *ptr!='/') out.add_string(filename,ptr-filename);
            filename = ptr;
            if (*filename==0) break;
        }
#endif
        if (pfc::is_path_bad_char(*filename))
        {
            if (allow_new_dirs && (*filename=='\\' || *filename=='/'))
            {
                if (!last_char_is_dir_sep)
                {
                    if (really_create_dirs) try {
                            filesystem::g_create_directory(out,p_abort);
                        }
                        catch(exception_io_already_exists) {}
                    out.add_char('\\');
                    last_char_is_dir_sep = true;
                }
            }
            else
                out.add_char('_');
        }
        else
        {
            out.add_byte(*filename);
            last_char_is_dir_sep = false;
        }
        filename++;
    }
    if (out.length()>0 && out[out.length()-1]=='\\')
    {
        out.add_string("noname");
    }
    if (extension && *extension)
    {
        out.add_char('.');
        out.add_string(extension);
    }
}
void toolbar_extension::button::custom_image::get_path(pfc::string8 & p_out) const
{
	p_out.reset();

	bool b_absolute = pfc::string_find_first(m_path, ':') != pfc_infinite || (m_path.length() > 1 && m_path.get_ptr()[0] == '\\' && m_path.get_ptr()[1] == '\\');
	bool b_relative_to_drive = !b_absolute && m_path.get_ptr()[0] == '\\';

	pfc::string8 fb2kexe;
	uGetModuleFileName(NULL, fb2kexe);
	//pfc::string8 fullPath;

	if (b_relative_to_drive)
	{
		t_size index_colon = fb2kexe.find_first(':');
		if (index_colon != pfc_infinite)
			p_out.add_string(fb2kexe.get_ptr(), index_colon + 1);
	}
	else if (!b_absolute)
		p_out << pfc::string_directory(fb2kexe) << "\\";
	p_out += m_path;
}
bool find_menu_path( GUID & parent, pfc::string8 & out )
{
   if ( parent == pfc::guid_null )
   {
      out.set_string( "main menu" );
      return true;
   }
   else
   {
      service_enum_t<mainmenu_group> e;
	   service_ptr_t<mainmenu_group> ptr;

      while ( e.next( ptr ) )
      {
         if ( ptr->get_guid() == parent )
         {
            pfc::string8 tmp;

            service_ptr_t<mainmenu_group_popup> popup;

            if ( ptr->service_query_t( popup ) )
            {
               popup->get_display_string( tmp );  
               find_menu_path( ptr->get_parent(), out );
               out.add_string( "/" );
               out.add_string( tmp );
               return true;
            }
            else
            {
               find_menu_path( ptr->get_parent(), out );
               return true;
            }
         }
      }
   }

   out.set_string( "main menu" );
   return false;
}