Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ForceUpdate.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.addons.debug.commands;
  23. import com.dmdirc.ClientModule.GlobalConfig;
  24. import com.dmdirc.DMDircMBassador;
  25. import com.dmdirc.addons.debug.Debug;
  26. import com.dmdirc.addons.debug.DebugCommand;
  27. import com.dmdirc.commandparser.CommandArguments;
  28. import com.dmdirc.commandparser.commands.context.CommandContext;
  29. import com.dmdirc.interfaces.WindowModel;
  30. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  31. import com.dmdirc.interfaces.config.IdentityController;
  32. import com.dmdirc.ui.messages.Styliser;
  33. import com.dmdirc.updater.UpdateChecker;
  34. import com.dmdirc.updater.manager.CachingUpdateManager;
  35. import javax.annotation.Nonnull;
  36. import javax.inject.Inject;
  37. import javax.inject.Provider;
  38. /**
  39. * Forces the client to check for an update.
  40. */
  41. public class ForceUpdate extends DebugCommand {
  42. /** The global configuration used to check if updates are enabled. */
  43. private final AggregateConfigProvider globalConfig;
  44. /** The controller to use to read/write settings for the updater. */
  45. private final IdentityController identityController;
  46. /** The update manager to use when forcing an update. */
  47. private final CachingUpdateManager updateManager;
  48. /** The event bus to post errors to. */
  49. private final DMDircMBassador eventBus;
  50. /**
  51. * Creates a new instance of the command.
  52. *
  53. * @param commandProvider The provider to use to access the main debug command.
  54. * @param globalConfig The global config to use to check if updates are enabled.
  55. * @param identityController The controller to use to read/write settings for the updater.
  56. * @param updateManager The update manager to use when forcing an update.
  57. * @param eventBus The event bus to post errors to
  58. */
  59. @Inject
  60. public ForceUpdate(
  61. final Provider<Debug> commandProvider,
  62. @GlobalConfig final AggregateConfigProvider globalConfig,
  63. final IdentityController identityController,
  64. final CachingUpdateManager updateManager,
  65. final DMDircMBassador eventBus) {
  66. super(commandProvider);
  67. this.globalConfig = globalConfig;
  68. this.identityController = identityController;
  69. this.updateManager = updateManager;
  70. this.eventBus = eventBus;
  71. }
  72. @Override
  73. public String getName() {
  74. return "forceupdate";
  75. }
  76. @Override
  77. public String getUsage() {
  78. return " - Forces a client update check";
  79. }
  80. @Override
  81. public void execute(@Nonnull final WindowModel origin,
  82. final CommandArguments args, final CommandContext context) {
  83. if (globalConfig.getOptionBool("updater", "enable")) {
  84. UpdateChecker.checkNow(updateManager, identityController, eventBus,
  85. "Forced update checker");
  86. } else {
  87. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Update checking is "
  88. + "currently disabled. You can enable it by typing:");
  89. sendLine(origin, args.isSilent(), FORMAT_ERROR, Styliser.CODE_FIXED
  90. + " /set updater enable true");
  91. }
  92. }
  93. }