/[pcsx2_0.9.7]/trunk/plugins/CDVDpeops/CDVDiso.c
ViewVC logotype

Contents of /trunk/plugins/CDVDpeops/CDVDiso.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 21623 byte(s)
committing r3113 initial commit again...
1 /*
2 * Original code from libcdvd by Hiryu & Sjeep (C) 2002
3 * Modified by Florin for PCSX2 emu
4 * Fixed CdRead by linuzappz
5 */
6
7 #include <string.h>
8 #ifdef __LINUX__
9 #define strnicmp strncasecmp
10 #endif
11
12 #include "CDVDiso.h"
13 #include "CDVDisodrv.h"
14
15 struct dir_toc_data{
16 unsigned int start_LBA;
17 unsigned int num_sectors;
18 unsigned int num_entries;
19 unsigned int current_entry;
20 unsigned int current_sector;
21 unsigned int current_sector_offset;
22 unsigned int inc_dirs;
23 unsigned char extension_list[128+1];
24 };
25
26 //static u8 cdVolDescriptor[2048];
27 static struct dir_toc_data getDirTocData;
28 static struct cdVolDesc CDVolDesc;
29
30 void _splitpath2(const char *constpath, char *dir, char *fname){
31 // 255 char max path-length is an ISO9660 restriction
32 // we must change this for Joliet or relaxed iso restriction support
33 static char pathcopy[1024+1];
34
35 char* slash;
36
37 strncpy(pathcopy, constpath, 1024);
38
39 slash = strrchr (pathcopy, '/');
40
41 // if the path doesn't contain a '/' then look for a '\'
42 if (!slash)
43 slash = strrchr (pathcopy, (int)'\\');
44
45 // if a slash was found
46 if (slash != NULL)
47 {
48 // null terminate the path
49 slash[0] = 0;
50 // and copy the path into 'dir'
51 strncpy(dir, pathcopy, 1024);
52 dir[255]=0;
53
54 // copy the filename into 'fname'
55 strncpy(fname, slash+1, 128);
56 fname[128]=0;
57 }
58 else
59 {
60 dir[0] = 0;
61
62 strncpy(fname, pathcopy, 128);
63 fname[128]=0;
64 }
65
66 }
67
68 // Used in findfile
69 int tolower(int c);
70 int strcasecmp(const char *s1, const char *s2){
71 while (*s1 != '\0' && tolower(*s1) == tolower(*s2))
72 {
73 s1++;
74 s2++;
75 }
76
77 return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
78 }
79
80 // Copy a TOC Entry from the CD native format to our tidier format
81 void TocEntryCopy(struct TocEntry* tocEntry, struct dirTocEntry* internalTocEntry){
82 int i;
83 int filenamelen;
84
85 tocEntry->fileSize = internalTocEntry->fileSize;
86 tocEntry->fileLBA = internalTocEntry->fileLBA;
87 tocEntry->fileProperties = internalTocEntry->fileProperties;
88 memcpy(tocEntry->date, internalTocEntry->dateStamp, 7);
89
90 if (CDVolDesc.filesystemType == 2){
91 // This is a Joliet Filesystem, so use Unicode to ISO string copy
92
93 filenamelen = internalTocEntry->filenameLength/2;
94
95 if (!(tocEntry->fileProperties & 0x02)){
96 // strip the ;1 from the filename
97 // filenamelen -= 2;//(Florin) nah, do not strip ;1
98 }
99
100 for (i=0; i < filenamelen; i++)
101 tocEntry->filename[i] = internalTocEntry->filename[(i<<1)+1];
102
103 tocEntry->filename[filenamelen] = 0;
104 }
105 else{
106 filenamelen = internalTocEntry->filenameLength;
107
108 if (!(tocEntry->fileProperties & 0x02)){
109 // strip the ;1 from the filename
110 // filenamelen -= 2;//(Florin) nah, do not strip ;1
111 }
112
113 // use normal string copy
114 strncpy(tocEntry->filename,internalTocEntry->filename,128);
115 tocEntry->filename[filenamelen] = 0;
116 }
117 }
118
119 // Check if a TOC Entry matches our extension list
120 int TocEntryCompare(char* filename, char* extensions){
121 static char ext_list[129];
122
123 char* token;
124
125 char* ext_point;
126
127 strncpy(ext_list,extensions,128);
128 ext_list[128]=0;
129
130 token = strtok( ext_list, " ," );
131 while( token != NULL )
132 {
133 // if 'token' matches extension of 'filename'
134 // then return a match
135 ext_point = strrchr(filename,'.');
136
137 if (strnicmp(ext_point, token, strlen(token)) == 0)
138 return (TRUE);
139
140 /* Get next token: */
141 token = strtok( NULL, " ," );
142 }
143
144 // If not match found then return FALSE
145 return (FALSE);
146
147 }
148
149 #define CD_SECS 60 /* seconds per minute */
150 #define CD_FRAMES 75 /* frames per second */
151 #define CD_MSF_OFFSET 150 /* MSF numbering offset of first frame */
152
153 int CdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode){
154 u32 i;
155 u8* buff;
156 int rmode;
157
158 switch (mode->datapattern) {
159 case CdSecS2048:
160 rmode = CDVD_MODE_2048; break;
161 case CdSecS2328:
162 rmode = CDVD_MODE_2328; break;
163 case CdSecS2340:
164 rmode = CDVD_MODE_2340; break;
165 default:
166 return 0;
167 }
168
169 for (i=0; i<sectors; i++){
170 if (CDVDreadTrack(lsn+i, rmode)==-1)
171 return 0;
172 buff = CDVDgetBuffer();
173 if (buff==NULL) return 0;
174
175 switch (mode->datapattern){
176 case CdSecS2048:
177 memcpy((void*)((uptr)buf+2048*i), buff, 2048);break;//only data
178 case CdSecS2328:
179 memcpy((void*)((uptr)buf+2328*i), buff, 2328);break;//without sync & head & sub
180 case CdSecS2340:
181 memcpy((void*)((uptr)buf+2340*i), buff, 2340);break;//without sync
182 }
183 }
184 return 1;
185 }
186
187 int DvdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode){
188 u32 i;
189 u8* buff;
190
191 for (i=lsn; i<(lsn+sectors); i++){
192 if (CDVDreadTrack(i, CDVD_MODE_2048)==-1)
193 return 0;
194 buff = CDVDgetBuffer();
195 if (buff==NULL) return 0;
196
197 // switch (mode->datapattern){
198 // case CdSecS2064:
199 ((u32*)buf)[0] = i + 0x30000;
200 memcpy((u8*)buf+12, buff, 2048);
201 (u8*)buf+= 2064; break;
202 // default:
203 // return 0;
204 // }
205 }
206
207 return 1;
208 }
209
210 /**************************************************************
211 * The functions below are not exported for normal file-system *
212 * operations, but are used by the file-system operations, and *
213 * may also be exported for use via RPC *
214 **************************************************************/
215
216 int CDVD_GetVolumeDescriptor(void){
217 // Read until we find the last valid Volume Descriptor
218 int volDescSector;
219
220 static struct cdVolDesc localVolDesc;
221
222 #ifdef DEBUG
223 printf("CDVD_GetVolumeDescriptor called\n");
224 #endif
225
226 for (volDescSector = 16; volDescSector<20; volDescSector++)
227 {
228 CdRead(volDescSector,1,&localVolDesc,&cdReadMode);
229 // CdSync(0x00);
230
231 // If this is still a volume Descriptor
232 if (strncmp(localVolDesc.volID, "CD001", 5) == 0)
233 {
234 if ((localVolDesc.filesystemType == 1) ||
235 (localVolDesc.filesystemType == 2))
236 {
237 memcpy(&CDVolDesc, &localVolDesc, sizeof(struct cdVolDesc));
238 }
239 }
240 else
241 break;
242 }
243
244 #ifdef DEBUG
245 if (CDVolDesc.filesystemType == 1)
246 printf("CD FileSystem is ISO9660\n");
247 else if (CDVolDesc.filesystemType == 2)
248 printf("CD FileSystem is Joliet\n");
249 else printf("Could not detect CD FileSystem type\n");
250 #endif
251 // CdStop();
252
253 return TRUE;
254 }
255
256 int CDVD_findfile(char* fname, struct TocEntry* tocEntry){
257 static char filename[128+1];
258 static char pathname[1024+1];
259 static char toc[2048];
260 char* dirname;
261
262
263 static struct TocEntry localTocEntry; // used for internal checking only
264
265 int found_dir;
266
267 int num_dir_sectors;
268 int current_sector;
269
270 int dir_lba;
271
272 struct dirTocEntry* tocEntryPointer;
273
274 #ifdef DEBUG
275 printf("CDVD_findfile called\n");
276 #endif
277
278 //make sure we have good cdReadMode
279 cdReadMode.trycount = 0;
280 cdReadMode.spindlctrl = CdSpinStm;
281 cdReadMode.datapattern = CdSecS2048;
282
283 _splitpath2(fname, pathname, filename);
284
285 // Find the TOC for a specific directory
286 if (CDVD_GetVolumeDescriptor() != TRUE){
287 #ifdef RPC_LOG
288 RPC_LOG("Could not get CD Volume Descriptor\n");
289 #endif
290 return -1;
291 }
292
293 // Read the TOC of the root directory
294 if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
295 #ifdef RPC_LOG
296 RPC_LOG("Couldn't Read from CD !\n");
297 #endif
298 return -1;
299 }
300 //CdSync(0x00);
301
302 // point the tocEntryPointer at the first real toc entry
303 (char*)tocEntryPointer = toc;
304
305 num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11; //round up fix
306 current_sector = tocEntryPointer->fileLBA;
307
308 (char*)tocEntryPointer += tocEntryPointer->length;
309 (char*)tocEntryPointer += tocEntryPointer->length;
310
311
312 localTocEntry.fileLBA = CDVolDesc.rootToc.tocLBA;
313 // while (there are more dir names in the path)
314 dirname = strtok( pathname, "\\/" );
315
316 while( dirname != NULL )
317 {
318 found_dir = FALSE;
319 /*
320 while(tocEntryPointer->length > 0)
321 {
322 // while there are still more directory entries then search through
323 // for the one we want
324
325 if (tocEntryPointer->fileProperties & 0x02)
326 {
327 // Copy the CD format TOC Entry to our format
328 TocEntryCopy(&localTocEntry, tocEntryPointer);
329
330 // If this TOC Entry is a directory,
331 // then see if it has the right name
332 if (strcasecmp(dirname,localTocEntry.filename) == 0)
333 {
334 // if the name matches then we've found the directory
335 found_dir = TRUE;
336 break;
337 }
338 }
339
340 // point to the next entry
341 (char*)tocEntryPointer += tocEntryPointer->length;
342 }
343 */
344 while(1)
345 {
346 if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048))
347 {
348 num_dir_sectors--;
349
350 if (num_dir_sectors > 0)
351 {
352 // If we've run out of entries, but arent on the last sector
353 // then load another sector
354
355 current_sector++;
356 if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE)
357 {
358 return -1;
359 }
360 // CdSync(0x00);
361
362 (char*)tocEntryPointer = toc;
363 }
364 else
365 {
366 // Couldnt find the directory, and got to end of directory
367 return -1;
368 }
369 }
370
371
372 if (tocEntryPointer->fileProperties & 0x02)
373 {
374 TocEntryCopy(&localTocEntry, tocEntryPointer);
375
376 // If this TOC Entry is a directory,
377 // then see if it has the right name
378 if (strcmp(dirname,localTocEntry.filename) == 0)
379 {
380 // if the name matches then we've found the directory
381 found_dir = TRUE;
382 break;
383 }
384 }
385
386 // point to the next entry
387 (char*)tocEntryPointer += tocEntryPointer->length;
388 }
389
390 // If we havent found the directory name we wanted then fail
391 if (found_dir != TRUE)
392 {
393 return -1;
394 }
395
396 // Get next directory name
397 dirname = strtok( NULL, "\\/" );
398
399 // Read the TOC of the found subdirectory
400 if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE)
401 {
402 return -1;
403 }
404 // CdSync(0x00);
405
406 num_dir_sectors = (localTocEntry.fileSize+2047) >> 11; //round up fix
407 current_sector = localTocEntry.fileLBA;
408
409 // and point the tocEntryPointer at the first real toc entry
410 (char*)tocEntryPointer = toc;
411 (char*)tocEntryPointer += tocEntryPointer->length;
412 (char*)tocEntryPointer += tocEntryPointer->length;
413 }
414
415 (char*)tocEntryPointer = toc;
416
417 num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11; //round up fix
418 dir_lba = tocEntryPointer->fileLBA;
419
420 (char*)tocEntryPointer = toc;
421 (char*)tocEntryPointer += tocEntryPointer->length;
422 (char*)tocEntryPointer += tocEntryPointer->length;
423
424 while (num_dir_sectors > 0)
425 {
426 while(tocEntryPointer->length != 0)
427 {
428 // Copy the CD format TOC Entry to our format
429 TocEntryCopy(&localTocEntry, tocEntryPointer);
430
431 if ((strnicmp(localTocEntry.filename, filename, strlen(filename)) == 0) ||
432 ((filename[strlen(filename)-2] == ';') &&
433 (localTocEntry.filename[strlen(localTocEntry.filename)-2] == ';') &&
434 (strnicmp(localTocEntry.filename, filename, strlen(filename)-2) == 0)))
435 {
436 // if the filename matches then copy the toc Entry
437 tocEntry->fileLBA = localTocEntry.fileLBA;
438 tocEntry->fileProperties = localTocEntry.fileProperties;
439 tocEntry->fileSize = localTocEntry.fileSize;
440
441 strcpy(tocEntry->filename, localTocEntry.filename);
442 memcpy(tocEntry->date, localTocEntry.date, 7);
443
444 #ifdef DEBUG
445 printf("CDVD_findfile: found file\n");
446 #endif
447
448 return TRUE;
449 }
450
451 (char*)tocEntryPointer += tocEntryPointer->length;
452 }
453
454 num_dir_sectors--;
455
456 if (num_dir_sectors > 0)
457 {
458 dir_lba++;
459
460 if (CdRead(dir_lba,1,toc,&cdReadMode) != TRUE){
461 return -1;
462 }
463 // CdSync(0x00);
464
465 (char*)tocEntryPointer = toc;
466 }
467 }
468
469 return FALSE;
470 }
471
472 // This is the RPC-ready function which takes the request to start the tocEntry retrieval
473 int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_dirs){
474 // int dir_depth = 1;
475 static char toc[2048];
476 char* dirname;
477 int found_dir;
478 int num_dir_sectors;
479 unsigned int toc_entry_num;
480 struct dirTocEntry* tocEntryPointer;
481 static struct TocEntry localTocEntry;
482 int current_sector;
483
484 // store the extension list statically for the retrieve function
485 strncpy(getDirTocData.extension_list, extensions, 128);
486 getDirTocData.extension_list[128]=0;
487
488 getDirTocData.inc_dirs = inc_dirs;
489
490 // Find the TOC for a specific directory
491 if (CDVD_GetVolumeDescriptor() != TRUE){
492 #ifdef RPC_LOG
493 RPC_LOG("[RPC:cdvd] Could not get CD Volume Descriptor\n");
494 #endif
495 return -1;
496 }
497
498 #ifdef RPC_LOG
499 RPC_LOG("[RPC:cdvd] Getting Directory Listing for: \"%s\"\n", pathname);
500 #endif
501
502 // Read the TOC of the root directory
503 if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
504 #ifdef RPC_LOG
505 RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
506 #endif
507 return -1;
508 }
509 //CdSync(0x00);
510
511 // point the tocEntryPointer at the first real toc entry
512 (char*)tocEntryPointer = toc;
513
514 num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11;
515 current_sector = tocEntryPointer->fileLBA;
516
517 (char*)tocEntryPointer += tocEntryPointer->length;
518 (char*)tocEntryPointer += tocEntryPointer->length;
519
520 // use strtok to get the next dir name
521
522 // if there isnt one, then assume we want the LBA
523 // for the current one, and exit the while loop
524
525 // if there is another dir name then increment dir_depth
526 // and look through dir table entries until we find the right name
527 // if we dont find the right name
528 // before finding an entry at a higher level (lower num), then return nothing
529
530 localTocEntry.fileLBA = CDVolDesc.rootToc.tocLBA;
531
532 // while (there are more dir names in the path)
533 dirname = strtok( pathname, "\\/" );
534 while( dirname != NULL ){
535 found_dir = FALSE;
536
537 while(1){
538 if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048)) {
539 num_dir_sectors--;
540
541 if (num_dir_sectors > 0){
542 // If we've run out of entries, but arent on the last sector
543 // then load another sector
544
545 current_sector++;
546 if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE){
547 #ifdef RPC_LOG
548 RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
549 #endif
550 return -1;
551 }
552 //CdSync(0x00);
553
554 (char*)tocEntryPointer = toc;
555 }
556 else{
557 // Couldnt find the directory, and got to end of directory
558 return -1;
559 }
560 }
561
562 if (tocEntryPointer->fileProperties & 0x02){
563 TocEntryCopy(&localTocEntry, tocEntryPointer);
564
565 // If this TOC Entry is a directory,
566 // then see if it has the right name
567 if (strcmp(dirname,localTocEntry.filename) == 0){
568 // if the name matches then we've found the directory
569 found_dir = TRUE;
570 #ifdef RPC_LOG
571 RPC_LOG("[RPC: ] Found directory %s in subdir at sector %d\n",dirname,current_sector);
572 RPC_LOG("[RPC: ] LBA of found subdirectory = %d\n",localTocEntry.fileLBA);
573 #endif
574 break;
575 }
576 }
577
578 // point to the next entry
579 (char*)tocEntryPointer += tocEntryPointer->length;
580 }
581
582 // If we havent found the directory name we wanted then fail
583 if (found_dir != TRUE)
584 return -1;
585
586 // Get next directory name
587 dirname = strtok( NULL, "\\/" );
588
589 // Read the TOC of the found subdirectory
590 if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE){
591 #ifdef RPC_LOG
592 RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
593 #endif
594 return -1;
595 }
596 //CdSync(0x00);
597
598 num_dir_sectors = (localTocEntry.fileSize+2047) >> 11;
599 current_sector = localTocEntry.fileLBA;
600
601 // and point the tocEntryPointer at the first real toc entry
602 (char*)tocEntryPointer = toc;
603 (char*)tocEntryPointer += tocEntryPointer->length;
604 (char*)tocEntryPointer += tocEntryPointer->length;
605 }
606
607 // We know how much data we need to read in from the DirTocHeader
608 // but we need to read in at least 1 sector before we can get this value
609
610 // Now we need to COUNT the number of entries (dont do anything with info at this point)
611 // so set the tocEntryPointer to point to the first actual file entry
612
613 // This is a bit of a waste of reads since we're not actually copying the data out yet,
614 // but we dont know how big this TOC might be, so we cant allocate a specific size
615
616 (char*)tocEntryPointer = toc;
617
618 // Need to STORE the start LBA and number of Sectors, for use by the retrieve func.
619 getDirTocData.start_LBA = localTocEntry.fileLBA;
620 getDirTocData.num_sectors = (tocEntryPointer->fileSize+2047) >> 11;
621 getDirTocData.num_entries = 0;
622 getDirTocData.current_entry = 0;
623 getDirTocData.current_sector = getDirTocData.start_LBA;
624 getDirTocData.current_sector_offset = 0;
625
626 num_dir_sectors = getDirTocData.num_sectors;
627
628 (char*)tocEntryPointer = toc;
629 (char*)tocEntryPointer += tocEntryPointer->length;
630 (char*)tocEntryPointer += tocEntryPointer->length;
631
632 toc_entry_num=0;
633
634 while(1){
635 if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048)){
636 // decrease the number of dirs remaining
637 num_dir_sectors--;
638
639 if (num_dir_sectors > 0){
640 // If we've run out of entries, but arent on the last sector
641 // then load another sector
642 getDirTocData.current_sector++;
643
644 if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
645 #ifdef RPC_LOG
646 RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
647 #endif
648 return -1;
649 }
650 //CdSync(0x00);
651
652 (char*)tocEntryPointer = toc;
653
654 // continue;
655 }
656 else{
657 getDirTocData.num_entries = toc_entry_num;
658 getDirTocData.current_sector = getDirTocData.start_LBA;
659 return (toc_entry_num);
660 }
661 }
662
663 // We've found a file/dir in this directory
664 // now check if it matches our extension list (if there is one)
665 TocEntryCopy(&localTocEntry, tocEntryPointer);
666
667 if (localTocEntry.fileProperties & 0x02){
668 // If this is a subdir, then check if we want to include subdirs
669 if (getDirTocData.inc_dirs){
670 toc_entry_num++;
671 }
672 }
673 else{
674 if (strlen(getDirTocData.extension_list) > 0){
675 if (TocEntryCompare(localTocEntry.filename, getDirTocData.extension_list) == TRUE){
676 // increment the number of matching entries counter
677 toc_entry_num++;
678 }
679 }
680 else{
681 toc_entry_num++;
682 }
683 }
684
685 (char*)tocEntryPointer += tocEntryPointer->length;
686
687 }
688
689
690 // THIS SHOULD BE UNREACHABLE -
691 // since we are trying to count ALL matching entries, rather than upto a limit
692
693
694 // STORE total number of TOC entries
695 getDirTocData.num_entries = toc_entry_num;
696 getDirTocData.current_sector = getDirTocData.start_LBA;
697
698
699 // we've reached the toc entry limit, so return how many we've done
700 return (toc_entry_num);
701
702 }
703
704 // This function can be called repeatedly after CDVD_GetDir_RPC_request to get the actual entries
705 // buffer (tocEntry) must be 18KB in size, and this will be filled with a maximum of 128 entries in one go
706 int CDVD_GetDir_RPC_get_entries(struct TocEntry tocEntry[], int req_entries){
707 static char toc[2048];
708 int toc_entry_num;
709
710 struct dirTocEntry* tocEntryPointer;
711
712 if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
713 #ifdef RPC_LOG
714 RPC_LOG("[RPC:cdvd] Couldn't Read from CD !\n");
715 #endif
716 return -1;
717 }
718 //CdSync(0x00);
719
720 if (getDirTocData.current_entry == 0){
721 // if this is the first read then make sure we point to the first real entry
722 (char*)tocEntryPointer = toc;
723 (char*)tocEntryPointer += tocEntryPointer->length;
724 (char*)tocEntryPointer += tocEntryPointer->length;
725
726 getDirTocData.current_sector_offset = (char*)tocEntryPointer - toc;
727 }
728 else{
729 (char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
730 }
731
732 if (req_entries > 128)
733 req_entries = 128;
734
735 for (toc_entry_num=0; toc_entry_num < req_entries;){
736 if ((tocEntryPointer->length == 0) || (getDirTocData.current_sector_offset >= 2048)){
737 // decrease the number of dirs remaining
738 getDirTocData.num_sectors--;
739
740 if (getDirTocData.num_sectors > 0){
741 // If we've run out of entries, but arent on the last sector
742 // then load another sector
743 getDirTocData.current_sector++;
744
745 if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
746 #ifdef RPC_LOG
747 RPC_LOG("[RPC:cdvd] Couldn't Read from CD !\n");
748 #endif
749 return -1;
750 }
751 //CdSync(0x00);
752
753 getDirTocData.current_sector_offset = 0;
754 (char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
755
756 // continue;
757 }
758 else{
759 return (toc_entry_num);
760 }
761 }
762
763 // This must be incremented even if the filename doesnt match extension list
764 getDirTocData.current_entry++;
765
766 // We've found a file in this directory
767 // now check if it matches our extension list (if there is one)
768
769 // Copy the entry regardless, as it makes the comparison easier
770 // if it doesn't match then it will just be overwritten
771 TocEntryCopy(&tocEntry[toc_entry_num], tocEntryPointer);
772
773 if (tocEntry[toc_entry_num].fileProperties & 0x02){
774 // If this is a subdir, then check if we want to include subdirs
775 if (getDirTocData.inc_dirs) {
776 toc_entry_num++;
777 }
778
779 getDirTocData.current_sector_offset += tocEntryPointer->length;
780 (char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
781 }
782 else{
783 if (strlen(getDirTocData.extension_list) > 0){
784 if (TocEntryCompare(tocEntry[toc_entry_num].filename, getDirTocData.extension_list) == TRUE){
785 // increment the number of matching entries counter
786 toc_entry_num++;
787 }
788
789 getDirTocData.current_sector_offset += tocEntryPointer->length;
790 (char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
791
792 }
793 else{
794 toc_entry_num++;
795 getDirTocData.current_sector_offset += tocEntryPointer->length;
796 (char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
797 }
798 }
799 /*
800 if (strlen(getDirTocData.extension_list) > 0)
801 {
802 if (TocEntryCompare(tocEntry[toc_entry_num].filename, getDirTocData.extension_list) == TRUE)
803 {
804
805 // increment this here, rather than in the main for loop
806 // since this should count the number of matching entries
807 toc_entry_num++;
808 }
809
810 getDirTocData.current_sector_offset += tocEntryPointer->length;
811 (char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
812 }
813 else
814 {
815 toc_entry_num++;
816 getDirTocData.current_sector_offset += tocEntryPointer->length;
817 (char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
818 }
819 */
820 }
821 return (toc_entry_num);
822 }

  ViewVC Help
Powered by ViewVC 1.1.22