/// <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); }