static void
trg_files_model_iter_update(TrgFilesModel * model,
                            GtkTreeIter * filesIter,
                            JsonObject * file,
                            JsonArray * wantedArray,
                            JsonArray * prioritiesArray, gint id)
{
    TrgFilesModelPrivate *priv = TRG_FILES_MODEL_GET_PRIVATE(model);
    gint64 fileLength = file_get_length(file);
    gint64 fileCompleted = file_get_bytes_completed(file);
    gint64 lastCompleted;

    gint wanted = (gint) json_array_get_int_element(wantedArray, id);
    gint priority = (gint) json_array_get_int_element(prioritiesArray, id);
    gdouble progress = file_get_progress(fileLength, fileCompleted);

    gtk_tree_model_get(GTK_TREE_MODEL(model), filesIter,
                       FILESCOL_BYTESCOMPLETED, &lastCompleted, -1);

    gtk_tree_store_set(GTK_TREE_STORE(model), filesIter, FILESCOL_PROGRESS,
                       progress, FILESCOL_BYTESCOMPLETED, fileCompleted,
                       -1);

    trg_files_update_parent_progress(GTK_TREE_MODEL(model), filesIter,
                                     fileCompleted - lastCompleted);

    if (priv->accept)
        gtk_tree_store_set(GTK_TREE_STORE(model), filesIter,
                           FILESCOL_WANTED, wanted, FILESCOL_PRIORITY,
                           priority, -1);
}
예제 #2
0
void file_read(File *in)
{
	uint8_t *offset = NULL;
	size_t total_read = 0, read = 0;

	in->fp = fopen(in->fullname, "rb");

	if (!in->fp) {
		fprintf(stderr, "Could not open %s\n", in->fullname);
		return;
	}

	file_get_length(in);

	do {
		read = file_remap(in, total_read);
		offset = file_find_chunk(in->data, read, in->chunkString/*, sizeof(in->chunkString)*/);
		total_read += read;
	} while ((total_read < in->len) && !offset);

	if (offset) {
		fprintf(stdout, "Chunk for file (%s) found\n", in->fullname);
		file_write(in, offset, read);
	} else {
		fprintf(stdout, "File (%s) was not trimmed\n", in->fullname);
	}

	fclose(in->fp);
}
static trg_files_tree_node *trg_file_parser_node_insert(trg_files_tree_node
                                                        * top,
                                                        trg_files_tree_node
                                                        * last,
                                                        JsonObject * file,
                                                        gint index,
                                                        JsonArray *
                                                        enabled,
                                                        JsonArray *
                                                        priorities)
{
    gchar **path = g_strsplit(file_get_name(file), "/", -1);
    trg_files_tree_node *lastIter = last;
    GList *parentList = NULL;
    gchar *path_el;
    GList *li;
    int i;

    /* Build up a list of pointers to each parent trg_files_tree_node
     * reversing the order as it iterates over its parent.
     */
    if (lastIter)
        while ((lastIter = lastIter->parent))
            parentList = g_list_prepend(parentList, lastIter);

    li = parentList;
    lastIter = top;

    /* Iterate over the path list which contains each file/directory
     * component of the path in order.
     */
    for (i = 0; (path_el = path[i]); i++) {
        gboolean isFile = !path[i + 1];
        trg_files_tree_node *target_node = NULL;

        /* No point checking for files. If there is a last parents iterator
         * check it for a shortcut. I'm assuming that these come in order of
         * directory at least to give performance a boost.
         */
        if (li && !isFile) {
            trg_files_tree_node *lastPathNode =
                (trg_files_tree_node *) li->data;

            if (!g_strcmp0(lastPathNode->name, path[i])) {
                target_node = lastPathNode;
                li = g_list_next(li);
            } else {
                /* No need to check any further. */
                li = NULL;
            }
        }

        if (!target_node && lastIter && lastIter->childrenHash && !isFile)
          target_node = g_hash_table_lookup(lastIter->childrenHash, path_el);

        /* Node needs creating */

        if (!target_node) {
            target_node = g_new0(trg_files_tree_node, 1);
            target_node->name = g_strdup(path[i]);
            target_node->parent = lastIter;
            trg_files_tree_node_add_child(lastIter, target_node);
        }

        lastIter = target_node;

        /* Files have more properties set here than for files.
         * Directories are updated from here too, by trg_files_tree_update_ancestors
         * working up the parents.
         */
        if (isFile) {
            target_node->length = file_get_length(file);
            target_node->bytesCompleted = file_get_bytes_completed(file);
            target_node->index = index;
            target_node->enabled =
                (gint) json_array_get_int_element(enabled, index);
            target_node->priority =
                (gint) json_array_get_int_element(priorities, index);

            trg_files_tree_update_ancestors(target_node);
        } else {
            target_node->index = -1;
        }
    }

    g_list_free(parentList);
    g_strfreev(path);

    return lastIter;
}
예제 #4
0
 int cache_data_to_svr(char *url, trans_info_t *info)
{
	FILE *iSvrResp = NULL;
	FILE *fStream = NULL;
	char head[20480];
	int  size = 0;
	int len=0;
	char *buffer = NULL, *tmp=NULL;
	int j;

	head[0]=0;
	if(info->opt->is_encrypt == 1) {
		tmp=(char *)malloc(bufferSize(info->cache)+1024);
		buffer = tmp;
		size=bufferEncrypt((char *)info->cache->buffer, bufferSize(info->cache), \
						buffer+8, bufferSize(info->cache)+1024, info->opt->SN, strlen(info->opt->SN));
		((int*)buffer)[1] = bufferSize(info->cache);
		strcpy(buffer,"LZO1");
		size += 8;
	} else {
		buffer = (char *)info->cache->buffer;
		size = bufferSize(info->cache);
	}

	if( NULL != info->file_path) {
		fStream = fopen(info->file_path,"rb");
		if (fStream != NULL) {
			len = file_get_length(fStream);
		}
		buffer[size]=0;
		size++;
	}
	/*如果发送数据后,没有收到服务器确认信息,将重发,三次都失败后,认为发送失败*/
	for (j=0; j<3;  j++) {
		iSvrResp = http_proc(url,head,buffer,size, fStream, \
							((size+len)>10*1024)?info->opt->websvr_time_out*4:info->opt->websvr_time_out,\
							info->opt->send_buf_size);
		if (svr_res_proc(iSvrResp,info,head)) {
			printf("[PUSH SDK]    UPLOAD %s(%d) INFO SUCESS\n\n",info->list->table_name,info->count);
			if (info->file_path != NULL) {
				printf("[PUSH SDK]    UPLOAD  %s(%s) FILE SUCESS\n\n",info->list->table_name,info->file_path);
			}
			pipe_write_to_parent_cmd(CHILD_CMD_ONLINE);
			break;
		}
		printf("[PUSH SDK]    TRANS  %s (%d)TIMES FAILED\n\n",info->list->table_name,j+1);
		msleep(300*(j+1));
	}

	if (fStream) {
		fclose(fStream);
	}
	if (tmp != NULL) {
		free(tmp);
	}

	if (j > 2) {
		pipe_write_to_parent_cmd(CHILD_CMD_OFFLINE);
		return 0;
	} else {
		return 1;
	}
}