📄 transfer.c
字号:
memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); str = g_strdup_printf ( _("File %s has changed.\nWould you like to upload it?"), ve_proc->remote_filename); MakeYesNoDialog (_("Edit File"), str, do_upload, ve_proc, dont_upload, ve_proc); g_free (str); continue; } } free_edit_data (ve_proc); continue; } } }}static voidon_next_transfer (gftp_transfer * tdata){ int fd; intptr_t refresh_files; gftp_file * tempfle; tdata->next_file = 0; for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) { tempfle = tdata->updfle->data; if (tempfle->is_fd) fd = tempfle->fd; else fd = 0; if (tempfle->done_view) { if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, tempfle->file, NULL); if (tempfle->is_fd) { close (tempfle->fd); tempfle->fd = -1; } } else if (tempfle->done_edit) { if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, tempfle->file, NULL); if (tempfle->is_fd) { close (tempfle->fd); tempfle->fd = -1; } } else if (tempfle->done_rm) tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, _("Skipped")); else gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, _("Finished")); } gftp_lookup_request_option (tdata->fromreq, "refresh_files", &refresh_files); if (refresh_files && tdata->curfle && tdata->curfle->next && compare_request (tdata->toreq, ((gftp_window_data *) tdata->towdata)->request, 1)) gftpui_refresh (tdata->towdata, 1);}static voidget_trans_password (gftp_request * request, gftp_dialog_data * ddata){ gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); request->stopable = 0;}static voidcancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata){ if (tdata->fromreq->stopable == 0) return; g_static_mutex_lock (&tdata->structmutex); if (tdata->started) { tdata->cancel = 1; tdata->fromreq->cancel = 1; tdata->toreq->cancel = 1; } else tdata->done = 1; tdata->fromreq->stopable = 0; tdata->toreq->stopable = 0; g_static_mutex_unlock (&tdata->structmutex); ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"), ((gftp_file *) tdata->curfle->data)->file);}static voidshow_transfer (gftp_transfer * tdata){ GdkPixmap * closedir_pixmap, * opendir_pixmap; GdkBitmap * closedir_bitmap, * opendir_bitmap; gftpui_common_curtrans_data * transdata; gftp_file * tempfle; GList * templist; char *text[2]; gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); text[0] = tdata->fromreq->hostname; text[1] = _("Waiting..."); tdata->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, text, 5, closedir_pixmap, closedir_bitmap, opendir_pixmap, opendir_bitmap, FALSE, tdata->numdirs + tdata->numfiles < 50); transdata = g_malloc (sizeof (*transdata)); transdata->transfer = tdata; transdata->curfle = NULL; gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->user_data, transdata); tdata->show = 0; tdata->curfle = tdata->updfle = tdata->files; tdata->total_bytes = 0; for (templist = tdata->files; templist != NULL; templist = templist->next) { tempfle = templist->data; text[0] = gftpui_gtk_get_utf8_file_pos (tempfle); if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) text[1] = _("Skipped"); else { tdata->total_bytes += tempfle->size; text[1] = _("Waiting..."); } tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), tdata->user_data, NULL, text, 5, NULL, NULL, NULL, NULL, FALSE, FALSE); transdata = g_malloc (sizeof (*transdata)); transdata->transfer = tdata; transdata->curfle = templist; gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, transdata); } if (!tdata->toreq->stopable && gftp_need_password (tdata->toreq)) { tdata->toreq->stopable = 1; MakeEditDialog (_("Enter Password"), _("Please enter your password for this site"), NULL, 0, NULL, gftp_dialog_button_connect, get_trans_password, tdata->toreq, cancel_get_trans_password, tdata); } if (!tdata->fromreq->stopable && gftp_need_password (tdata->fromreq)) { tdata->fromreq->stopable = 1; MakeEditDialog (_("Enter Password"), _("Please enter your password for this site"), NULL, 0, NULL, gftp_dialog_button_connect, get_trans_password, tdata->fromreq, cancel_get_trans_password, tdata); }}static voidtransfer_done (GList * node){ gftpui_common_curtrans_data * transdata; gftp_transfer * tdata; gftp_file * tempfle; GList * templist; tdata = node->data; if (tdata->started) { if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, tdata->fromreq)) { gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); } else gftp_disconnect (tdata->fromreq); if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, tdata->toreq)) { gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); } else gftp_disconnect (tdata->toreq); if (tdata->towdata != NULL && compare_request (tdata->toreq, ((gftp_window_data *) tdata->towdata)->request, 1)) gftpui_refresh (tdata->towdata, 1); num_transfers_in_progress--; } if (!tdata->show && tdata->started) { transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tdata->user_data); if (transdata != NULL) g_free (transdata); for (templist = tdata->files; templist != NULL; templist = templist->next) { tempfle = templist->data; transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tempfle->user_data); if (transdata != NULL) g_free (transdata); } gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); } g_static_mutex_lock (&gftpui_common_transfer_mutex); gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); g_static_mutex_unlock (&gftpui_common_transfer_mutex); gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), gftp_version); free_tdata (tdata);}static void *_gftpui_transfer_files (void *data){ int ret; pthread_detach (pthread_self ()); ret = gftpui_common_transfer_files (data); return (GINT_TO_POINTER(ret));}static voidcreate_transfer (gftp_transfer * tdata){ pthread_t tid; if (!tdata->fromreq->stopable) { if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, tdata->fromreq)) { gftp_swap_socks (tdata->fromreq, ((gftp_window_data *) tdata->fromwdata)->request); update_window (tdata->fromwdata); } if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, tdata->toreq)) { gftp_swap_socks (tdata->toreq, ((gftp_window_data *) tdata->towdata)->request); update_window (tdata->towdata); } num_transfers_in_progress++; tdata->started = 1; tdata->stalled = 1; gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, _("Connecting...")); pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); }}static voidupdate_file_status (gftp_transfer * tdata){ char totstr[150], dlstr[150], winstr[150], gotstr[50], ofstr[50]; unsigned long remaining_secs, lkbs; int hours, mins, secs, pcent, st; intptr_t show_trans_in_title; gftp_file * tempfle; struct timeval tv; g_static_mutex_lock (&tdata->statmutex); tempfle = tdata->curfle->data; gettimeofday (&tv, NULL); remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; lkbs = (unsigned long) tdata->kbs; if (lkbs > 0) remaining_secs /= lkbs; hours = remaining_secs / 3600; remaining_secs -= hours * 3600; mins = remaining_secs / 60; remaining_secs -= mins * 60; secs = remaining_secs; if (hours < 0 || mins < 0 || secs < 0) { g_static_mutex_unlock (&tdata->statmutex); return; } if ((double) tdata->total_bytes > 0) pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); else pcent = 0; if (pcent > 100) g_snprintf (totstr, sizeof (totstr), _("Unknown percentage complete. (File %ld of %ld)"), tdata->current_file_number, tdata->numdirs + tdata->numfiles); else g_snprintf (totstr, sizeof (totstr), _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), pcent, hours, mins, secs, tdata->current_file_number, tdata->numdirs + tdata->numfiles); *dlstr = '\0'; if (!tdata->stalled) { insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); insert_commas (tempfle->size, ofstr, sizeof (ofstr)); st = 1; if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) { if (tdata->curfle->next != NULL) { remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; lkbs = (unsigned long) tdata->kbs; if (lkbs > 0) remaining_secs /= lkbs; hours = remaining_secs / 3600; remaining_secs -= hours * 3600; mins = remaining_secs / 60; remaining_secs -= mins * 60; secs = remaining_secs; } if (!(hours < 0 || mins < 0 || secs < 0)) { g_snprintf (dlstr, sizeof (dlstr), _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); st = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -