/** * tifiles_file_test: * @filename: a filename as string. * @type: type to check * @target: hand-held model or CALC_NONE for no filtering * * Check whether #filename is a TI file of type #type useable on a #target model. * This function is a generic one which overwrap and extends the tifiles_file_is_* * functions. * * This is a powerful function which allows checking of a specific file type for * a given target. * * Return value: a boolean value. **/ TIEXPORT2 int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel target) { char *e = tifiles_fext_get(filename); if (!tifiles_file_is_ti(filename)) return 0; if (!strcmp(e, "")) return 0; if(target > CALC_MAX) { tifiles_critical("tifiles_file_test: invalid target argument! This is a bug."); return 0; } if(type & TIFILE_SINGLE) { if(target && !g_ascii_strncasecmp(e, GROUP_FILE_EXT[target], 2)) return !0; else return tifiles_file_is_single(filename); } if(type & TIFILE_GROUP) { if(target && !g_ascii_strcasecmp(e, GROUP_FILE_EXT[target])) return !0; else return tifiles_file_is_group(filename); } if(type & TIFILE_REGULAR) { return tifiles_file_test(filename, TIFILE_SINGLE, target) || tifiles_file_test(filename, TIFILE_GROUP, target); } if(type & TIFILE_BACKUP) { if(target && !g_ascii_strcasecmp(e, BACKUP_FILE_EXT[target])) return !0; else return tifiles_file_is_backup(filename); } if(type & TIFILE_OS) { if(target && !g_ascii_strcasecmp(e, FLASH_OS_FILE_EXT[target])) return !0; else if(target && tifiles_file_is_tib(filename)) { FILE *f; uint8_t data[16]; f = g_fopen(filename, "rb"); if(f == NULL) return 0; fread_n_chars(f, 16, (char *)data); fclose(f); switch(data[8]) { case 1: if(target != CALC_TI92P) return 0; case 3: if(target != CALC_TI89) return 0; case 8: if(target != CALC_V200) return 0; case 9: if(target != CALC_TI89T) return 0; } return !0; } else return tifiles_file_is_os(filename); } if(type & TIFILE_APP) { if(target && !g_ascii_strcasecmp(e, FLASH_APP_FILE_EXT[target])) return !0; else return tifiles_file_is_app(filename); } if(type & TIFILE_FLASH) { return tifiles_file_test(filename, TIFILE_OS, target) || tifiles_file_test(filename, TIFILE_APP, target); } if(type & TIFILE_TIGROUP) { if(target) { // No easy/light way for this part: we have to load the whole file // and to parse the TigEntry structures. TigContent *content; int ret, ok=0; int k; if(!tifiles_file_has_tig_header(filename)) return 0; content = tifiles_content_create_tigroup(CALC_NONE, 0); ret = tifiles_file_read_tigroup(filename, content); if(ret) return 0; for (k = 0; k < content->n_apps; k++) { TigEntry *te = content->app_entries[k]; if(tifiles_calc_are_compat(te->content.regular->model, target)) ok++; } for (k = 0; k < content->n_vars; k++) { TigEntry *te = content->var_entries[k]; if(tifiles_calc_are_compat(te->content.regular->model, target)) ok++; } tifiles_content_delete_tigroup(content); return ok; } else return tifiles_file_is_tigroup(filename); } return 0; }
// Used for sending vars // Note: user_data is a string: // - such as "<FLASH>" for sending var into FLASH (ti83+/84+/89/92+/v200) // - such as "" for sending var in the default folder // - such as "foo" for sending var in the 'foo' folder // - unused for sending FLASH files void on_tilp_send(const gchar *user_data) { gchar *target; FileEntry *f; int ret1 = -1; int ret2 = -1; if (local.selection0 == NULL && local.selection2 == NULL && local.selection5 == NULL) return; tilp_local_contents_load(); // send apps if(local.selection3 || (local.selection5 && local.selection3)) { f = (FileEntry *) local.selection3->data; // send os upgrades if(tifiles_file_is_flash(f->name) || tifiles_file_is_tigroup(f->name)) { if(tifiles_file_test(f->name, TIFILE_OS, options.calc_model)) { if (tilp_calc_send_os(f->name) != 0) return; } else if(tifiles_file_is_app(f->name)) { ret1 = tilp_calc_send_app(); if(!ret1) { // update dirlist (caching, avoid to request dirlist again) tilp_local_update_applist(); ctree_refresh(); labels_refresh(); } } } } // send vars if(local.selection1 || (local.selection5 && local.selection1)) { // note: dst_folder must be a copy b/c the user_data // pointer is no longer valid after dirlist_remote target = g_strdup(user_data); // change target folder if(strcmp(target, "") && strcmp(target, "<FLASH>")) tilp_local_change_folder(target); // and wait for action if (display_action_dbox(target) == BUTTON2) { g_free(target); tilp_local_contents_unload(); return; } // needed: avoid box locking/flickering ! GTK_REFRESH(); ret2 = tilp_calc_send_var(); if(!ret2) { // update dirlist (caching, avoid to request dirlist again) tilp_local_update_varlist(); ctree_refresh(); labels_refresh(); } g_free(target); } tilp_local_contents_unload(); }
/** * tifiles_file_is_flash: * @filename: a filename as string. * * Check whether file is a FLASH file (os or app). * * Return value: a boolean value. **/ TIEXPORT2 int TICALL tifiles_file_is_flash(const char *filename) { return tifiles_file_is_os(filename) || tifiles_file_is_app(filename); }
/* Preload TI variables belonging with the selection */ void tilp_local_contents_load(void) { GList *ptr; int err; // TIGroups if (local.selection5 != NULL) { for(ptr = local.selection5; ptr; ptr = ptr->next) { FileEntry *fe5 = ptr->data; if(tifiles_file_is_tigroup(fe5->name)) { TigContent *content = NULL; FileContent **p, **contents1 = NULL; FlashContent **q, **contents2 = NULL; content = tifiles_content_create_tigroup(options.calc_model, 0); err = tifiles_file_read_tigroup(fe5->name, content); if(err) { tilp_err(err); continue; } err = tifiles_untigroup_content(content, &contents1, &contents2); if(err) { tilp_err(err); tifiles_content_delete_tigroup(content); continue; } tifiles_content_delete_tigroup(content); for(p = contents1; *p; p++) { FileEntry *fe1 = g_memdup(ptr->data, sizeof(FileEntry)); fe1->name = g_memdup(fe1->name, strlen(fe1->name)+1); fe1->content1 = *p; //g_free(fe1->name); //fe1->name = tifiles_build_filename(options.calc_model, (*p)->entries[0]); local.selection1 = g_list_append(local.selection1, fe1); } for(q = contents2; *q; q++) { FileEntry *fe3 = g_memdup(ptr->data, sizeof(FileEntry)); fe3->name = g_memdup(fe3->name, strlen(fe3->name)+1); fe3->content2 = *q; /* { VarEntry ve; g_free(fe3->name); strcpy(ve.name, (*q)->name); ve.type = (*q)->data_type; fe3->name = tifiles_build_filename(options.calc_model, &ve); }*/ local.selection3 = g_list_append(local.selection3, fe3); } } } } // Variables if (local.selection0 != NULL) { for(ptr = local.selection0; ptr; ptr = ptr->next) { FileEntry *fe0 = ptr->data; if(!g_ascii_strcasecmp(tifiles_fext_get(fe0->name), "8xidl")) continue; // doesn't send this pseudo-variable if(tifiles_file_is_single(fe0->name)) { FileEntry *fe1 = g_memdup(ptr->data, sizeof(FileEntry)); fe1->content1 = tifiles_content_create_regular(options.calc_model); err = tifiles_file_read_regular(fe1->name, fe1->content1); if(err) { // The content is already deleted by the subroutines of tifiles_file_read_regular. //tifiles_content_delete_regular(fe1->content1); g_free(fe1); continue; } local.selection1 = g_list_append(local.selection1, fe1); } else if(tifiles_file_is_group(fe0->name)) { // explode group files so that we have 1 VarEntry per item (skip/retry/cancel) FileContent **p, **dst = NULL; FileContent *src = NULL; src = tifiles_content_create_regular(options.calc_model); err = tifiles_file_read_regular(fe0->name, src); if(err) { // The content is already deleted by the subroutines of tifiles_file_read_regular. //tifiles_content_delete_regular(src); continue; } err = tifiles_ungroup_content(src, &dst); if(err) { tifiles_content_delete_regular(src); continue; } for(p = dst; *p; p++) { FileEntry *fe = g_memdup(ptr->data, sizeof(FileEntry)); fe->content1 = *p; local.selection1 = g_list_append(local.selection1, fe); } tifiles_content_delete_regular(src); } } } // Applications if(local.selection2 != NULL) { for(ptr = local.selection2; ptr; ptr = ptr->next) { FileEntry *fe2 = ptr->data; if(tifiles_file_is_app(fe2->name) || tifiles_file_test(fe2->name, TIFILE_OS, options.calc_model)) { FileEntry *fe3 = g_memdup(ptr->data, sizeof(FileEntry)); fe3->content2 = tifiles_content_create_flash(options.calc_model); err = tifiles_file_read_flash(fe2->name, fe3->content2); if(err) { tifiles_content_delete_flash(fe3->content2); g_free(fe3); continue; } local.selection3 = g_list_append(local.selection3, fe3); } } } // Reparse variables and change target folder if (local.selection1) { // replaced "" folder by "main" if(!tifiles_has_folder(options.calc_model)) return; for(ptr = local.selection1; ptr; ptr = ptr->next) { FileEntry *fe = ptr->data; FileContent *fc = fe->content1; unsigned int i; if(fc == NULL) continue; for(i = 0; i < fc->num_entries; i++) { VarEntry *ve = (fc->entries)[i]; if(!strcmp(ve->folder , "")) strcpy(ve->folder, "main"); } } } }