void fs_send_file(const gchar *filename) { int err; // set pbar title if(tifiles_file_is_flash(filename)) { create_pbar_(FNCT_SEND_APP, _("Sending app(s)")); } else if(tifiles_file_is_group(filename)) { create_pbar_(FNCT_SEND_VAR, _("Sending var(s)")); } else if(tifiles_file_is_backup(filename)) { create_pbar_(FNCT_SEND_BACKUP, _("Restoring")); } else if(tifiles_file_is_single(filename)) { create_pbar_(FNCT_SEND_VAR, _("Sending var(s)")); } else if(tifiles_file_is_tigroup(filename)) { create_pbar_type5(_("Restoring")); } // note that core is currently not bkpt-interruptible when // transferring file GTK_REFRESH(); err = ti68k_linkport_send_file(filename); handle_error(); destroy_pbar(); }
/** * tifiles_group_del_file: * @src_filename: the file to remove from group file * @dst_filename: the group file * * Search for entry and remove it from file. * * Return value: 0 if successful, an error code otherwise. **/ TIEXPORT2 int TICALL tifiles_group_del_file(VarEntry *entry, const char *dst_filename) { CalcModel dst_model; FileContent* dst_content = NULL; int ret = 0; if (entry == NULL || dst_filename == NULL) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } // src can be single/group file and dst must be group file if(!tifiles_file_is_group(dst_filename)) return -1; dst_model = tifiles_file_get_model(dst_filename); dst_content = tifiles_content_create_regular(dst_model); ret = tifiles_file_read_regular(dst_filename, dst_content); if(ret) goto tgdf; tifiles_content_del_entry(dst_content, entry); tifiles_file_display_regular(dst_content); ret = tifiles_file_write_regular(dst_filename, dst_content, NULL); if(ret) goto tgdf; tgdf: tifiles_content_delete_regular(dst_content); return ret; }
int gfm_tifiles_group(const char **filenames, int type) { char **ptr; gchar *input; gchar *target = NULL; gchar *dirname = g_path_get_dirname(filenames[0]); // gchar *basename = g_path_get_basename(filenames[0]); int err = 0; // Check for selection consistency for(ptr = (char **)filenames; *ptr; ptr++) { if(tifiles_file_is_group(*ptr) || tifiles_file_is_tigroup(*ptr)) { msgbox_one(MSGBOX_ERROR, _("Group files are not allowed in selection.")); return -1; } if(tifiles_file_is_flash(*ptr) && type != TIFILE_TIGROUP) { msgbox_one(MSGBOX_ERROR, _("FLASH files are not allowed in group files.")); return -1; } } // Ask for group name input = msgbox_input(_("Group files"), "group", _("Group name: ")); if(input == NULL) return -1; // And group if(type == TIFILE_GROUP) { target = g_strconcat(dirname, G_DIR_SEPARATOR_S, input, ".", tifiles_fext_of_group(tifiles_file_get_model(filenames[0])), NULL); g_free(input); err = tifiles_group_files((char **)filenames, target); } else if(type == TIFILE_TIGROUP) { target = g_strconcat(dirname, G_DIR_SEPARATOR_S, input, ".tig", NULL); g_free(input); err = tifiles_tigroup_files((char **)filenames, target); } if(err) { gchar *str; tifiles_error_get(err, &str); msgbox_one(MSGBOX_ERROR, str); g_free(str); } g_free(target); return 0; }
/** * tifiles_file_is_regular: * @filename: a filename as string. * * Check whether file is a single or group file. * * Return value: a boolean value. **/ TIEXPORT2 int TICALL tifiles_file_is_regular(const char *filename) { if (!tifiles_file_is_ti(filename)) return 0; return (tifiles_file_is_single(filename) || tifiles_file_is_group(filename)); }
/** * tifiles_file_is_single: * @filename: a filename as string. * * Check whether file is a single TI file (like program, function, ...). * * Return value: a boolean value. **/ TIEXPORT2 int TICALL tifiles_file_is_single(const char *filename) { if (!tifiles_file_is_ti(filename)) return 0; if (!tifiles_file_is_group(filename) && !tifiles_file_is_backup(filename) && !tifiles_file_is_flash(filename) && !tifiles_file_is_tigroup(filename)) return !0; return 0; }
/** * tifiles_file_get_class: * @filename: a filename as string. * * Returns the file class (single, group, backup, flash). * * Return value: a value in #FileClass. **/ TIEXPORT2 FileClass TICALL tifiles_file_get_class(const char *filename) { if (tifiles_file_is_single(filename)) return TIFILE_SINGLE; else if (tifiles_file_is_group(filename)) return TIFILE_GROUP; else if (tifiles_file_is_backup(filename)) return TIFILE_BACKUP; else if (tifiles_file_is_flash(filename)) return TIFILE_FLASH; else if (tifiles_file_is_tigroup(filename)) return TIFILE_TIGROUP; else return 0; }
/** * tifiles_group_add_file: * @src_filename: the file to add to group file * @dst_filename: the group file * * Add src_filename content to dst_filename content and write to dst_filename. * * Return value: 0 if successful, an error code otherwise. **/ TIEXPORT2 int TICALL tifiles_group_add_file(const char *src_filename, const char *dst_filename) { CalcModel src_model; CalcModel dst_model; FileContent* src_content = NULL; FileContent* dst_content = NULL; int i; int ret = 0; if (src_filename == NULL || dst_filename == NULL) { tifiles_critical("%s: an argument is NULL", __FUNCTION__); return ERR_INVALID_FILE; } // src can be single/group file and dst must be group file if(!tifiles_file_is_group(dst_filename)) return -1; src_model = tifiles_file_get_model(src_filename); dst_model = tifiles_file_get_model(dst_filename); src_content = tifiles_content_create_regular(src_model); dst_content = tifiles_content_create_regular(dst_model); ret = tifiles_file_read_regular(src_filename, src_content); if(ret) goto tgaf; ret = tifiles_file_read_regular(dst_filename, dst_content); if(ret) goto tgaf; for(i = 0; i < src_content->num_entries; i++) tifiles_content_add_entry(dst_content, tifiles_ve_dup(src_content->entries[i])); ret = tifiles_file_write_regular(dst_filename, dst_content, NULL); if(ret) goto tgaf; tgaf: tifiles_content_delete_regular(src_content); tifiles_content_delete_regular(dst_content); return ret; }
/** * 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; }
/** * tifiles_file_get_icon: * @filename: a filename as string. * * Returns the type of file (function, program, ...). * * Return value: a string like "Assembly Program" (non localized). **/ TIEXPORT2 const char *TICALL tifiles_file_get_icon(const char *filename) { char *ext; ext = tifiles_fext_get(filename); if (!strcmp(ext, "")) return ""; if (!g_ascii_strcasecmp(ext, "tib")) return "OS upgrade"; if (!g_ascii_strcasecmp(ext, "tno") || !g_ascii_strcasecmp(ext, "tnc") || !g_ascii_strcasecmp(ext, "tco") || !g_ascii_strcasecmp(ext, "tcc")) return "OS upgrade"; if (!tifiles_file_is_ti(filename)) return ""; if(tifiles_file_is_tigroup(filename)) return "TiGroup"; if (tifiles_file_is_group(filename)) { switch (tifiles_file_get_model(filename)) { case CALC_TI89: case CALC_TI89T: case CALC_TI89T_USB: case CALC_TI92P: case CALC_V200: return "Group/Backup"; default: return "Group"; } } switch (tifiles_file_get_model(filename)) { #ifndef DISABLE_TI8X case CALC_TI73: return ti73_byte2icon(ti73_fext2byte(ext)); case CALC_TI82: return ti82_byte2icon(ti82_fext2byte(ext)); case CALC_TI83: return ti83_byte2icon(ti83_fext2byte(ext)); case CALC_TI83P: case CALC_TI84P: case CALC_TI84P_USB: return ti83p_byte2icon(ti83p_fext2byte(ext)); case CALC_TI85: return ti85_byte2icon(ti85_fext2byte(ext)); case CALC_TI86: return ti86_byte2icon(ti86_fext2byte(ext)); #endif #ifndef DISABLE_TI9X case CALC_TI89: case CALC_TI89T: case CALC_TI89T_USB: return ti89_byte2icon(ti89_fext2byte(ext)); case CALC_TI92: return ti92_byte2icon(ti92_fext2byte(ext)); case CALC_TI92P: return ti92p_byte2icon(ti92p_fext2byte(ext)); case CALC_V200: return v200_byte2icon(v200_fext2byte(ext)); #endif case CALC_NSPIRE: return nsp_byte2icon(nsp_fext2byte(ext)); case CALC_NONE: default: return ""; break; } return ""; }
/* 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"); } } } }
// The main function int main(int argc, char **argv) { char *msg = NULL; char buffer[256]; int i; int ret; // init library tifiles_library_init(); // test tifiles.c printf("Library version : <%s>\n", tifiles_version_get()); printf("--\n"); // test error.c tifiles_error_get(515, &msg); printf("Error message: <%s>\n", msg); #ifndef __WIN32__ free(msg); #endif printf("--\n"); // test type2str.c printf("tifiles_string_to_model: <%i> <%i>\n", CALC_TI92, tifiles_string_to_model(tifiles_model_to_string(CALC_TI92))); printf("tifiles_string_to_attribute: <%i> <%i>\n", ATTRB_LOCKED, tifiles_string_to_attribute(tifiles_attribute_to_string(ATTRB_LOCKED))); printf("tifiles_string_to_class: <%i> <%i>\n", TIFILE_SINGLE, tifiles_string_to_class(tifiles_class_to_string(TIFILE_SINGLE))); printf("--\n"); // test filetypes.c for(i = CALC_TI73; i <= CALC_V200; i++) { printf("%s (%i) ", tifiles_fext_of_group(i), i); } printf("\n"); for(i = CALC_TI73; i <= CALC_V200; i++) { printf("%s ", tifiles_fext_of_backup(i)); } printf("\n"); for(i = CALC_TI73; i <= CALC_V200; i++) { printf("%s ", tifiles_fext_of_flash_os(i)); } printf("\n"); for(i = CALC_TI73; i <= CALC_V200; i++) { printf("%s ", tifiles_fext_of_flash_app(i)); } printf("\n"); printf("--\n"); printf("<%s> <%s>\n", "foo.bar", tifiles_fext_get("foo.bar")); ret = tifiles_file_is_ti(PATH("misc/str.92s")); printf("tifiles_file_is_ti: %i\n", ret); ret = tifiles_file_is_single(PATH("misc/str.92s")); printf("tifiles_file_is_single: %i\n", ret); ret = tifiles_file_is_group(PATH("misc/group.92g")); printf("tifiles_file_is_group: %i\n", ret); ret = tifiles_file_is_regular(PATH("misc/str.92s")); printf("tifiles_file_is_regular: %i\n", ret); ret = tifiles_file_is_regular(PATH("misc/group.92g")); printf("tifiles_file_is_regular: %i\n", ret); ret = tifiles_file_is_backup(PATH("misc/backup.83b")); printf("tifiles_file_is_backup: %i\n", ret); ret = tifiles_file_is_flash(PATH("misc/ticabfra.89k")); printf("tifiles_file_is_flash: %i\n", ret); ret = tifiles_file_is_flash(PATH("misc/TI73_OS160.73U")); printf("tifiles_file_is_flash: %i\n", ret); ret = tifiles_file_is_tib(PATH("misc/ams100.tib")); printf("tifiles_file_is_tib: %i\n", ret); ret = tifiles_file_is_tigroup(PATH("misc/test.tig")); printf("tifiles_file_is_tigroup: %i\n", ret); printf("--\n"); // test typesxx.c printf("tifiles_file_get_model: %s\n", tifiles_model_to_string(tifiles_file_get_model(PATH("misc/str.92s")))); printf("tifiles_file_get_class: %s\n", tifiles_class_to_string(tifiles_file_get_class(PATH("misc/group.92g")))); printf("tifiles_file_get_type: %s\n", tifiles_file_get_type(PATH("misc/TI73_OS160.73U"))); printf("tifiles_file_get_icon: %s\n", tifiles_file_get_icon(PATH("misc/str.92s"))); printf("--\n"); // test misc.c printf("tifiles_calc_is_ti8x: %i\n", tifiles_calc_is_ti8x(CALC_TI83)); printf("tifiles_calc_is_ti9x: %i\n", tifiles_calc_is_ti9x(CALC_TI89)); printf("tifiles_has_folder: %i\n", tifiles_has_folder(CALC_TI92)); printf("tifiles_is_flash: %i\n", tifiles_is_flash(CALC_TI73)); printf("tifiles_get_varname: <%s>\n", tifiles_get_varname("fld\\var")); printf("tifiles_get_fldname: <%s>\n", tifiles_get_fldname("fld\\var")); tifiles_build_fullname(CALC_TI89, buffer, "fld", "var"); printf("tifiles_build_fullname: <%s>\n", buffer); printf("--\n"); // test filesxx.c & grouped.c do { // TI73 support change_dir(PATH("ti73")); ret = test_ti73_backup_support(); if (ret) break; ret = test_ti73_regular_support(); if (ret) break; ret = test_ti73_group_support(); if (ret) break; ret = test_ti73_ungroup_support(); if (ret) break; // TI82 support change_dir(PATH("ti82")); ret = test_ti82_backup_support(); if (ret) break; ret = test_ti82_regular_support(); if (ret) break; ret = test_ti82_group_support(); if (ret) break; ret = test_ti82_ungroup_support(); if (ret) break; // TI83 support change_dir(PATH("ti83")); ret = test_ti83_backup_support(); if (ret) break; ret = test_ti83_regular_support(); if (ret) break; ret = test_ti83_group_support(); if (ret) break; ret = test_ti83_ungroup_support(); if (ret) break; // TI84+ support change_dir(PATH("ti84p")); ret = test_ti84p_regular_support(); if (ret) break; ret = test_ti84p_group_support(); if (ret) break; ret = test_ti84p_ungroup_support(); if (ret) break; ret = test_ti84p_flash_support(); if (ret) break; // TI85 support change_dir(PATH("ti85")); ret = test_ti85_regular_support(); if (ret) break; // TI86 support change_dir(PATH("ti86")); ret = test_ti86_backup_support(); if (ret) break; ret = test_ti86_regular_support(); if (ret) break; ret = test_ti86_group_support(); if (ret) break; ret = test_ti86_ungroup_support(); if (ret) break; // TI89 support change_dir(PATH("ti89")); ret = test_ti89_regular_support(); if (ret) break; ret = test_ti89_flash_support(); if (ret) break; ret = test_v200_regular_support(); if (ret) break; // TI92 support change_dir(PATH("ti92")); ret = test_ti92_backup_support(); if (ret) break; ret = test_ti92_regular_support(); if (ret) break; ret = test_ti92_group_support(); if (ret) break; ret = test_ti92_ungroup_support(); if (ret) break; // TIXX certificates change_dir(PATH("certs")); ret = test_ti8x_cert_support(); if (ret) break; ret = test_ti9x_cert_support(); if (ret) break; // Add/Del files change_dir(PATH("misc")); ret = test_ti8x_group_merge(); if (ret) break; change_dir(PATH("tig")); ret = test_tigroup(); } while(0); // end of test tifiles_library_exit(); return ret; }