Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UpdaterModule.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (c) 2006-2014 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.commandline.CommandLineParser;
  24. import com.dmdirc.interfaces.config.IdentityController;
  25. import com.dmdirc.updater.checking.CheckResultConsolidator;
  26. import com.dmdirc.updater.checking.DMDircCheckStrategy;
  27. import com.dmdirc.updater.checking.NaiveConsolidator;
  28. import com.dmdirc.updater.checking.UpdateCheckStrategy;
  29. import com.dmdirc.updater.components.ClientComponent;
  30. import com.dmdirc.updater.components.DefaultsComponent;
  31. import com.dmdirc.updater.components.LauncherComponent;
  32. import com.dmdirc.updater.components.ModeAliasesComponent;
  33. import com.dmdirc.updater.installing.LegacyInstallationStrategy;
  34. import com.dmdirc.updater.installing.UpdateInstallationStrategy;
  35. import com.dmdirc.updater.manager.CachingUpdateManager;
  36. import com.dmdirc.updater.manager.ConfigComponentPolicy;
  37. import com.dmdirc.updater.manager.DMDircUpdateManager;
  38. import com.dmdirc.updater.manager.UpdateComponentPolicy;
  39. import com.dmdirc.updater.manager.UpdateManager;
  40. import com.dmdirc.updater.retrieving.DownloadRetrievalStrategy;
  41. import com.dmdirc.updater.retrieving.UpdateRetrievalStrategy;
  42. import com.dmdirc.DMDircMBassador;
  43. import javax.inject.Singleton;
  44. import dagger.Module;
  45. import dagger.Provides;
  46. /**
  47. * Provides injections for the updater system.
  48. */
  49. @Module(library = true, complete = false)
  50. public class UpdaterModule {
  51. /**
  52. * Provides a client component for the updater component set.
  53. *
  54. * @param component The client component to provide.
  55. *
  56. * @return The component entry in the set.
  57. */
  58. @Provides(type = Provides.Type.SET)
  59. public UpdateComponent getClientComponent(final ClientComponent component) {
  60. return component;
  61. }
  62. /**
  63. * Provides a mode aliases component for the updater component set.
  64. *
  65. * @param component The mode aliases component to provide.
  66. *
  67. * @return The component entry in the set.
  68. */
  69. @Provides(type = Provides.Type.SET)
  70. public UpdateComponent getModeAliasesComponent(final ModeAliasesComponent component) {
  71. return component;
  72. }
  73. /**
  74. * Provides a defaults component for the updater component set.
  75. *
  76. * @param component The defaults component to provide.
  77. *
  78. * @return The component entry in the set.
  79. */
  80. @Provides(type = Provides.Type.SET)
  81. public UpdateComponent getDefaultsComponent(final DefaultsComponent component) {
  82. return component;
  83. }
  84. /**
  85. * Gets an update manager for the client.
  86. *
  87. * @param commandLineParser CLI parser to use to find launcher version.
  88. * @param updateManager The underlying update manager.
  89. * @param identityController The controller to use to read and update settings.
  90. * @param eventBus The event bus to post errors to.
  91. *
  92. * @return The update manager to use.
  93. */
  94. @Provides
  95. @Singleton
  96. public UpdateManager getUpdateManager(
  97. final CommandLineParser commandLineParser,
  98. final DMDircUpdateManager updateManager,
  99. final IdentityController identityController,
  100. final DMDircMBassador eventBus) {
  101. UpdateChecker.init(updateManager, identityController, eventBus);
  102. if (commandLineParser.getLauncherVersion() != null) {
  103. LauncherComponent.setLauncherInfo(updateManager,
  104. commandLineParser.getLauncherVersion());
  105. }
  106. return updateManager;
  107. }
  108. /**
  109. * Gets a caching update manager for the client.
  110. *
  111. * @param updateManager The underlying update manager.
  112. *
  113. * @return The update manager to use.
  114. */
  115. @Provides
  116. @Singleton
  117. public CachingUpdateManager getCachingUpdateManager(final DMDircUpdateManager updateManager) {
  118. return updateManager;
  119. }
  120. /**
  121. * Provides a {@link CheckResultConsolidator} that the client should use.
  122. *
  123. * @param consolidator The consolidator to provide.
  124. *
  125. * @return The consolidator to use in the client.
  126. */
  127. @Provides
  128. public CheckResultConsolidator getConsolidator(final NaiveConsolidator consolidator) {
  129. return consolidator;
  130. }
  131. /**
  132. * Provides an {@link UpdateComponentPolicy} that the client should use.
  133. *
  134. * @param policy The policy to provide.
  135. *
  136. * @return The policy to use in the client.
  137. */
  138. @Provides
  139. public UpdateComponentPolicy getUpdatePolicy(final ConfigComponentPolicy policy) {
  140. return policy;
  141. }
  142. /**
  143. * Provides an {@link UpdateRetrievalStrategy} that the client should use.
  144. *
  145. * @param strategy The strategy to provide.
  146. *
  147. * @return The strategy to use in the client.
  148. */
  149. @Provides(type = Provides.Type.SET)
  150. public UpdateRetrievalStrategy getRetrievalStrategy(final DownloadRetrievalStrategy strategy) {
  151. return strategy;
  152. }
  153. /**
  154. * Provides an {@link UpdateInstallationStrategy} that the client should use.
  155. *
  156. * @param strategy The strategy to provide.
  157. *
  158. * @return The strategy to use in the client.
  159. */
  160. @Provides(type = Provides.Type.SET)
  161. public UpdateInstallationStrategy getInstallStrategy(final LegacyInstallationStrategy strategy) {
  162. return strategy;
  163. }
  164. /**
  165. * Provides an {@link UpdateCheckStrategy} that the client should use.
  166. *
  167. * @param strategy The strategy to provide.
  168. *
  169. * @return The strategy to use in the client.
  170. */
  171. @Provides(type = Provides.Type.SET)
  172. public UpdateCheckStrategy getCheckStrategy(final DMDircCheckStrategy strategy) {
  173. return strategy;
  174. }
  175. }