bool rarch_task_push_image_load(const char *fullpath, const char *type, rarch_task_callback_t cb, void *user_data)
{
#if defined(HAVE_RPNG) && defined(HAVE_MENU)
   rarch_task_t *t;
   nbio_handle_t *nbio;
   uint32_t cb_type_hash        = 0;
   struct nbio_t* handle        = NULL;

   cb_type_hash = djb2_calculate(type);

   handle = nbio_open(fullpath, NBIO_READ);

   if (!handle)
   {
      RARCH_ERR("[image load] Failed to open '%s': %s.\n", fullpath, strerror(errno));
      return false;
   }

   nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
   nbio->handle       = handle;
   nbio->is_finished  = false;
   nbio->cb           = &cb_nbio_default;
   nbio->status       = NBIO_STATUS_TRANSFER;
   nbio->image.status = NBIO_IMAGE_STATUS_TRANSFER;


   if (cb_type_hash == CB_MENU_WALLPAPER)
      nbio->cb = &cb_nbio_image_menu_wallpaper;
   else if (cb_type_hash == CB_MENU_BOXART)
      nbio->cb = &cb_nbio_image_menu_boxart;

   nbio_begin_read(handle);

   t = (rarch_task_t*)calloc(1, sizeof(*t));
   t->state = nbio;
   t->handler = rarch_task_file_load_handler;
   t->callback = cb;
   t->user_data = user_data;

   rarch_task_push(t);
#endif
   return true;
}
Exemple #2
0
bool rarch_task_push_decompress(const char *source_file, const char *target_dir,
      const char *subdir, const char *valid_ext, rarch_task_callback_t cb, void *user_data)
{
   decompress_state_t *s;
   rarch_task_t *t;
   char tmp[PATH_MAX_LENGTH];
   bool is_compressed = false;

   if (!target_dir || !target_dir[0] || !source_file || !source_file[0])
   {
      RARCH_WARN("[decompress] Empty or null source file or target directory arguments.\n");
      return false;
   }

   /* ZIP or APK only */
   is_compressed = !strcmp("zip", path_get_extension(source_file));
   is_compressed = !is_compressed ? !strcmp("apk", path_get_extension(source_file)) : is_compressed;

   if (!path_file_exists(source_file) || !is_compressed)
   {
      RARCH_WARN("[decompress] File '%s' does not exist or is not a compressed file.\n",
            source_file);
      return false;
   }

   if (!valid_ext || !valid_ext[0])
      valid_ext = NULL;

   if (rarch_task_find(rarch_task_decompress_finder, (void*)source_file))
   {
      RARCH_LOG("[decompress] File '%s' already being decompressed.\n", source_file);
      return false;
   }

   s = (decompress_state_t*)calloc(1, sizeof(*s));

   s->source_file = strdup(source_file);
   s->target_dir  = strdup(target_dir);

   s->valid_ext = valid_ext ? strdup(valid_ext) : NULL;
   s->zlib.type = ZLIB_TRANSFER_INIT;

   t = (rarch_task_t*)calloc(1, sizeof(*t));
   t->state     = s;
   t->handler   = rarch_task_decompress_handler;

   if (!string_is_empty(subdir))
   {
      s->subdir   = strdup(subdir);
      t->handler   = rarch_task_decompress_handler_subdir;
   }

   t->callback  = cb;
   t->user_data = user_data;

   snprintf(tmp, sizeof(tmp), "%s '%s'", msg_hash_to_str(MSG_EXTRACTING), path_basename(source_file));
   t->title = strdup(tmp);

   rarch_task_push(t);

   return true;
}