int osdcmd_fileinfo(const osdfuncparm_t *parm) { unsigned long crc, length; int i,j; char buf[256]; if (parm->numparms != 1) return OSDCMD_SHOWHELP; if ((i = kopen4load((char *)parm->parms[0],0)) < 0) { OSD_Printf("fileinfo: File \"%s\" does not exist.\n", parm->parms[0]); return OSDCMD_OK; } length = kfilelength(i); crc32init(&crc); do { j = kread(i,buf,256); crc32block(&crc,buf,j); } while (j == 256); crc32finish(&crc); kclose(i); OSD_Printf("fileinfo: %s\n" " File size: %d\n" " CRC-32: %08X\n", parm->parms[0], length, crc); return OSDCMD_OK; }
void calcHash( FILE *f ) { unsigned long var; crc32init( &var ); while ( !feof( f ) ) { unsigned char c; fread( (void*)&c, 1, 1, f ); crc32block( &var, &c, 1 ); } fseek( f, 0, 0 ); char s[30]; sprintf( s, "CRC32: %x", crc32finish( &var ) ); OutputDebugStringA( s ); }
int32_t ScanGroups(void) { CACHE1D_FIND_REC *srch, *sidx; struct grpcache *fg, *fgg; struct grpfile *grp; char *fn; struct Bstat st; #define BUFFER_SIZE (1024 * 1024 * 8) uint8_t *buf = (uint8_t *)Bmalloc(BUFFER_SIZE); if (!buf) { initprintf("Error allocating %d byte buffer to scan GRPs!\n", BUFFER_SIZE); return 0; } initprintf("Searching for game data...\n"); LoadGameList(); //LoadGroupsCache(); SB: disabled to match local srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE); for (sidx = srch; sidx; sidx = sidx->next) { for (fg = grpcache; fg; fg = fg->next) { if (!Bstrcmp(fg->name, sidx->name)) break; } if (fg) { if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename if (Bstat(fn, &st)) { Bfree(fn); continue; } // failed to stat the file Bfree(fn); if (fg->size == st.st_size && fg->mtime == st.st_mtime) { grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = Bstrdup(sidx->name); grp->crcval = fg->crcval; grp->size = fg->size; grp->next = foundgrps; foundgrps = grp; fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); strcpy(fgg->name, fg->name); fgg->size = fg->size; fgg->mtime = fg->mtime; fgg->crcval = fg->crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; continue; } } { int32_t b, fh; int32_t crcval; fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); if (fh < 0) continue; if (Bfstat(fh, &st)) continue; initprintf(" Checksumming %s...", sidx->name); crc32init((uint32_t *)&crcval); do { b = read(fh, buf, BUFFER_SIZE); if (b > 0) crc32block((uint32_t *)&crcval, (uint8_t *)buf, b); } while (b == BUFFER_SIZE); crc32finish((uint32_t *)&crcval); close(fh); initprintf(" Done\n"); grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = Bstrdup(sidx->name); grp->crcval = crcval; grp->size = st.st_size; grp->next = foundgrps; foundgrps = grp; fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); Bstrncpy(fgg->name, sidx->name, BMAX_PATH); fgg->size = st.st_size; fgg->mtime = st.st_mtime; fgg->crcval = crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; } } klistfree(srch); FreeGroupsCache(); for (grp = foundgrps; grp; /*grp=grp->next*/) { struct grpfile *igrp; for (igrp = listgrps; igrp; igrp=igrp->next) if (grp->crcval == igrp->crcval) break; if (igrp == NULL) { grp = grp->next; continue; } if (igrp->dependency) { struct grpfile *depgrp; //initprintf("found grp with dep\n"); for (depgrp = foundgrps; depgrp; depgrp=depgrp->next) if (depgrp->crcval == igrp->dependency) break; if (depgrp == NULL || depgrp->crcval != igrp->dependency) // couldn't find dependency { //initprintf("removing %s\n", grp->name); RemoveGroup(igrp->crcval); grp = foundgrps; continue; } } if (igrp->game && !grp->game) grp->game = igrp->game; grp=grp->next; } if (usedgrpcache) { int32_t i = 0; FILE *fp; fp = fopen(GRPCACHEFILE, "wt"); if (fp) { for (fg = usedgrpcache; fg; fg=fgg) { fgg = fg->next; fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval); Bfree(fg); i++; } fclose(fp); } // initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file"); Bfree(buf); return 0; } initprintf("Found no recognized game data!\n"); Bfree(buf); return 0; }