예제 #1
0
/* Try to open a file for reading. If the filename ends in one of the
   defined compressor extensions, pipe the file through the decompressor */
struct timidity_file *try_to_open(char *name, int decompress)
{
    struct timidity_file *tf;
    URL url;
    int len;

    if((url = url_arc_open(name)) == NULL)
      if((url = url_open(name)) == NULL)
	return NULL;

    tf = (struct timidity_file *)safe_malloc(sizeof(struct timidity_file));
    tf->url = url;
    tf->tmpname = NULL;

    len = strlen(name);
    if(decompress && len >= 3 && strcasecmp(name + len - 3, ".gz") == 0)
    {
	int method;

	if(!IS_URL_SEEK_SAFE(tf->url))
	{
	    if((tf->url = url_cache_open(tf->url, 1)) == NULL)
	    {
		close_file(tf);
		return NULL;
	    }
	}

	method = skip_gzip_header(tf->url);
	if(method == ARCHIVEC_DEFLATED)
	{
	    url_cache_disable(tf->url);
	    if((tf->url = url_inflate_open(tf->url, -1, 1)) == NULL)
	    {
		close_file(tf);
		return NULL;
	    }

	    /* success */
	    return tf;
	}
	/* fail */
	url_rewind(tf->url);
	url_cache_disable(tf->url);
    }

#ifdef __W32__
    /* Sorry, DECOMPRESSOR_LIST and PATCH_CONVERTERS are not worked yet. */
    return tf;
#endif /* __W32__ */

#if defined(DECOMPRESSOR_LIST)
    if(decompress)
    {
	static char *decompressor_list[] = DECOMPRESSOR_LIST, **dec;
	char tmp[1024];

	/* Check if it's a compressed file */
	for(dec = decompressor_list; *dec; dec += 2)
	{
	    if(!check_file_extension(name, *dec, 0))
		continue;

	    tf->tmpname = url_dumpfile(tf->url, *dec);
	    if (tf->tmpname == NULL) {
		close_file(tf);
		return NULL;
	    }

	    url_close(tf->url);
	    snprintf(tmp, sizeof(tmp), *(dec+1), tf->tmpname);
	    if((tf->url = url_pipe_open(tmp)) == NULL)
	    {
		close_file(tf);
		return NULL;
	    }

	    break;
	}
    }
#endif /* DECOMPRESSOR_LIST */

#if defined(PATCH_CONVERTERS)
    if(decompress == 2)
    {
	static char *decompressor_list[] = PATCH_CONVERTERS, **dec;
	char tmp[1024];

	/* Check if it's a compressed file */
	for(dec = decompressor_list; *dec; dec += 2)
	{
	    if(!check_file_extension(name, *dec, 0))
		continue;

	    tf->tmpname = url_dumpfile(tf->url, *dec);
	    if (tf->tmpname == NULL) {
		close_file(tf);
		return NULL;
	    }

	    url_close(tf->url);
	    sprintf(tmp, *(dec+1), tf->tmpname);
	    if((tf->url = url_pipe_open(tmp)) == NULL)
	    {
		close_file(tf);
		return NULL;
	    }

	    break;
	}
    }
#endif /* PATCH_CONVERTERS */
    
    return tf;
}
예제 #2
0
파일: smfconv.c 프로젝트: jdieter/xbmc
/* return 0 (successful or not convert)
          -1 (error and lost tf->url) */
int smfconv_w32(struct timidity_file *tf, char *fn)
{
    URL url;
    int ret;
    struct midi_file_info *infop;

    /* rcpcv.dll convertion stage */
rcpcv_dll_stage:
    if(exist_rcpcv_dll())
    {

        ret = is_midifile_filename(fn);
        if(ret == IS_RCP_FILE || ret == IS_R36_FILE || ret == IS_G18_FILE || ret == IS_G36_FILE)
        {
            if(!IS_URL_SEEK_SAFE(tf->url))
                tf->url = url_cache_open(tf->url, 1);
            ret = is_midifile_url(tf->url);
            url_rewind(tf->url);
            if(ret == IS_RCP_FILE || ret == IS_R36_FILE || ret == IS_G18_FILE || ret == IS_G36_FILE)
            {
                ctl->cmsg(CMSG_INFO,VERB_NORMAL,"Try to Convert RCP,R36,G18,G36 to SMF by RCPCV.DLL (c)1997 Fumy.");
                url = rcpcv_convert(tf->url,ret);
                if(url == NULL) {
                    /* url_arc or url_cash is buggy ? */
                    /*
                    url_rewind(tf->url);
                    url_cache_disable(tf->url);
                    ctl->cmsg(CMSG_INFO,VERB_NORMAL,"Convert Failed.");
                    goto end_of_rcpcv_dll_stage;
                    */

                    char *buffer;
                    int len;
                    URL new_url;

                    url_rewind(tf->url);
                    if((buffer = (char *)url2mem(tf->url,&len))==NULL) {
                        ctl->cmsg(CMSG_INFO,VERB_NORMAL,"Convert Failed.");
                        goto end_of_rcpcv_dll_stage;
                    }
                    if((new_url=url_mem_open(buffer,len,1))==NULL) {
                        ctl->cmsg(CMSG_INFO,VERB_NORMAL,"Convert Failed and Memory Allocate Error.");
                        url_cache_disable(tf->url);
                        return -1;
                    }
                    url_close(tf->url);
                    tf->url = new_url;
                    ctl->cmsg(CMSG_INFO,VERB_NORMAL,"Convert Failed.");
                    goto end_of_rcpcv_dll_stage;
                }
                url_cache_disable(tf->url);
                tf->url = url;
                ctl->cmsg(CMSG_INFO,VERB_NORMAL,"Convert Completed.");

                /* Store the midi file type information */
                infop = get_midi_file_info(fn, 1);
                infop->file_type = ret;
            } else
                url_cache_disable(tf->url);
        }

    }
    /* end of rcpcv.dll convertion stage */
end_of_rcpcv_dll_stage:

    /* smfk32.dll convertion stage */
smfk32_dll_stage:

    /* not exist */

    /* end of smfk32.dll convertion stage */
end_of_smfk32_dll_stage:

last_stage:
    return 0;
}