public Task <string> GetUpdateUrlAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null || information._updateUrl != null) { return(Task.FromResult(information?._updateUrl)); } return(_installationUrlTaskCache.Get(async() => { try { var url = $"{information.SourceRegistry}/{type.ToString().ToLowerInvariant()}/{id}/get"; using (var client = new CookieAwareWebClient()) { var updateUrl = await client.GetFinalRedirectAsync(url); if (updateUrl != null) { information._updateUrl = updateUrl; } return updateUrl; } } catch (Exception e) { NonfatalError.NotifyBackground("Can’t download an update", e); return null; } }, type, id)); }
public void IgnoreUpdate(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { return; } _storage.Set($"ignore:{new CupKey(type, id)}:{information.Version}", true); }
public void IgnoreUpdate(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { return; } _storage.Set($"ignore:{new CupKey(type, id)}:{information.Version}", true); _versions.Remove(new CupKey(type, id)); GetLoaded(type, id).OnCupUpdateAvailableChanged(); }
public Task <bool> InstallUpdateAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { return(Task.FromResult(false)); } return(_installTaskCache.Get(async() => { var updateUrl = await GetUpdateUrlAsync(type, id); Logging.Debug(updateUrl); if (information.IsToUpdateManually) { WindowsHelper.ViewInBrowser(updateUrl ?? information.InformationUrl); return false; } var idsToUpdate = new[] { id }.Append(information.AlternativeIds ?? new string[0]).ToArray(); return updateUrl != null && await ContentInstallationManager.Instance.InstallAsync(updateUrl, new ContentInstallationParams { // Actual installation params PreferCleanInstallation = information.PreferCleanInstallation, // For displaying stuff DisplayName = information.Name, IdsToUpdate = idsToUpdate, // For updating content CupType = type, Author = information.Author, Version = information.Version, InformationUrl = information.InformationUrl, SyncDetails = true /*PostInstallation = { * async (progress, token) => { * var manager = GetAssociatedManager(type); * if (manager == null) return; * * progress.Report(new AsyncProgressEntry("Syncing versions…", 0.9999)); * await Task.Delay(1000); * foreach (var cupSupportedObject in idsToUpdate.Select(x => manager.GetObjectById(x) as ICupSupportedObject).NonNull()) { * Logging.Debug($"Set values: {cupSupportedObject}={information.Version}"); * cupSupportedObject.SetValues(information.Author, information.InformationUrl, information.Version); * } * } * }*/ }); }, type, id)); }
public CupInformation GetInformation(CupContentType type, [NotNull] string id) { var key = new CupKey(type, id); if (!_versions.TryGetValue(key, out var data)) { return(null); } if (!data.IsExtendedLoaded) { data.IsExtendedLoaded = true; LoadExtendedInformation(key, data.SourceRegistry).Forget(); } return(data); }
public void Register <T>(BaseAcManager <T> manager, CupContentType type) where T : AcObjectNew, ICupSupportedObject { if (Instance == null) { return; } _managers.Add(type, manager); Instance.NewLatestVersion += (sender, args) => { if (args.Key.Type != type) { return; } var obj = manager.GetWrapperById(args.Key.Id); if (obj == null || !obj.IsLoaded) { return; } ((ICupSupportedObject)obj.Value).OnCupUpdateAvailableChanged(); }; }
public Task <bool> InstallUpdateAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { Logging.Warning($"Failed to update: information == null (type={type}, ID={id})"); return(Task.FromResult(false)); } return(_installTaskCache.Get(async() => { var updateUrl = await GetUpdateUrlAsync(type, id); Logging.Debug(updateUrl); if (information.IsToUpdateManually) { WindowsHelper.ViewInBrowser(updateUrl ?? information.InformationUrl); return false; } var idsToUpdate = new[] { id }.Append(information.AlternativeIds ?? new string[0]).ToArray(); return updateUrl != null && await ContentInstallationManager.Instance.InstallAsync(updateUrl, new ContentInstallationParams(true) { // Actual installation params PreferCleanInstallation = information.PreferCleanInstallation, // For displaying stuff DisplayName = information.Name, IdsToUpdate = idsToUpdate, // For updating content CupType = type, Author = information.Author, Version = information.Version, InformationUrl = information.InformationUrl, SyncDetails = true }); }, type, id)); }
public Task <bool> ReportUpdateAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { return(Task.FromResult(false)); } return(_reportTaskCache.Get(async() => { try { var url = $"{information.SourceRegistry}/{type.ToString().ToLowerInvariant()}/{id}/complain"; using (var client = new CookieAwareWebClient()) { await client.UploadStringTaskAsync(url, ""); IgnoreUpdate(type, id); Toast.Show("Update reported", "Update reported and will be ignored. Thank you for your participation"); return true; } } catch (Exception e) { NonfatalError.NotifyBackground("Can’t report an update", e); return false; } }, type, id)); }
public CupKey(CupContentType type, [NotNull] string id) { Type = type; Id = id ?? throw new ArgumentNullException(nameof(id)); }
public IAcManagerNew GetAssociatedManager(CupContentType type) { return(_managers.TryGetValue(type, out var result) ? result : null); }
public void IgnoreAllUpdates(CupContentType type, [NotNull] string id) { _storage.Set($"ignore:{new CupKey(type, id)}", true); }
public bool ContainsAnUpdate(CupContentType type, [NotNull] string id, [CanBeNull] string installedVersion) { return(_versions.TryGetValue(new CupKey(type, id), out var information) && information.Version.IsVersionNewerThan(installedVersion)); }
public void IgnoreAllUpdates(CupContentType type, [NotNull] string id) { _storage.Set($"ignore:{new CupKey(type, id)}", true); _versions.Remove(new CupKey(type, id)); GetLoaded(type, id).OnCupUpdateAvailableChanged(); }
private ICupSupportedObject GetLoaded(CupContentType type, [NotNull] string id) { return(GetAssociatedManager(type)?.WrappersAsIList.OfType <AcItemWrapper>().GetByIdOrDefault(id, StringComparison.InvariantCultureIgnoreCase)?.Value as ICupSupportedObject); }
public CupKey(CupContentType type, [NotNull] string id) { Type = type; Id = (id ?? throw new ArgumentNullException(nameof(id))).ToLowerInvariant(); }