bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task_callback_t cb, void *user_data) { char tmp[PATH_MAX_LENGTH]; task_finder_data_t find_data; struct http_connection_t *conn = NULL; rarch_task_t *t = NULL; http_handle_t *http = NULL; if (string_is_empty(url)) return false; find_data.func = rarch_task_http_finder; find_data.userdata = (void*)url; /* Concurrent download of the same file is not allowed */ if (task_ctl(TASK_CTL_FIND, &find_data)) { RARCH_LOG("[http] '%s'' is already being downloaded.\n", url); return false; } conn = net_http_connection_new(url); if (!conn) return false; http = (http_handle_t*)calloc(1, sizeof(*http)); if (!http) goto error; http->connection.handle = conn; http->connection.cb = &cb_http_conn_default; if (type) strlcpy(http->connection.elem1, type, sizeof(http->connection.elem1)); http->status = HTTP_STATUS_CONNECTION_TRANSFER; t = (rarch_task_t*)calloc(1, sizeof(*t)); if (!t) goto error; t->handler = rarch_task_http_transfer_handler; t->state = http; t->callback = cb; t->user_data = user_data; t->progress = -1; snprintf(tmp, sizeof(tmp), "%s '%s'", msg_hash_to_str(MSG_DOWNLOADING), path_basename(url)); t->title = strdup(tmp); task_ctl(TASK_CTL_PUSH, t); return true; error: if (conn) net_http_connection_free(conn); if (t) free(t); if (http) free(http); return false; }
bool rarch_task_push_decompress( const char *source_file, const char *target_dir, const char *target_file, const char *subdir, const char *valid_ext, rarch_task_callback_t cb, void *user_data) { task_finder_data_t find_data; char tmp[PATH_MAX_LENGTH]; decompress_state_t *s = NULL; rarch_task_t *t = NULL; bool is_compressed = false; if (string_is_empty(target_dir) || string_is_empty(source_file)) { RARCH_WARN("[decompress] Empty or null source file or" " target directory arguments.\n"); return false; } /* ZIP or APK only */ is_compressed = string_is_equal(path_get_extension(source_file), "zip"); is_compressed = is_compressed || string_is_equal(path_get_extension(source_file), "apk"); 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; find_data.func = rarch_task_decompress_finder; find_data.userdata = (void*)source_file; if (task_ctl(TASK_CTL_FIND, &find_data)) { RARCH_LOG("[decompress] File '%s' already being decompressed.\n", source_file); return false; } RARCH_LOG("[decompress] File '%s.\n", source_file); s = (decompress_state_t*)calloc(1, sizeof(*s)); if (!s) goto error; 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)); if (!t) goto error; 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; } else if (!string_is_empty(target_file)) { s->target_file = strdup(target_file); t->handler = rarch_task_decompress_handler_target_file; } 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); task_ctl(TASK_CTL_PUSH, t); return true; error: if (s) free(s); if (t) free(t); return false; }