gpointer tag_reader_main (TagReader *self) { while (self->priv->run) { QueueEntry *entry; if (self->priv->p) { if (g_async_queue_length (self->priv->job_queue) == 0) { shell_remove_progress (self->priv->shell, self->priv->p); g_object_unref (self->priv->p); self->priv->p = NULL; self->priv->total = 0; self->priv->done = 0; } else { gchar *new_str = g_strdup_printf ("%d of %d", self->priv->done, self->priv->total); progress_set_text (self->priv->p, new_str); progress_set_percent (self->priv->p, (gdouble) self->priv->done / (gdouble) self->priv->total); g_free (new_str); } } entry = g_async_queue_pop (self->priv->job_queue); if (!entry || !self->priv->run) continue; if (!self->priv->p) { self->priv->p = progress_new ("Importing..."); shell_add_progress (self->priv->shell, self->priv->p); gchar *new_str = g_strdup_printf ("%d of %d", self->priv->done, self->priv->total); progress_set_text (self->priv->p, new_str); progress_set_percent (self->priv->p, (gdouble) self->priv->done / (gdouble) self->priv->total); g_free (new_str); } gboolean has_video; gchar **kvs = tag_reader_get_tags (self, entry->location, &has_video); if (kvs) { if (entry->mtype) { shell_move_to (self->priv->shell, kvs, entry->mtype); } else { if (has_video) { shell_move_to (self->priv->shell, kvs, "Movies"); } else { shell_move_to (self->priv->shell, kvs, "Music"); } } g_strfreev (kvs); kvs = NULL; } if (entry->location) { g_free (entry->location); } if (entry->mtype) { g_free (entry->mtype); } g_free (entry); self->priv->done++; } }
int dump_data(UrlResource *rsrc, int sock, FILE *out, libnet_callback notify) { Progress *p = NULL; int bytes_read = 0; ssize_t written = 0; char *buf = NULL; int lenth, final, final2 = 0; int buflen; if ((out == NULL) && (rsrc->buffer == NULL) && (NULL == rsrc->strfile_handle)) return 0; /* if we already have all of it */ if ( !(rsrc->options ) ) { if ( rsrc->outfile_size &&(rsrc->outfile_offset >= rsrc->outfile_size) ) { LIBNET_DEBUG( "you already have all of `%s', skipping", rsrc->outfile); //S_CLOSE(sock); return 0; } } p = progress_new(); p->tranfer_callback = notify; if(NULL == rsrc->strfile_handle) { progress_init(p, rsrc, rsrc->outfile_size); progress_update(p, rsrc->outfile_offset); buflen = BUFSIZE; }else { progress_init(p, rsrc, rsrc->outfile_size); buflen = BUFSIZE * 3; } p->offset = rsrc->outfile_offset; if ( out && (rsrc->outfile_offset > 0) && (rsrc->options & OPT_RESUME)) { fseek(out, rsrc->outfile_offset, SEEK_SET); LIBNET_DEBUG("ftell = %d \n", ftell(out)); } buf = MALLOC(buflen); if(rsrc->strfile_handle) { fd_set set; struct timeval tv = {30, 0}; FD_ZERO(&set); FD_SET(sock, &set); while (lwip_select(sock + 1, &set, NULL, NULL, &tv) > 0 && (rsrc->running)) { bytes_read = S_READ(sock, buf, buflen); if(0 >= bytes_read) break; lenth = bytes_read; final += bytes_read; final2 += bytes_read; while(lenth) { written = httpstrfile_writedatatobuff(rsrc->strfile_handle, buf + (bytes_read - lenth), (UINT32)lenth); lenth -= written; osal_task_sleep(1); } if(0x20000 <= final2) { // libc_printf("final = %d/%d\n", final, rsrc->outfile_size); progress_update(p, final2); final2 = 0; } }