int tixx_recv_backup(CalcHandle* handle, BackupContent* content) { int i, j, k; int i_max, j_max; GNode *vars, *apps; int nvars, ivars = 0; int b = 0; FileContent **group; FileContent *single; if(handle == NULL) return ERR_INVALID_HANDLE; if (content == NULL) { ticalcs_critical("tixx_recv_backup: content is NULL"); return -1; } // Do a directory list and check for something to backup TRYF(handle->calc->get_dirlist(handle, &vars, &apps)); nvars = ticalcs_dirlist_ve_count(vars); if(!nvars) return ERR_NO_VARS; update_->cnt2 = update_->cnt3 = 0; update_->max2 = update_->max3 = nvars; update_->pbar(); // Check whether the last folder is empty b = g_node_n_children(g_node_nth_child(vars, g_node_n_children(vars) - 1)); PAUSE(100); // needed by TI84+/USB // Create a group file k = 0; group = tifiles_content_create_group(nvars); // Receive all vars except for FLASH apps i_max = g_node_n_children(vars); for(i = 0; i < i_max; i++) { GNode *parent = g_node_nth_child(vars, i); j_max = g_node_n_children(parent); for(j = 0; j < j_max; j++) { GNode *node = g_node_nth_child(parent, j); VarEntry *ve = (VarEntry *) (node->data); update_->cnt2 = update_->cnt3 = ++ivars; update_->pbar(); // we need to group files ! TRYF(handle->calc->is_ready(handle)); group[k] = tifiles_content_create_regular(handle->model); TRYF(handle->calc->recv_var(handle, 0, group[k++], ve)); } } ticalcs_dirlist_destroy(&vars); ticalcs_dirlist_destroy(&apps); tifiles_group_contents(group, &single); tifiles_content_delete_group(group); // Swap content and single because we have a pointer on an allocated content { FileContent* cnt = (FileContent *)content; memcpy(content, single, sizeof(FileContent)); cnt->entries = single->entries; strcpy(cnt->comment, tifiles_comment_set_group()); } return 0; }
static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr) { int nvar = 0; int ret = 0; uint16_t ve_size; ticalcs_strlcpy(update_->text, _("Waiting for var(s)..."), sizeof(update_->text)); update_label(); content->model = handle->model; content->num_entries = 0; for (nvar = 0;; nvar++) { VarEntry *ve = tifiles_ve_create(); int ret2; do { update_refresh(); if (update_->cancel) { ret = ERR_ABORT; goto error; } ret = RECV_VAR(handle, &ve_size, &(ve->type), ve->name); ve->size = ve_size; } while (ret == ERROR_READ_TIMEOUT); ret2 = SEND_ACK(handle); if (ret) { if (ret == ERR_EOT) // end of transmission { ret = 0; } goto error; } if (ret2) { ret = ret2; goto error; } ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ticonv_varname_to_utf8_sn(handle->model, ve->name, update_->text, sizeof(update_->text), ve->type); update_label(); ve->data = tifiles_ve_alloc_data(ve->size); ret = RECV_XDP(handle, &ve_size, ve->data); if (!ret) { ve->size = ve_size; ret = SEND_ACK(handle); } } } if (!ret) { tifiles_content_add_entry(content, ve); } else { error: tifiles_ve_delete(ve); break; } } if (nvar == 1) { ticalcs_strlcpy(content->comment, tifiles_comment_set_single(), sizeof(content->comment)); *vr = tifiles_ve_dup(content->entries[0]); } else { ticalcs_strlcpy(content->comment, tifiles_comment_set_group(), sizeof(content->comment)); *vr = NULL; } return ret; }
static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr) { int nvar = 0; int err = 0; char *utf8; uint16_t ve_size; g_snprintf(update_->text, sizeof(update_->text), _("Waiting for var(s)...")); update_label(); content->model = CALC_TI82; for (nvar = 0;; nvar++) { VarEntry *ve; content->entries = tifiles_ve_resize_array(content->entries, nvar+1); ve = content->entries[nvar] = tifiles_ve_create(); do { update_refresh(); if (update_->cancel) return ERR_ABORT; err = ti82_recv_VAR(&ve_size, &(ve->type), ve->name); ve->size = ve_size; } while (err == ERROR_READ_TIMEOUT); TRYF(ti82_send_ACK()); if (err == ERR_EOT) goto exit; TRYF(err); TRYF(ti82_send_CTS()); TRYF(ti82_recv_ACK(NULL)); utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); g_snprintf(update_->text, sizeof(update_->text), "%s", utf8); g_free(utf8); update_label(); ve->data = tifiles_ve_alloc_data(ve->size); TRYF(ti82_recv_XDP(&ve_size, ve->data)); ve->size = ve_size; TRYF(ti82_send_ACK()); } exit: content->num_entries = nvar; if(nvar == 1) { strcpy(content->comment, tifiles_comment_set_single()); *vr = tifiles_ve_dup(content->entries[0]); } else { strcpy(content->comment, tifiles_comment_set_group()); *vr = NULL; } return 0; }
int tixx_recv_all_vars_backup(CalcHandle* handle, FileContent* content) { int i, j, k; int i_max; GNode *vars, *apps; int nvars, ivars = 0; int b = 0; FileContent **group; FileContent *single; int ret; VALIDATE_HANDLE(handle); if (content == NULL) { ticalcs_critical("tixx_recv_backup: content is NULL"); return -1; } VALIDATE_CALCFNCTS(handle->calc); // Do a directory list and check for something to backup ret = handle->calc->get_dirlist(handle, &vars, &apps); if (ret) { return ret; } nvars = ticalcs_dirlist_ve_count(vars); if (!nvars) { return ERR_NO_VARS; } handle->updat->cnt2 = handle->updat->cnt3 = 0; handle->updat->max2 = handle->updat->max3 = nvars; ticalcs_update_pbar(handle); // Check whether the last folder is empty b = g_node_n_children(g_node_nth_child(vars, g_node_n_children(vars) - 1)); PAUSE(100); // needed by TI84+/USB // Create a group file k = 0; group = tifiles_content_create_group(nvars); // Receive all vars except for FLASH apps i_max = g_node_n_children(vars); for (i = 0; i < i_max; i++) { GNode *parent = g_node_nth_child(vars, i); int j_max = g_node_n_children(parent); for (j = 0; j < j_max; j++) { GNode *node = g_node_nth_child(parent, j); VarEntry *ve = (VarEntry *) (node->data); handle->updat->cnt2 = handle->updat->cnt3 = ++ivars; ticalcs_update_pbar(handle); // we need to group files ! ret = handle->calc->is_ready(handle); if (ret) { goto end; } group[k] = tifiles_content_create_regular(handle->model); ret = handle->calc->recv_var(handle, 0, group[k++], ve); if (ret) { goto end; } } } end: ticalcs_dirlist_destroy(&vars); ticalcs_dirlist_destroy(&apps); if (!ret) { FileContent * cnt; ret = tifiles_group_contents(group, &cnt); if (!ret) { cnt->model = content->model; // Steal contents of cnt, then clean up. memcpy(content, cnt, sizeof(*content)); cnt->num_entries = 0; cnt->entries = NULL; tifiles_content_delete_regular(cnt); ticalcs_strlcpy(content->comment, tifiles_comment_set_group(), sizeof(content->comment)); } } tifiles_content_delete_group(group); return ret; }