Ejemplo n.º 1
0
static char*
mime_part_get_filename (GMimeObject *mobj, unsigned index,
			gboolean construct_if_needed)
{
	gchar *fname;

	fname = NULL;

	if (GMIME_IS_PART (mobj)) {
		/* the easy case: the part has a filename */
		fname = (gchar*)g_mime_part_get_filename (GMIME_PART(mobj));
		if (fname) /* don't include directory components */
			fname = g_path_get_basename (fname);
	}

	if (!fname && !construct_if_needed)
		return NULL;

	if (GMIME_IS_MESSAGE_PART(mobj)) {
		GMimeMessage *msg;
		const char *subj;
		msg  = g_mime_message_part_get_message
			(GMIME_MESSAGE_PART(mobj));
		subj = g_mime_message_get_subject (msg);
		fname = g_strdup_printf ("%s.eml", subj ? subj : "message");
	}

	if (!fname)
		fname =	g_strdup_printf ("%u.part", index);

	/* remove slashes, spaces, colons... */
	cleanup_filename (fname);
	return fname;
}
Ejemplo n.º 2
0
Archivo: gui.c Proyecto: OrangeTide/fed
int add_to_filelist(char *f, int d)
{
   FILENODE *pos, *prev, *node;
   char fn[256];

   strcpy(fn, f);
   cleanup_filename(fn);

   node = malloc(sizeof(FILENODE) + strlen(fn) + 1);
   if (!node)
      return (errno = ENOMEM);

   strcpy(node->name, fn);

   prev = NULL;
   pos = filenode;

   while (pos) {
      if (((node->name[strlen(node->name)-1] == '\\') && (pos->name[strlen(pos->name)-1] != '\\')) ||
	  ((node->name[strlen(node->name)-1] == '/') && (pos->name[strlen(pos->name)-1] != '/')) ||
	  (stricmp(pos->name, node->name) > 0))
	 break;
      prev = pos;
      pos = pos->next;
   }

   node->next = pos;
   if (prev)
      prev->next = node;
   else
      filenode = node;

   filebox.count++;
   return 0;
}
Ejemplo n.º 3
0
Archivo: gui.c Proyecto: OrangeTide/fed
int select_file(char *prompt, char *fname)
{
   int ret;
   static char p[256] = "";

   filebox.h = screen_h - 10;
   filebox.height = screen_h - 14;
   filebox.w = MAX(screen_w - 16, 32);
   filebox.slen = filebox.w - 8;

   draw_box(prompt, 7, 2, filebox.w, 5, TRUE);

   draw_listbox(&filebox);
   hi_vid();
   goto1(7,6);
   pch(LJOIN_CHAR);
   goto1(filebox.w+6,6);
   pch(RJOIN_CHAR);

   if (!fname[0]) {
      if (p[0])
	 strcpy(fname, p);
      else
	 getcwd(fname, 256);

      cleanup_filename(fname);
      append_backslash(fname);
   }

   fill_filelist(fname);

   goto1(12, 4);
   ret = do_input_text(fname, 255, 54, is_filechar, fsel_proc, TRUE, fsel_mouse);

   if (ret != ESC) {
      strcpy(p, fname);
      *get_fname(p) = 0;
   }

   n_vid();
   empty_filelist();
   dirty_everything();
   return ret;
}
Ejemplo n.º 4
0
/**
 * Filename generator
 *
 * - convert from utf8
 * - avoid duplicate filenames
 *
 */
static int
pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
{
  char fullname[PATH_MAX];
  char path[PATH_MAX];
  int tally = 0;
  struct stat st;
  char *filename, *s;
  struct tm tm;
  dvr_config_t *cfg;

  if (de == NULL)
    return -1;

  cfg = de->de_config;
  strncpy(path, cfg->dvr_storage, sizeof(path));
  path[sizeof(path)-1] = '\0';

  /* Remove trailing slash */
  if (path[strlen(path)-1] == '/')
    path[strlen(path)-1] = '\0';

  /* Append per-day directory */
  if (cfg->dvr_dir_per_day) {
    localtime_r(&de->de_start, &tm);
    strftime(fullname, sizeof(fullname), "%F", &tm);
    s = cleanup_filename(fullname, cfg);
    if (s == NULL)
      return -1;
    snprintf(path + strlen(path), sizeof(path) - strlen(path), "/%s", s);
    free(s);
  }

  /* Append per-channel directory */
  if (cfg->dvr_channel_dir) {
    char *chname = strdup(DVR_CH_NAME(de));
    s = cleanup_filename(chname, cfg);
    free(chname);
    if (s == NULL)
      return -1;
    snprintf(path + strlen(path), sizeof(path) - strlen(path), "/%s", s);
    free(s);
  }

  // TODO: per-brand, per-season

  /* Append per-title directory */
  if (cfg->dvr_title_dir) {
    char *title = strdup(lang_str_get(de->de_title, NULL));
    s = cleanup_filename(title, cfg);
    free(title);
    if (s == NULL)
      return -1;
    snprintf(path + strlen(path), sizeof(path) - strlen(path), "/%s", s);
    free(s);
  }

  if (makedirs(path, cfg->dvr_muxcnf.m_directory_permissions) != 0)
    return -1;
  
  /* Construct final name */
  dvr_make_title(fullname, sizeof(fullname), de);
  filename = cleanup_filename(fullname, cfg);
  if (filename == NULL)
    return -1;
  snprintf(fullname, sizeof(fullname), "%s/%s.%s",
	   path, filename, muxer_suffix(de->de_chain->prch_muxer, ss));

  while(1) {
    if(stat(fullname, &st) == -1) {
      tvhlog(LOG_DEBUG, "dvr", "File \"%s\" -- %s -- Using for recording",
	     fullname, strerror(errno));
      break;
    }

    tvhlog(LOG_DEBUG, "dvr", "Overwrite protection, file \"%s\" exists", 
	   fullname);

    tally++;

    snprintf(fullname, sizeof(fullname), "%s/%s-%d.%s",
	     path, filename, tally, muxer_suffix(de->de_chain->prch_muxer, ss));
  }
  free(filename);

  tvh_str_set(&de->de_filename, fullname);

  return 0;
}
Ejemplo n.º 5
0
Archivo: gui.c Proyecto: OrangeTide/fed
void fill_filelist(char *path)
{
   char b[256];
   int c;
   FILENODE *node;
   int redraw = FALSE;
   int old;

   strcpy(b, path);
 #if (defined TARGET_DJGPP) || (defined TARGET_WIN)
   strcpy(get_fname(b), "*.*");
 #else
   strcpy(get_fname(b), "*");
 #endif
   cleanup_filename(b);

   if (stricmp(b, filepath) != 0) {
      empty_filelist();
      do_for_each_file(b, add_to_filelist, 0);
      do_for_each_directory(b, add_to_filelist, 0);

      if (filebox.count > 0) {
	 filebox.data = malloc(sizeof(LISTITEM)*filebox.count);
	 if (filebox.data) {
	    node = filenode;
	    for (c=0; c<filebox.count; c++) {
	       filebox.data[c].text = node->name;
	       filebox.data[c].data = -1;
	       filebox.data[c].click_proc = NULL;
	       filebox.data[c].draw_proc = NULL;
	       filebox.data[c].comment = NULL;
	       node = node->next;
	    }
	 }
	 else
	    errno = ENOMEM;
      }

      redraw = TRUE;
      strcpy(filepath, b);
   }

   old = filebox.current;
   filebox.current = -1;

   if (path[0]) {
      char *p = get_fname(path);
      int len = strlen(p);
      if (p[0]) {
	 for (c=0; c<filebox.count; c++) {
	    if (strnicmp(p, get_fname(filebox.data[c].text), len)==0) {
	       filebox.current = c;
	       break;
	    } 
	 }
      }
   }

   if (filebox.current != old) {
      if (filebox.current != -1) {
	 while (filebox.current < filebox.scroll)
	    filebox.scroll--;
	 while (filebox.current >= filebox.scroll+filebox.height)
	    filebox.scroll++;
      }
      redraw = TRUE;
   }

   if (redraw) {
      if (errno==0)
	 draw_contents(&filebox);
      else {
	 filebox.current = -1;
	 filebox.count = -1;
	 draw_contents(&filebox);
	 hi_vid();
	 goto1(filebox.x+filebox.xoff+1, filebox.y+filebox.yoff);
	 mywrite("Error: ");
	 mywrite(err());
      }
   }
}