/// <summary> /// Checks for the updated information for the given mod. /// </summary> /// <param name="mod">The mod for which to check for updates.</param> /// <returns>The latest information available for the given mod, /// or <c>null</c> if no information is available.</returns> private IModInfo CheckForUpdate(IMod mod) { IModInfo modInfo = null; if (!ModRepository.IsOffline) { //get mod info for (var i = 0; i <= 2; i++) { if (!string.IsNullOrEmpty(mod.Id)) { modInfo = ModRepository.GetModInfo(mod.Id); } if (modInfo == null) { modInfo = ModRepository.GetModInfoForFile(mod.Filename); } if (modInfo != null) { break; } Thread.Sleep(1000); } } return(modInfo); }
/// <summary> /// Checks for the updated information for the given mod. /// </summary> /// <param name="p_modMod">The mod for which to check for updates.</param> /// <returns>The lastest informaiton available for the given mod, /// or <c>null</c> if no information is available.</returns> 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); } }
/// <summary> /// The method that is called to start the backgound task. /// </summary> /// <param name="p_objArgs">Arguments to for the task execution.</param> /// <returns>Always <c>null</c>.</returns> protected override object DoWork(object[] p_objArgs) { int intModLimit = 75; if (m_booMissingDownloadId != false) { intModLimit = 75; } List <string> ModList = new List <string>(); List <IMod> ModCheck = new List <IMod>(); ConfirmActionMethod camConfirm = (ConfirmActionMethod)p_objArgs[0]; OverallMessage = "Updating mods info: setup search.."; OverallProgress = 0; OverallProgressStepSize = 1; ShowItemProgress = true; ItemProgress = 0; ItemProgressStepSize = 1; ItemProgressMaximum = 1; OverallProgressMaximum = 1; OverallProgressMaximum = m_lstModList.Count * 2; ItemProgressMaximum = (m_lstModList.Count > intModLimit) ? intModLimit : m_lstModList.Count; for (int i = 0; i < m_lstModList.Count; i++) { IMod modCurrent = m_lstModList[i]; string modID = string.Empty; string modName = string.Empty; int isEndorsed = 0; ItemMessage = modCurrent.ModName; if (m_booCancel) { break; } modName = StripFileName(modCurrent.Filename, modCurrent.Id); if (!string.IsNullOrEmpty(modCurrent.Id)) { modID = modCurrent.Id; isEndorsed = modCurrent.IsEndorsed == true ? 1 : (modCurrent.IsEndorsed == false ? -1 : 0); } else { try { IModInfo mifInfo = ModRepository.GetModInfoForFile(modCurrent.Filename); if (mifInfo != null) { modCurrent.Id = mifInfo.Id; modID = mifInfo.Id; AutoUpdater.AddNewVersionNumberForMod(modCurrent, mifInfo); modName = StripFileName(modCurrent.Filename, mifInfo.Id); } } catch (RepositoryUnavailableException) { //the repository is not available, so don't bother } } if ((m_booMissingDownloadId == null) || ((m_booMissingDownloadId == true) && (string.IsNullOrEmpty(modCurrent.DownloadId) || (modCurrent.DownloadId == "0") || (modCurrent.DownloadId == "-1")))) { ModList.Add(string.Format("{0}|{1}|{2}", modName, string.IsNullOrWhiteSpace(modID) ? "0" : modID, Path.GetFileName(modCurrent.Filename))); ModCheck.Add(modCurrent); } else if ((m_booMissingDownloadId == false) && !string.IsNullOrEmpty(modCurrent.DownloadId)) { if (m_booOverrideCategorySetup) { ModList.Add(string.Format("{0}", modCurrent.DownloadId)); } else { ModList.Add(string.Format("{0}|{1}|{2}|{3}|{4}", string.IsNullOrWhiteSpace(modCurrent.DownloadId) ? "0" : modCurrent.DownloadId, string.IsNullOrWhiteSpace(modID) ? "0" : modID, Path.GetFileName(modName), string.IsNullOrWhiteSpace(modCurrent.HumanReadableVersion) ? "0" : modCurrent.HumanReadableVersion, isEndorsed)); } ModCheck.Add(modCurrent); } if (ItemProgress < ItemProgressMaximum) { StepItemProgress(); } if (OverallProgress < OverallProgressMaximum) { StepOverallProgress(); } if (m_booCancel) { break; } // Prevents the repository request string from becoming too long. if (ModList.Count == intModLimit) { string strResult = CheckForModListUpdate(ModList, ModCheck); if (!string.IsNullOrEmpty(strResult)) { ModList.Clear(); return(strResult); } ModList.Clear(); OverallMessage = "Updating mods info: setup search.."; ItemProgress = 0; ItemProgressMaximum = (m_lstModList.Count == intModLimit) ? 1 : (m_lstModList.Count - (i + 1)); } } if (!m_booCancel && (ModList.Count > 0)) { string strResult = CheckForModListUpdate(ModList, ModCheck); if (!string.IsNullOrEmpty(strResult)) { m_lstModList.Clear(); return(strResult); } } m_lstModList.Clear(); return(dctNewDownloadID); }
/// <summary> /// The method that is called to start the background task. /// </summary> /// <param name="args">Arguments to for the task execution.</param> /// <returns>Always null.</returns> protected override object DoWork(object[] args) { const int modLimit = 75; List <string> updatedMods = new List <string>(); var modList = new List <string>(); var modCheck = new List <IMod>(); OverallMessage = "Updating mods info: setup search.."; OverallProgress = 0; OverallProgressStepSize = 1; ShowItemProgress = true; ItemProgress = 0; ItemProgressStepSize = 1; ItemProgressMaximum = 1; OverallProgressMaximum = 1; OverallProgressMaximum = _modList.Count * 2; ItemProgressMaximum = _modList.Count > modLimit ? modLimit : _modList.Count; if (!string.IsNullOrEmpty(_period)) { // get mod updates updatedMods = ModRepository.GetUpdated(_period); } for (var i = 0; i < _modList.Count; i++) { if (_cancel) { break; } var modCurrent = _modList[i]; var modId = string.Empty; var isEndorsed = 0; ItemMessage = modCurrent.ModName; var modName = StripFileName(modCurrent.Filename, modCurrent.Id); if (!string.IsNullOrEmpty(modCurrent.Id)) { modId = modCurrent.Id; isEndorsed = modCurrent.IsEndorsed == true ? 1 : modCurrent.IsEndorsed == false ? -1 : 0; } else { var modInfoForFile = ModRepository.GetModInfoForFile(modCurrent.Filename); if (modInfoForFile != null) { modCurrent.Id = modInfoForFile.Id; modId = modInfoForFile.Id; AutoUpdater.AddNewVersionNumberForMod(modCurrent, modInfoForFile); modName = StripFileName(modCurrent.Filename, modInfoForFile.Id); } } if (_missingDownloadId == null || _missingDownloadId == true && (string.IsNullOrEmpty(modCurrent.DownloadId) || modCurrent.DownloadId == "0" || modCurrent.DownloadId == "-1")) { if (updatedMods.Count > 0 && !string.IsNullOrWhiteSpace(modId) && updatedMods.Contains(modId, StringComparer.OrdinalIgnoreCase)) { modList.Add(string.Format("{0}|{1}|{2}", modName, modId, Path.GetFileName(modCurrent.Filename))); modCheck.Add(modCurrent); } else if (updatedMods.Count == 0 || string.IsNullOrWhiteSpace(modId)) { modList.Add(string.Format("{0}|{1}|{2}", modName, string.IsNullOrWhiteSpace(modId) ? "0" : modId, Path.GetFileName(modCurrent.Filename))); modCheck.Add(modCurrent); } } else if (_missingDownloadId == false && !string.IsNullOrEmpty(modCurrent.DownloadId)) { if (_overrideCategorySetup) { modList.Add(string.Format("{0}", modCurrent.DownloadId)); } else { modList.Add(string.Format("{0}|{1}|{2}|{3}|{4}", string.IsNullOrWhiteSpace(modCurrent.DownloadId) ? "0" : modCurrent.DownloadId, string.IsNullOrWhiteSpace(modId) ? "0" : modId, Path.GetFileName(modName), string.IsNullOrWhiteSpace(modCurrent.HumanReadableVersion) ? "0" : modCurrent.HumanReadableVersion, isEndorsed)); } modCheck.Add(modCurrent); } if (ItemProgress < ItemProgressMaximum) { StepItemProgress(); } if (OverallProgress < OverallProgressMaximum) { StepOverallProgress(); } if (_cancel) { break; } // Prevents the repository request string from becoming too long. if (modList.Count == modLimit) { string strResult = CheckForModListUpdate(modList, modCheck); if (!string.IsNullOrEmpty(strResult)) { modList.Clear(); return(strResult); } modList.Clear(); OverallMessage = "Updating mods info: setup search.."; ItemProgress = 0; ItemProgressMaximum = _modList.Count == modLimit ? 1 : _modList.Count - (i + 1); } } if (!_cancel && modList.Count > 0) { string strResult = CheckForModListUpdate(modList, modCheck); if (!string.IsNullOrEmpty(strResult)) { _modList.Clear(); return(strResult); } } _modList.Clear(); return(_newDownloadID); }