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

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