| 2245 | |
| 2246 | |
| 2247 | static int parse_image (struct cdunit *cdu, const TCHAR *img) |
| 2248 | { |
| 2249 | struct zfile *zcue; |
| 2250 | int i; |
| 2251 | const TCHAR *ext; |
| 2252 | int secoffset; |
| 2253 | |
| 2254 | secoffset = 0; |
| 2255 | cdu->tracks = 0; |
| 2256 | if (!img) |
| 2257 | return 0; |
| 2258 | zcue = zfile_fopen (img, _T("rb"), ZFD_ARCHIVE | ZFD_CD | ZFD_DELAYEDOPEN); |
| 2259 | if (!zcue) |
| 2260 | return 0; |
| 2261 | |
| 2262 | ext = _tcsrchr (zfile_getname (zcue), '.'); |
| 2263 | if (ext) { |
| 2264 | TCHAR curdir[MAX_DPATH]; |
| 2265 | TCHAR oldcurdir[MAX_DPATH], *p; |
| 2266 | TCHAR *pcurdir = NULL; |
| 2267 | |
| 2268 | ext++; |
| 2269 | oldcurdir[0] = 0; |
| 2270 | _tcscpy(curdir, img); |
| 2271 | p = curdir + _tcslen(curdir); |
| 2272 | while (p > curdir) { |
| 2273 | if (*p == '/' || *p == '\\') |
| 2274 | break; |
| 2275 | p--; |
| 2276 | } |
| 2277 | *p = 0; |
| 2278 | if (p > curdir) { |
| 2279 | pcurdir = curdir; |
| 2280 | my_setcurrentdir(pcurdir, oldcurdir); |
| 2281 | } |
| 2282 | |
| 2283 | if (!_tcsicmp(ext, _T("cue"))) { |
| 2284 | parsecue(cdu, zcue, img, pcurdir, oldcurdir); |
| 2285 | } else if (!_tcsicmp(ext, _T("ccd"))) { |
| 2286 | parseccd(cdu, zcue, img, pcurdir, oldcurdir); |
| 2287 | } else if (!_tcsicmp(ext, _T("mds"))) { |
| 2288 | parsemds(cdu, zcue, img, pcurdir, oldcurdir); |
| 2289 | } else if (!_tcsicmp(ext, _T("nrg"))) { |
| 2290 | parsenrg(cdu, zcue, img, pcurdir, oldcurdir); |
| 2291 | #ifdef WITH_CHD |
| 2292 | } else if (!_tcsicmp(ext, _T("chd"))) { |
| 2293 | parsechd (cdu, zcue, img, pcurdir, oldcurdir); |
| 2294 | #endif |
| 2295 | } |
| 2296 | |
| 2297 | if (oldcurdir[0]) |
| 2298 | my_setcurrentdir (oldcurdir, NULL); |
| 2299 | } |
| 2300 | if (!cdu->tracks) { |
| 2301 | uae_u64 siz = zfile_size (zcue); |
| 2302 | if (siz >= 16384 && ((siz % 2048) == 0 || (siz % 2352) == 0)) { |
| 2303 | struct cdtoc *t = &cdu->toc[0]; |
| 2304 | cdu->tracks = 1; |
no test coverage detected