diff options
author | Pixel <Pixel> | 2002-09-27 12:17:57 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-09-27 12:17:57 +0000 |
commit | bfa5de7eccf4604ff8217f619e9685a09e80d545 (patch) | |
tree | a5be5de750ac611145f459a09bda902c3dbc1a70 /lib/cdutils.cpp | |
parent | 60c1003845035ad4cd0e9ea50862bad7626faf0e (diff) |
The week-without-the-network changes
Diffstat (limited to 'lib/cdutils.cpp')
-rw-r--r-- | lib/cdutils.cpp | 194 |
1 files changed, 100 insertions, 94 deletions
diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp index 1049535..0f7aa76 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -26,32 +26,34 @@ #include "cdutils.h" #include "Output.h" -Output * ppf_file = 0; -int pt1 = -1, pt2 = -1, snum = 0, ptl = 0, root = 0; +const long sec_sizes[6] = {0, 2048, 2336, 2048, 2324, 2352}; +const long sec_offsts[6] = {0, 16, 16, 24, 24, 0}; +const String sec_modes[6] = {"MODE 0 (empty)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2", "Autodetect"}; -long sec_sizes[5] = {0, 2048, 2336, 2048, 2324}; -long sec_offsts[5] = {0, 16, 16, 24, 24}; -String sec_modes[5] = {"MODE 0 (no mode)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2"}; +cdutils::cdutils(Handle * r, Handle * w) : f_iso_r(r), f_iso_w(w), ppf_file(0), pt1(-1), pt2(-1), snum(0), ptl(0), root(0) {} -struct DirEntry rootDir; +cdutils::~cdutils() { + if (ppf_file) + delete ppf_file; +} -unsigned char from_BCD(unsigned char x) { +unsigned char cdutils::from_BCD(unsigned char x) { return ((x & 0xf) + ((x & 0xf0) >> 4) * 10); } -unsigned char to_BCD(unsigned char x) { +unsigned char cdutils::to_BCD(unsigned char x) { return ((x / 10) << 4) | (x % 10); } -int is_valid_BCD(unsigned char x) { +int cdutils::is_valid_BCD(unsigned char x) { return (((x & 15) < 10) && ((x >> 4) < 10)); } -unsigned long from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start) { +unsigned long cdutils::from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start) { return (from_BCD(m) * 60 + from_BCD(s)) * 75 + from_BCD(f) - start; } -unsigned long from_MSF(unsigned long msf, unsigned long start) { +unsigned long cdutils::from_MSF(unsigned long msf, unsigned long start) { unsigned char f = msf & 0xff, s = (msf >> 8) & 0xff, @@ -60,9 +62,8 @@ unsigned long from_MSF(unsigned long msf, unsigned long start) { return from_MSF(m, s, f, start); } -Handle * open_ppf(String ppf, Handle * iso, String comment) throw (GeneralException) { +Handle * cdutils::open_ppf(String ppf, String comment) throw (GeneralException) { int i, l; - Byte buffer[1024]; if (ppf_file) throw GeneralException("Tried to open_ppf() while already opened."); @@ -80,16 +81,15 @@ Handle * open_ppf(String ppf, Handle * iso, String comment) throw (GeneralExcept } } - l = iso->GetSize(); + l = f_iso_r->GetSize(); ppf_file->write(&l, sizeof(l)); - iso->seek(0x9320, SEEK_SET); - iso->read(buffer, 1024); - ppf_file->write(buffer, 1024); + f_iso_r->seek(0x9320, SEEK_SET); + copy(f_iso_r, ppf_file, 1024); return ppf_file; } -void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { +void cdutils::write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { int i, l = 0, o; for (i = 0; i < 2352; i++) { @@ -114,7 +114,7 @@ void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { } } -void close_ppf() throw (GeneralException) { +void cdutils::close_ppf() throw (GeneralException) { if (ppf_file) { delete ppf_file; ppf_file = 0; @@ -123,7 +123,12 @@ void close_ppf() throw (GeneralException) { } } -String format_date(String input) { +void cdutils::set_iso_w(Handle * w) { + if (!f_iso_w) + f_iso_w = w; +} + +String cdutils::format_date(String input) { String output; output = input.extract(6, 7) + '/'; @@ -137,23 +142,23 @@ String format_date(String input) { return output; } -Uint16 swap_word(Uint16 i) { +Uint16 cdutils::swap_word(Uint16 i) { return (i >> 8) | (i << 8); } -Uint32 swap_dword(Uint32 i) { +Uint32 cdutils::swap_dword(Uint32 i) { return (i >> 24) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | (i << 24); } -int guess_type(Handle * f_iso, int number) { +int cdutils::guess_type(int number) { Byte header[24]; if (number >= 0) { - sector_seek(f_iso, number); + sector_seek(number); } - f_iso->read(header, 24); - f_iso->seek(-24, SEEK_CUR); + f_iso_r->read(header, 24); + f_iso_r->seek(-24, SEEK_CUR); if (header[15] == 1) { return MODE_1; } else if (header[15] == 2) { @@ -172,136 +177,137 @@ int guess_type(Handle * f_iso, int number) { return MODE_0; } -void sector_seek(Handle * f_iso, long sector) { - f_iso->seek(2352 * sector); +void cdutils::sector_seek(long sector) { + f_iso_r->seek(2352 * sector); + if (f_iso_w) + f_iso_w->seek(2352 * sector); } -long read_sector(Handle * f_iso, Byte * buffer, int type, int number) { +long cdutils::read_sector(Byte * buffer, int type, int number) { if (number >= 0) { - sector_seek(f_iso, number); + sector_seek(number); } if (type == GUESS) { - type = guess_type(f_iso, number); + type = guess_type(); } - f_iso->seek(sec_offsts[type], SEEK_CUR); - f_iso->read(buffer, sec_sizes[type]); - f_iso->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); + f_iso_r->seek(sec_offsts[type], SEEK_CUR); + f_iso_r->read(buffer, sec_sizes[type]); + f_iso_r->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); return sec_sizes[type]; } -void read_datas(Handle * f_iso, Byte * buffer, int type, int number, long size) { +void cdutils::read_datas(Byte * buffer, int type, int number, long size) { Byte sector[2352]; int i, n, reste; if (type == GUESS) { - type = guess_type(f_iso, number); + type = guess_type(number); } n = size / sec_sizes[type]; reste = size - n * sec_sizes[type]; - sector_seek(f_iso, number); + sector_seek(number); for (i = 0; i < n; i++) { - read_sector(f_iso, buffer + i * sec_sizes[type], type); + read_sector(buffer + i * sec_sizes[type], type); } if (reste) { - read_sector(f_iso, sector, type); + read_sector(sector, type); bcopy((char *) sector, (char *) (buffer + n * sec_sizes[type]), reste); } } -void read_file(Handle * f_iso, Handle * file, int type, int number, long size) { +void cdutils::read_file(Handle * file, int type, int number, long size) { Byte sector[2352]; int i, n, reste; if (type == GUESS) { - type = guess_type(f_iso, number); + type = guess_type(number); } n = size / sec_sizes[type]; reste = size - n * sec_sizes[type]; - sector_seek(f_iso, number); + sector_seek(number); for (i = 0; i < n; i++) { - read_sector(f_iso, sector, type); + read_sector(sector, type); file->write(sector, sec_sizes[type]); } if (reste) { - read_sector(f_iso, sector, type); + read_sector(sector, type); file->write(sector, reste); } } -void write_sector(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number) { +void cdutils::write_sector(Byte * buffer, int type, int number) { Byte old_sector[2352], new_sector[2352]; if (type == GUESS) { - type = guess_type(f_iso_r, number); + type = guess_type(number); } if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); + sector_seek(number); } f_iso_r->read(old_sector, 2352); - minute = old_sector[12]; - second = old_sector[13]; - frame = old_sector[14]; + yazedc_o.minute = old_sector[12]; + yazedc_o.second = old_sector[13]; + yazedc_o.frame = old_sector[14]; bcopy((char *) old_sector, (char *) new_sector, 2532); bcopy((char *) buffer, (char *) new_sector + sec_offsts[type], sec_sizes[type]); - do_encode_L2(new_sector, type, 0); - if (!ppf_file) { + yazedc_o.do_encode_L2(new_sector, type, 0); + if (f_iso_w) { f_iso_w->write(new_sector, 2352); - } else { + } else if (ppf_file) { write_ppf(old_sector, new_sector, number); + } else { + printm(M_ERROR, "No writing method for iso file"); } } -void write_datas(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number, long size) { +void cdutils::write_datas(Byte * buffer, int type, int number, long size) { long nbsectors, i; unsigned char sector[2352]; if (type == GUESS) { - type = guess_type(f_iso_r, number); + type = guess_type(number); } if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); + sector_seek(number); } nbsectors = size / sec_sizes[type]; for (i = 0; i < nbsectors; i++) { - write_sector(f_iso_r, f_iso_w, buffer + i * sec_sizes[type], type, number + i); + write_sector(buffer + i * sec_sizes[type], type, number + i); } if (size % sec_sizes[type]) { memset(sector, 0, 2352); bcopy((char *) (buffer + i * sec_sizes[type]), (char *) sector, size % sec_sizes[type]); - write_sector(f_iso_r, f_iso_w, sector, type, number + i); + write_sector(sector, type, number + i); } } -void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * file, int type, int number) { +void cdutils::write_file(Handle * file, int type, int number) { long size, nbsectors, i; unsigned char buffer[2352]; if (type == GUESS) { - type = guess_type(f_iso_r, number); + type = guess_type(number); } if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); + sector_seek(number); } size = file->GetSize(); @@ -314,15 +320,15 @@ void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * file, int type, int for (i = 0; i < nbsectors; i++) { memset(buffer, 0, 2352); file->read(buffer, sec_sizes[type]); - write_sector(f_iso_r, f_iso_w, buffer, type); + write_sector(buffer, type); } } -void show_head_entry(void) { +void cdutils::show_head_entry(void) { printm(M_BARE, "Sector - Size - Date - Time - Flags - Name\n"); } -int show_entry(struct DirEntry * dir) { +int cdutils::show_entry(struct DirEntry * dir) { char pbuf[200]; if (!dir->R) { return 1; @@ -338,7 +344,7 @@ int show_entry(struct DirEntry * dir) { return dir->R; } -int show_dir(Handle * f_iso, struct DirEntry * dir) { +int cdutils::show_dir(struct DirEntry * dir) { unsigned int ptr; Byte * buffer; @@ -347,7 +353,7 @@ int show_dir(Handle * f_iso, struct DirEntry * dir) { } buffer = (Byte *) malloc(dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); + read_datas(buffer, GUESS, dir->Sector, dir->Size); ptr = 0; while(ptr < dir->Size) { @@ -358,7 +364,7 @@ int show_dir(Handle * f_iso, struct DirEntry * dir) { return 1; } -struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String name) { +struct cdutils::DirEntry cdutils::find_dir_entry(struct DirEntry * dir, String name) { unsigned int ptr, size; unsigned char * buffer; struct DirEntry r = {0, 0, 0, 0, 0}; @@ -368,7 +374,7 @@ struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String nam } buffer = (unsigned char *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); + read_datas(buffer, GUESS, dir->Sector, dir->Size); ptr = 0; while(ptr < size) { @@ -387,7 +393,7 @@ struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String nam return r; } -struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry * dir, String name) { +struct cdutils::DirEntry * cdutils::find_dir_entry(Byte ** bufout, struct cdutils::DirEntry * dir, String name) { unsigned int ptr, size; Byte * buffer; struct DirEntry * rdir = 0; @@ -398,7 +404,7 @@ struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry } buffer = (Byte *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); + read_datas(buffer, GUESS, dir->Sector, dir->Size); ptr = 0; while(ptr < size) { @@ -421,14 +427,14 @@ struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry return rdir; } -int show_iso_infos(Handle * f_iso) { +int cdutils::show_iso_infos() { char buffer[2048]; char pbuff[130]; short int s, nogood = 0; - read_sector(f_iso, (Byte *) buffer, GUESS, 16); + read_sector((Byte *) buffer, GUESS, 16); - printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(f_iso, 16)] + "\n"); + printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(16)] + "\n"); printm(M_BARE, "offset-size-info : contents\n"); printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); memcpy(pbuff, buffer + 1, 5); @@ -481,10 +487,10 @@ int show_iso_infos(Handle * f_iso) { memcpy(pbuff, buffer + 776, 37); pbuff[37] = 0; printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); - printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813]).to_charp()); - printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830]).to_charp()); - printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847]).to_charp()); - printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864]).to_charp()); + printm(M_BARE, " 813 - 17- DTCreat: " + format_date(&buffer[813]) + "\n"); + printm(M_BARE, " 830 - 17- DTModif: " + format_date(&buffer[830]) + "\n"); + printm(M_BARE, " 847 - 17- DTExpir: " + format_date(&buffer[847]) + "\n"); + printm(M_BARE, " 864 - 17- DTEffec: " + format_date(&buffer[864]) + "\n"); printm(M_BARE, "Root record:\n"); show_head_entry(); @@ -493,12 +499,12 @@ int show_iso_infos(Handle * f_iso) { return 1; } -int get_iso_infos(Handle * f_iso) { +int cdutils::get_iso_infos() { unsigned char buffer[2048]; char pbuff[130]; short int s, nogood = 0; - read_sector(f_iso, buffer, GUESS, 16); + read_sector(buffer, GUESS, 16); memcpy(pbuff, buffer + 1, 5); pbuff[5] = 0; @@ -521,11 +527,11 @@ int get_iso_infos(Handle * f_iso) { return 1; } -int get_pt_infos(Handle * f_iso) { +int cdutils::get_pt_infos() { Byte * buffer; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos()) return 0; if ((!pt1) & (!pt2)) { @@ -534,7 +540,7 @@ int get_pt_infos(Handle * f_iso) { } buffer = (Byte *) malloc(ptl); - read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); + read_datas(buffer, GUESS, !pt1 ? pt2 : pt1, ptl); if (buffer[0] == 1) if (buffer[1] == 0) @@ -548,13 +554,13 @@ int get_pt_infos(Handle * f_iso) { return root ? 1 : 0; } -int show_pt_infos(Handle * f_iso) { +int cdutils::show_pt_infos() { Byte * buffer; char pbuf[100]; int i, ptr; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos()) return 0; if ((!pt1) & (!pt2)) { @@ -563,7 +569,7 @@ int show_pt_infos(Handle * f_iso) { } buffer = (Byte *) malloc(ptl); - read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); + read_datas(buffer, GUESS, !pt1 ? pt2 : pt1, ptl); printm(M_BARE, "node^paren@sector : name\n"); for (ptr = 0, i = 1; buffer[ptr]; ptr += ptr & 1, i++) { @@ -577,13 +583,13 @@ int show_pt_infos(Handle * f_iso) { return 1; } -struct DirEntry find_path(Handle * f_iso, String path) { +struct cdutils::DirEntry cdutils::find_path(String path) { char * newpath = path.strdup(); char ** pts = split(newpath, '/'); struct DirEntry dir = {0, 0, 0, 0, 0}; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) { + if (!get_iso_infos()) { free(newpath); return dir; } @@ -600,7 +606,7 @@ struct DirEntry find_path(Handle * f_iso, String path) { for (dir = rootDir; *pts; pts++) { if (!strlen(*pts)) continue; - dir = find_dir_entry(f_iso, &dir, *pts); + dir = find_dir_entry(&dir, *pts); if (!dir.R) { free(newpath); return dir; @@ -611,7 +617,7 @@ struct DirEntry find_path(Handle * f_iso, String path) { return dir; } -struct DirEntry find_parent(Handle * f_iso, String path) { +struct cdutils::DirEntry cdutils::find_parent(String path) { char * newpath = path.strdup(); char ** pts, * p; struct DirEntry dir = {0, 0, 0, 0, 0}; @@ -626,7 +632,7 @@ struct DirEntry find_parent(Handle * f_iso, String path) { pts = split(newpath, '/'); if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) { + if (!get_iso_infos()) { free(newpath); return dir; } @@ -643,7 +649,7 @@ struct DirEntry find_parent(Handle * f_iso, String path) { for (dir = rootDir; *pts; pts++) { if (!strlen(*pts)) continue; - dir = find_dir_entry(f_iso, &dir, *pts); + dir = find_dir_entry(&dir, *pts); if (!dir.R) { free(newpath); return dir; |