bool ArchDrive::change_arch(const char *path) { FILE *new_file; // Open new archive file if ((new_file = fopen(path, "rb")) != NULL) { file_info.clear(); // Read header, determine archive type and parse archive contents uint8 header[64]; fread(header, 1, 64, new_file); bool parsed_ok = false; if (is_t64_header(header)) { archive_type = TYPE_T64; parsed_ok = parse_t64_file(new_file, file_info, dir_title); } else if (is_lynx_header(header)) { archive_type = TYPE_LYNX; parsed_ok = parse_lynx_file(new_file, file_info, dir_title); } else if (is_p00_header(header)) { archive_type = TYPE_P00; parsed_ok = parse_p00_file(new_file, file_info, dir_title); } if (!parsed_ok) { fclose(new_file); if (the_file) { close_all_channels(); fclose(the_file); the_file = NULL; } return false; } // Close old archive if open, and set new file if (the_file) { close_all_channels(); fclose(the_file); the_file = NULL; } the_file = new_file; return true; } return false; }
void T64Drive::open_close_t64_file(const char *t64name) { uint8 buf[64]; bool parsed_ok = false; // Close old .t64, if open if (the_file != NULL) { close_all_channels(); fclose(the_file); the_file = NULL; delete[] file_info; file_info = NULL; } // Open new .t64 file if (t64name[0]) { if ((the_file = fopen(t64name, "rb")) != NULL) { // Check file ID fread(&buf, 64, 1, the_file); if (buf[0] == 0x43 && buf[1] == 0x36 && buf[2] == 0x34) { is_lynx = false; parsed_ok = parse_t64_file(); } else if (buf[0x3c] == 0x4c && buf[0x3d] == 0x59 && buf[0x3e] == 0x4e && buf[0x3f] == 0x58) { is_lynx = true; parsed_ok = parse_lynx_file(); } if (!parsed_ok) { fclose(the_file); the_file = NULL; delete[] file_info; file_info = NULL; return; } } } }