private IModInfo CheckForUpdate(IMod p_modMod)
{
IModInfo mifInfo = null;
try
{
if (!ModRepository.IsOffline)
{
//get mod info
for (int i = 0; i <= 2; i++)
{
if (!String.IsNullOrEmpty(p_modMod.Id))
mifInfo = ModRepository.GetModInfo(p_modMod.Id);
if (mifInfo == null)
mifInfo = ModRepository.GetModInfoForFile(p_modMod.Filename);
if (mifInfo != null)
break;
Thread.Sleep(1000);
}
if (mifInfo == null)
{
string strSearchTerms = p_modMod.ModName;
if (String.IsNullOrEmpty(strSearchTerms))
strSearchTerms = Path.GetFileNameWithoutExtension(p_modMod.Filename).Replace("_", " ").Replace("-", " ");
//use heuristics to find info
if (!String.IsNullOrEmpty(strSearchTerms))
{
string[] strTerms = strSearchTerms.Split(' ', '-', '_');
string strSearchString = strTerms.OrderByDescending(s => s.Length).FirstOrDefault();
string strAuthor = p_modMod.Author;
if (!String.IsNullOrEmpty(strSearchString) && !String.IsNullOrEmpty(strAuthor) && (strAuthor.Length >= 3))
mifInfo = ModRepository.FindMods(strSearchString, strAuthor, true).FirstOrDefault();
}
}
}
if (mifInfo == null)
return null;
return mifInfo;
}
catch (RepositoryUnavailableException)
{
//the repository is not available, so don't bother
return null;
}
}