Loading

Paste #p7fdfcmh8

  1. AIInfo *AIScannerInfo::FindInfo(const char *nameParam, int versionParam, bool force_exact_match)
  2. {
  3.     if (this->info_list.size() == 0) return NULL;
  4.     if (nameParam == NULL) return NULL;
  5.  
  6.     char ai_name[1024];
  7.     strecpy(ai_name, nameParam, lastof(ai_name));
  8.     strtolower(ai_name);
  9.  
  10.     AIInfo *info = NULL;
  11.     int version = -1;
  12.  
  13.     if (versionParam == -1) {
  14.         /* We want to load the latest version of this AI; so find it */
  15.         if (this->info_single_list.find(ai_name) != this->info_single_list.end()) return static_cast<AIInfo *>(this->info_single_list[ai_name]);
  16.  
  17.         /* If we didn't find a match AI, maybe the user included a version */
  18.         char *e = strrchr(ai_name, '.');
  19.         if (e == NULL) return NULL;
  20.         *e = '\0';
  21.         e++;
  22.         versionParam = atoi(e);
  23.         /* FALL THROUGH, like we were calling this function with a version. */
  24.     }
  25.  
  26.     if (force_exact_match) {
  27.         /* Try to find a direct 'name.version' match */
  28.         char ai_name_tmp[1024];
  29.         seprintf(ai_name_tmp, lastof(ai_name_tmp), "%s.%d", ai_name, versionParam);
  30.         strtolower(ai_name_tmp);
  31.         if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return static_cast<AIInfo *>(this->info_list[ai_name_tmp]);
  32.     }
  33.  
  34.     /* See if there is a compatible AI which goes by that name, with the highest
  35.      *  version which allows loading the requested version */
  36.     ScriptInfoList::iterator it = this->info_list.begin();
  37.     for (; it != this->info_list.end(); it++) {
  38.         AIInfo *i = static_cast<AIInfo *>((*it).second);
  39.         if (strcasecmp(ai_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  40.             version = (*it).second->GetVersion();
  41.             info = i;
  42.         }
  43.     }
  44.  
  45.     if (info == NULL && !force_exact_match && versionParam != -1) {
  46.         /* If we didn't find a match AI, maybe the user included a version */
  47.         char *e = strrchr(ai_name, '.');
  48.         if (e == NULL) return NULL;
  49.         *e = '\0';
  50.         e++;
  51.         versionParam = atoi(e);
  52.         /* Try to find a direct 'name.version' match */
  53.         char ai_name_tmp[1024];
  54.         seprintf(ai_name_tmp, lastof(ai_name_tmp), "%s.%d", ai_name, versionParam);
  55.         strtolower(ai_name_tmp);
  56.         if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return static_cast<AIInfo *>(this->info_list[ai_name_tmp]);
  57.  
  58.         /* See if there is a compatible AI which goes by that name, with the highest
  59.         *  version which allows loading the requested version */
  60.         ScriptInfoList::iterator it = this->info_list.begin();
  61.         for (; it != this->info_list.end(); it++) {
  62.             AIInfo *i = static_cast<AIInfo *>((*it).second);
  63.             if (strcasecmp(ai_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
  64.                 version = (*it).second->GetVersion();
  65.                 info = i;
  66.             }
  67.         }
  68.     }
  69.  
  70.     return info;
  71. }

Comments