You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UpdaterModule.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.updater;
  18. import com.dmdirc.commandline.CommandLineParser;
  19. import com.dmdirc.events.eventbus.EventBus;
  20. import com.dmdirc.interfaces.config.IdentityController;
  21. import com.dmdirc.updater.checking.CheckResultConsolidator;
  22. import com.dmdirc.updater.checking.DMDircCheckStrategy;
  23. import com.dmdirc.updater.checking.NaiveConsolidator;
  24. import com.dmdirc.updater.checking.NightlyChecker;
  25. import com.dmdirc.updater.checking.UpdateCheckStrategy;
  26. import com.dmdirc.updater.components.ClientComponent;
  27. import com.dmdirc.updater.components.DefaultsComponent;
  28. import com.dmdirc.updater.components.LauncherComponent;
  29. import com.dmdirc.updater.components.ModeAliasesComponent;
  30. import com.dmdirc.updater.installing.LegacyInstallationStrategy;
  31. import com.dmdirc.updater.installing.UpdateInstallationStrategy;
  32. import com.dmdirc.updater.manager.CachingUpdateManager;
  33. import com.dmdirc.updater.manager.ConfigComponentPolicy;
  34. import com.dmdirc.updater.manager.DMDircUpdateManager;
  35. import com.dmdirc.updater.manager.UpdateComponentPolicy;
  36. import com.dmdirc.updater.manager.UpdateManager;
  37. import com.dmdirc.updater.retrieving.DownloadRetrievalStrategy;
  38. import com.dmdirc.updater.retrieving.UpdateRetrievalStrategy;
  39. import javax.inject.Singleton;
  40. import dagger.Module;
  41. import dagger.Provides;
  42. /**
  43. * Provides injections for the updater system.
  44. */
  45. @Module(library = true, complete = false)
  46. public class UpdaterModule {
  47. /**
  48. * Provides a client component for the updater component set.
  49. *
  50. * @param component The client component to provide.
  51. *
  52. * @return The component entry in the set.
  53. */
  54. @Provides(type = Provides.Type.SET)
  55. public UpdateComponent getClientComponent(final ClientComponent component) {
  56. return component;
  57. }
  58. /**
  59. * Provides a mode aliases component for the updater component set.
  60. *
  61. * @param component The mode aliases component to provide.
  62. *
  63. * @return The component entry in the set.
  64. */
  65. @Provides(type = Provides.Type.SET)
  66. public UpdateComponent getModeAliasesComponent(final ModeAliasesComponent component) {
  67. return component;
  68. }
  69. /**
  70. * Provides a defaults component for the updater component set.
  71. *
  72. * @param component The defaults component to provide.
  73. *
  74. * @return The component entry in the set.
  75. */
  76. @Provides(type = Provides.Type.SET)
  77. public UpdateComponent getDefaultsComponent(final DefaultsComponent component) {
  78. return component;
  79. }
  80. /**
  81. * Gets an update manager for the client.
  82. *
  83. * @param commandLineParser CLI parser to use to find launcher version.
  84. * @param updateManager The underlying update manager.
  85. * @param identityController The controller to use to read and update settings.
  86. * @param eventBus The event bus to post errors to.
  87. *
  88. * @return The update manager to use.
  89. */
  90. @Provides
  91. @Singleton
  92. public UpdateManager getUpdateManager(
  93. final CommandLineParser commandLineParser,
  94. final DMDircUpdateManager updateManager,
  95. final IdentityController identityController,
  96. final EventBus eventBus) {
  97. UpdateChecker.init(updateManager, identityController);
  98. commandLineParser.getLauncherVersion().ifPresent(version ->
  99. LauncherComponent.setLauncherInfo(updateManager, version));
  100. return updateManager;
  101. }
  102. /**
  103. * Gets a caching update manager for the client.
  104. *
  105. * @param updateManager The underlying update manager.
  106. *
  107. * @return The update manager to use.
  108. */
  109. @Provides
  110. @Singleton
  111. public CachingUpdateManager getCachingUpdateManager(final DMDircUpdateManager updateManager) {
  112. return updateManager;
  113. }
  114. /**
  115. * Provides a {@link CheckResultConsolidator} that the client should use.
  116. *
  117. * @param consolidator The consolidator to provide.
  118. *
  119. * @return The consolidator to use in the client.
  120. */
  121. @Provides
  122. public CheckResultConsolidator getConsolidator(final NaiveConsolidator consolidator) {
  123. return consolidator;
  124. }
  125. /**
  126. * Provides an {@link UpdateComponentPolicy} that the client should use.
  127. *
  128. * @param policy The policy to provide.
  129. *
  130. * @return The policy to use in the client.
  131. */
  132. @Provides
  133. public UpdateComponentPolicy getUpdatePolicy(final ConfigComponentPolicy policy) {
  134. return policy;
  135. }
  136. /**
  137. * Provides an {@link UpdateRetrievalStrategy} that the client should use.
  138. *
  139. * @param strategy The strategy to provide.
  140. *
  141. * @return The strategy to use in the client.
  142. */
  143. @Provides(type = Provides.Type.SET)
  144. public UpdateRetrievalStrategy getRetrievalStrategy(final DownloadRetrievalStrategy strategy) {
  145. return strategy;
  146. }
  147. /**
  148. * Provides an {@link UpdateInstallationStrategy} that the client should use.
  149. *
  150. * @param strategy The strategy to provide.
  151. *
  152. * @return The strategy to use in the client.
  153. */
  154. @Provides(type = Provides.Type.SET)
  155. public UpdateInstallationStrategy getInstallStrategy(final LegacyInstallationStrategy strategy) {
  156. return strategy;
  157. }
  158. /**
  159. * Provides an {@link UpdateCheckStrategy} that the client should use.
  160. *
  161. * @param strategy The strategy to provide.
  162. *
  163. * @return The strategy to use in the client.
  164. */
  165. @Provides(type = Provides.Type.SET)
  166. public UpdateCheckStrategy getCheckStrategy(final DMDircCheckStrategy strategy) {
  167. return strategy;
  168. }
  169. /**
  170. * Provides an {@link UpdateCheckStrategy} that the client should use for nightlies.
  171. *
  172. * @param strategy The strategy to provide.
  173. *
  174. * @return The strategy to use in the client.
  175. */
  176. @Provides(type = Provides.Type.SET)
  177. public UpdateCheckStrategy getCheckStrategy(final NightlyChecker strategy) {
  178. return strategy;
  179. }
  180. }