bool zip_list_file(std::string zip_file_name, std::string list_file[], std::string list_name[], int num_file) { bool add_zip_status; for(int i = 0; i < num_file; i++){ add_zip_status = add_to_zip(zip_file_name.c_str(), list_file[i].c_str(), list_name[i].c_str()); if(!add_zip_status) return false; } return true; }
static int download_files_thread(void* _data) { char file_name[256]; char comment[64]; download_files_thread_data_t *data = NULL; update_info_t* info = NULL; char* download_buffer = NULL; void* file_buffer = NULL; FILE *file = NULL; Uint64 file_size, size; Uint32 i, len, result, error, count, index, running; Uint32 download_buffer_size; data = (download_files_thread_data_t*)_data; init_thread_log("download_files"); #ifdef WINDOWS file = my_tmpfile(); #else file = tmpfile(); #endif if (file == 0) { return 1; } error = 0; file_buffer = 0; download_buffer_size = 4096; download_buffer = calloc(download_buffer_size, sizeof(char)); count = data->count; while (1) { CHECK_AND_LOCK_MUTEX(data->mutex); do { info = queue_pop(data->files); running = data->running; if ((running == 1) && (info == 0)) { SDL_CondWait(data->condition, data->mutex); } } while ((data->running == 1) && (info == 0)); index = data->index; CHECK_AND_UNLOCK_MUTEX(data->mutex); if (info == 0) { break; } if (data->update_progress_function("Downloading files", count, index, data->user_data) != 1) { CHECK_AND_LOCK_MUTEX(data->mutex); data->running = 0; CHECK_AND_UNLOCK_MUTEX(data->mutex); error = 2; break; } for (i = 0; i < 5; i++) { fseek(file, 0, SEEK_SET); result = download_file(info->file_name, file, data->server, data->path, &size, download_buffer_size, download_buffer, 0, 0); if (result != 0) { LOG_ERROR("Download error %d while updating " "file '%s' from server '%s', retrying" " it", result, info->file_name, data->server); error = 3; continue; } if (file_read(file, size, &file_buffer, &file_size) != 0) { LOG_ERROR("Read error while updating file '%s' " "from server '%s', retrying it", info->file_name, data->server); error = 3; continue; } convert_md5_digest_to_comment_string(info->digest, sizeof(comment), comment); len = strlen(info->file_name); safe_snprintf(file_name, sizeof(file_name), "%s", info->file_name); if (has_suffix(file_name, len, ".xz", 3)) { file_name[len - 3] = 0; } CHECK_AND_LOCK_MUTEX(data->mutex); add_to_zip(file_name, file_size, file_buffer, data->dest, comment); data->index++; CHECK_AND_UNLOCK_MUTEX(data->mutex); free(file_buffer); error = 0; break; } if (error != 0) { break; } } free(download_buffer); fclose(file); return error; }