Ticket #8634: cleandetector.patch
File cleandetector.patch, 5.1 KB (added by , 18 years ago) |
---|
-
common/advancedDetector.cpp
254 254 IntMap filesSize; 255 255 IntMap allFiles; 256 256 257 String tstr , tstr2;257 String tstr; 258 258 259 259 uint i; 260 260 char md5str[32+1]; … … 273 273 for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { 274 274 tstr = String(fileDesc->fileName); 275 275 tstr.toLowercase(); 276 tstr2 = tstr + ".";277 276 filesList[tstr] = true; 278 filesList[tstr2] = true;279 277 } 280 278 } 281 279 282 280 if (fslist != 0) { 281 // Get the information of the existing files 283 282 for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { 284 283 Common::File f; 285 284 286 285 if (file->isDirectory()) continue; 287 286 tstr = file->name(); 288 287 tstr.toLowercase(); 289 tstr2 = tstr + ".";290 288 291 allFiles[tstr] = allFiles[tstr2] = 1; 289 // Strip the trailing dot 290 if (tstr.lastChar() == '.') 291 tstr.deleteLastChar(); 292 292 293 allFiles[tstr] = 1; 294 293 295 debug(3, "+ %s", tstr.c_str()); 294 296 295 if (!filesList.contains(tstr) && !filesList.contains(tstr2)) continue;297 if (!filesList.contains(tstr)) continue; 296 298 297 299 if (!md5_file_string(*file, md5str, params.md5Bytes)) 298 300 continue; 299 filesMD5[tstr] = filesMD5[tstr2] =md5str;301 filesMD5[tstr] = md5str; 300 302 301 303 debug(3, "> %s: %s", tstr.c_str(), md5str); 302 304 303 305 if (f.open(file->path())) { 304 filesSize[tstr] = filesSize[tstr2] =(int32)f.size();306 filesSize[tstr] = (int32)f.size(); 305 307 f.close(); 306 308 } 307 309 } 308 310 } else { 311 // Get the information of the requested files 309 312 File testFile; 310 313 311 314 for (StringSet::const_iterator file = filesList.begin(); file != filesList.end(); ++file) { 312 315 tstr = file->_key; 313 tstr.toLowercase();314 316 315 317 debug(3, "+ %s", tstr.c_str()); 316 318 if (!filesMD5.contains(tstr)) { 317 if (testFile.open( file->_key)) {318 filesSize[tstr] = filesSize[tstr2] =(int32)testFile.size();319 if (testFile.open(tstr) || testFile.open(tstr + ".")) { 320 filesSize[tstr] = (int32)testFile.size(); 319 321 testFile.close(); 320 322 321 323 if (md5_file_string(file->_key.c_str(), md5str, params.md5Bytes)) { … … 330 332 ADGameDescList matched; 331 333 int maxFilesMatched = 0; 332 334 335 // MD5 based matching 333 336 for (i = 0, descPtr = params.descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += params.descItemSize, ++i) { 334 337 g = (const ADGameDescription *)descPtr; 335 338 fileMissing = false; … … 341 344 continue; 342 345 } 343 346 344 // Try to openall files for this game347 // Try to match all files for this game 345 348 for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { 346 349 tstr = fileDesc->fileName; 347 350 tstr.toLowercase(); 348 tstr2 = tstr + ".";349 351 350 if (!filesMD5.contains(tstr) && !filesMD5.contains(tstr2)) {352 if (!filesMD5.contains(tstr)) { 351 353 fileMissing = true; 352 354 break; 353 355 } 354 356 if (fileDesc->md5 != NULL) { 355 if (strcmp(fileDesc->md5, filesMD5[tstr].c_str()) && strcmp(fileDesc->md5, filesMD5[tstr2].c_str())) {357 if (strcmp(fileDesc->md5, filesMD5[tstr].c_str())) { 356 358 debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fileDesc->md5, filesMD5[tstr].c_str()); 357 359 fileMissing = true; 358 360 break; … … 360 362 } 361 363 362 364 if (fileDesc->fileSize != -1) { 363 if (fileDesc->fileSize != filesSize[tstr] && fileDesc->fileSize != filesSize[tstr2]) {365 if (fileDesc->fileSize != filesSize[tstr]) { 364 366 debug(3, "Size Mismatch. Skipping"); 365 367 fileMissing = true; 366 368 break; … … 378 380 int curFilesMatched = 0; 379 381 for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) 380 382 curFilesMatched++; 381 383 382 384 if (curFilesMatched > maxFilesMatched) { 383 385 debug(2, " ... new best match, removing all previous candidates"); 384 386 maxFilesMatched = curFilesMatched; … … 416 418 printf("\n"); 417 419 } 418 420 421 // Filename based fallback 419 422 if (params.fileBasedFallback != 0) { 420 423 const ADFileBasedFallback *ptr = params.fileBasedFallback; 421 424 const char* const* filenames = 0; 422 425 423 426 // First we create list of files required for detection. 424 if (allFiles.empty()) {425 427 // The filenames can be different than the MD5 based match ones. 428 File testFile; 426 429 427 428 429 430 431 430 for (; ptr->desc; ptr++) { 431 filenames = ptr->filenames; 432 for (; *filenames; filenames++) { 433 tstr = String(*filenames); 434 tstr.toLowercase(); 432 435 433 if (!allFiles.contains(tstr)) { 434 if (testFile.open(tstr)) { 435 tstr2 = tstr + "."; 436 allFiles[tstr] = allFiles[tstr2] = 1; 437 testFile.close(); 438 } 436 if (!allFiles.contains(tstr)) { 437 if (testFile.open(tstr) || testFile.open(tstr + ".")) { 438 allFiles[tstr] = 1; 439 testFile.close(); 439 440 } 440 441 } 441 442 } … … 461 462 } 462 463 463 464 tstr = String(*filenames); 464 465 465 tstr.toLowercase(); 466 tstr2 = tstr + ".";467 466 468 467 debug(3, "++ %s", *filenames); 469 if (!allFiles.contains(tstr) && !allFiles.contains(tstr2)) {468 if (!allFiles.contains(tstr)) { 470 469 fileMissing = true; 471 470 continue; 472 471 }