| 187 | inline FileBaseInfo DetermineFileBase(const std::string& str) { return DetermineFileBase(str.c_str()); } |
| 188 | |
| 189 | static FCEUFILE * TryUnzip(const std::string& path) { |
| 190 | unzFile tz; |
| 191 | if((tz=unzOpen(path.c_str()))) // If it's not a zip file, use regular file handlers. |
| 192 | // Assuming file type by extension usually works, |
| 193 | // but I don't like it. :) |
| 194 | { |
| 195 | if(unzGoToFirstFile(tz)==UNZ_OK) |
| 196 | { |
| 197 | for(;;) |
| 198 | { |
| 199 | char tempu[512]; // Longer filenames might be possible, but I don't |
| 200 | // think people would name files that long in zip files... |
| 201 | unzGetCurrentFileInfo(tz,0,tempu,512,0,0,0,0); |
| 202 | tempu[511]=0; |
| 203 | if(strlen(tempu)>=4) |
| 204 | { |
| 205 | char *za=tempu+strlen(tempu)-4; |
| 206 | |
| 207 | //if(!ext) |
| 208 | { |
| 209 | if(!strcasecmp(za,".nes") || !strcasecmp(za,".fds") || |
| 210 | !strcasecmp(za,".nsf") || !strcasecmp(za,".unf") || |
| 211 | !strcasecmp(za,".nez")) |
| 212 | break; |
| 213 | } |
| 214 | //else if(!strcasecmp(za,ext)) |
| 215 | // break; |
| 216 | } |
| 217 | if(strlen(tempu)>=5) |
| 218 | { |
| 219 | if(!strcasecmp(tempu+strlen(tempu)-5,".unif")) |
| 220 | break; |
| 221 | } |
| 222 | if(unzGoToNextFile(tz)!=UNZ_OK) |
| 223 | { |
| 224 | if(unzGoToFirstFile(tz)!=UNZ_OK) goto zpfail; |
| 225 | unzCloseCurrentFile(tz); |
| 226 | unzClose(tz); |
| 227 | return 0; |
| 228 | } |
| 229 | } |
| 230 | if(unzOpenCurrentFile(tz)!=UNZ_OK) |
| 231 | goto zpfail; |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | zpfail: |
| 236 | unzClose(tz); |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | unz_file_info ufo; |
| 241 | unzGetCurrentFileInfo(tz,&ufo,0,0,0,0,0,0); |
| 242 | |
| 243 | int size = ufo.uncompressed_size; |
| 244 | EMUFILE_MEMORY* ms = new EMUFILE_MEMORY(size); |
| 245 | unzReadCurrentFile(tz,ms->buf(),ufo.uncompressed_size); |
| 246 | unzCloseCurrentFile(tz); |
no test coverage detected