Beispiel #1
0
/**
  * Meniul de navigare in fisiere
  */
void printdirs(struct DIR * dir){
	char namebuf [12];
	uint32_t size = 0;
	uint8_t bitmap = 0, selected = 0, cnt = 0, ret_code = 0, is=0;
	struct dirent * crt_dir;

	do{
		/* Afisam continutul directorului curent */
		rewinddir(dir);
		LCD_clear();
		cnt = 0;
		while(1){
			crt_dir = readdir( dir, buffer);
			ret_code = check (crt_dir);
			if(ret_code == DIR_INVALID)
				continue;
			if(ret_code == DIR_END)
				break;

			get_dirent_name(crt_dir, namebuf);
			if(cnt ++ == selected){
				LCD_str( namebuf,SELECTED );
			}else{
				LCD_str( namebuf, NOT_SELECTED);
			}
		}

		/* Asteptam sa selecteze un fisier sau director */
		bitmap = BTN_wait();

		switch(bitmap){
			case UP:
				selected = (selected +1)%cnt;
				continue;
			case DOWN:
				selected = (selected + cnt-1) % cnt;
				continue;
			case ENTER:
				rewinddir(dir);
				selected ++;
				while(1){
					crt_dir = readdir( dir, buffer);
					ret_code = check (crt_dir);
					if( ret_code == DIR_VALID) selected--;
					if( !selected ) break;
				}
				break;
			default:
				continue;

		}

		is_dir(crt_dir, &is);
		if( is){
			dir = opendir(crt_dir);
		}else{
			get_dirent_size(crt_dir, &size);
			open_f(crt_dir);

			/* Curatam ecranul si afisam poza */
			LCD_clear();
			draw_bmp();
			close_f();

			/* Asteptam sa apese butonul de exit */
			while( BTN_wait() != CLOSE);
		}
	}while(1);
	exit(EXIT_SUCCESS);
}
Beispiel #2
0
static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
  int len = 0,resp;
  struct stream_priv_s* p = (struct stream_priv_s*)opts;
  char str[256],rsp_txt[256];

  if(mode != STREAM_READ) {
    mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] Unknown open mode %d\n",mode);
    m_struct_free(&stream_opts,opts);
    return STREAM_UNSUPPORTED;
  }

  if(!p->filename || !p->host) {
    mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] Bad url\n");
    m_struct_free(&stream_opts,opts);
    return STREAM_ERROR;
  }

  // Open the control connection
  p->handle = connect2Server(p->host,p->port,1);
  
  if(p->handle < 0) {
    m_struct_free(&stream_opts,opts);
    return STREAM_ERROR;
  }

  // We got a connection, let's start serious things
  stream->fd = -1;
  stream->priv = p;
  p->buf = malloc(BUFSIZE);

  if (readresp(p, NULL) == 0) {
    close_f(stream);
    m_struct_free(&stream_opts,opts);
    return STREAM_ERROR;
  }

  // Login
  snprintf(str,255,"USER %s",p->user);
  resp = FtpSendCmd(str,p,rsp_txt);

  // password needed
  if(resp == 3) {
    snprintf(str,255,"PASS %s",p->pass);
    resp = FtpSendCmd(str,p,rsp_txt);
    if(resp != 2) {
      mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] command '%s' failed: %s\n",str,rsp_txt);
      close_f(stream);
      return STREAM_ERROR;
    }
  } else if(resp != 2) {
    mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] command '%s' failed: %s\n",str,rsp_txt);
    close_f(stream);
    return STREAM_ERROR;
  }
    
  // Set the transfer type
  resp = FtpSendCmd("TYPE I",p,rsp_txt);
  if(resp != 2) {
    mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command 'TYPE I' failed: %s\n",rsp_txt);
    close_f(stream);
    return STREAM_ERROR;
  }

  // Get the filesize
  snprintf(str,255,"SIZE %s",p->filename);
  resp = FtpSendCmd(str,p,rsp_txt);
  if(resp != 2) {
    mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command '%s' failed: %s\n",str,rsp_txt);
  } else {
    int dummy;
    sscanf(rsp_txt,"%d %d",&dummy,&len);
  }

  if(len > 0) {
    stream->seek = seek;
    stream->end_pos = len;
  }

  // The data connection is really opened only at the first
  // read/seek. This must be done when the cache is used
  // because the connection would stay open in the main process,
  // preventing correct abort with many servers.
  stream->fd = -1;
  stream->priv = p;
  stream->fill_buffer = fill_buffer;
  stream->close = close_f;

  return STREAM_OK;
}