protected virtual Version?GetComponentVersion(IComponent component) { try { return(UpdaterUtilities.GetAssemblyVersion(component.GetFilePath())); } catch { return(null); } }
protected internal Task CalculateComponentStatusAsync(IComponent component) { Logger.Trace($"Check dependency if update required: {component}"); var destination = component.Destination; Logger.Trace($"Dependency base path: {destination}"); if (string.IsNullOrEmpty(destination)) { return(Task.FromException(new InvalidOperationException())); } var filePath = component.GetFilePath(); if (File.Exists(filePath)) { var currentVersion = GetComponentVersion(component); if (currentVersion == null) { Logger.Info($"Dependency marked to get updated: {component}"); component.CurrentState = CurrentState.None; component.RequiredAction = ComponentAction.Update; return(Task.CompletedTask); } component.CurrentState = CurrentState.Installed; component.CurrentVersion = currentVersion; component.DiskSize = new FileInfo(filePath).Length; if (component.OriginInfo is null) { return(Task.CompletedTask); } var newVersion = component.OriginInfo.Version; if (newVersion != null && newVersion != currentVersion) { Logger.Info($"Dependency marked to get updated: {component}"); component.RequiredAction = ComponentAction.Update; return(Task.CompletedTask); } if (component.OriginInfo.ValidationContext is null) { Logger.Info($"Dependency marked to keep: {component}"); return(Task.CompletedTask); } var hashResult = HashVerifier.VerifyFile(filePath, component.OriginInfo.ValidationContext); if (hashResult == ValidationResult.HashMismatch) { Logger.Info($"Dependency marked to get updated: {component}"); component.RequiredAction = ComponentAction.Update; return(Task.CompletedTask); } Logger.Info($"Dependency marked to keep: {component}"); return(Task.CompletedTask); } Logger.Info($"Dependency marked to get updated: {component}"); component.RequiredAction = ComponentAction.Update; return(Task.CompletedTask); }