Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ClientComponent.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.components;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  25. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  26. import com.dmdirc.events.StatusBarMessageEvent;
  27. import com.dmdirc.interfaces.EventBus;
  28. import com.dmdirc.interfaces.config.IdentityController;
  29. import com.dmdirc.ui.StatusMessage;
  30. import com.dmdirc.updater.UpdateComponent;
  31. import com.dmdirc.updater.Version;
  32. import com.dmdirc.util.io.FileUtils;
  33. import java.io.IOException;
  34. import java.nio.file.Files;
  35. import java.nio.file.Path;
  36. import javax.inject.Inject;
  37. /**
  38. * Represents the client component, which covers the core client resources.
  39. */
  40. public class ClientComponent implements UpdateComponent {
  41. /** The controller to read settings from. */
  42. private final IdentityController identityController;
  43. /** The event bus to post messages to. */
  44. private final EventBus eventBus;
  45. /** Base directory to move updates to. */
  46. private final Path baseDirectory;
  47. /**
  48. * Creates a new instance of {@link ClientComponent}.
  49. *
  50. * @param identityController The controller to read settings from.
  51. * @param eventBus The event bus to post messages to.
  52. */
  53. @Inject
  54. public ClientComponent(
  55. final IdentityController identityController,
  56. final EventBus eventBus,
  57. @Directory(DirectoryType.BASE) final Path baseDirectory) {
  58. this.identityController = identityController;
  59. this.eventBus = eventBus;
  60. this.baseDirectory = baseDirectory;
  61. }
  62. @Override
  63. public String getName() {
  64. return "client";
  65. }
  66. @Override
  67. public String getFriendlyName() {
  68. return "DMDirc client";
  69. }
  70. @Override
  71. public Version getVersion() {
  72. return new Version(getFriendlyVersion());
  73. }
  74. @Override
  75. public boolean requiresRestart() {
  76. return true;
  77. }
  78. @Override
  79. public boolean requiresManualInstall() {
  80. return !LauncherComponent.isUsingLauncher();
  81. }
  82. @Override
  83. public String getManualInstructions(final Path path) {
  84. final Path targetFile = baseDirectory.resolve(".DMDirc.jar");
  85. if (requiresManualInstall()) {
  86. if (FileUtils.isRunningFromJar(Main.class)) {
  87. return "A new version of DMDirc has been downloaded, but as you\n"
  88. + "do not seem to be using the DMDirc launcher, it will\n"
  89. + "not be installed automatically.\n\n"
  90. + "To install this update manually, please replace the\n"
  91. + "existing DMDirc.jar file, located at:\n"
  92. + ' ' + FileUtils.getApplicationPath(Main.class)
  93. + "\n with the following file:\n "
  94. + targetFile.toAbsolutePath();
  95. } else {
  96. return "A new version of DMDirc has been downloaded, but as you\n"
  97. + "do not seem to be using the DMDirc launcher, it will\n"
  98. + "not be installed automatically.\n\n"
  99. + "To install this update manually, please extract the\n"
  100. + "new DMDirc.jar file, located at:\n"
  101. + ' ' + targetFile.toAbsolutePath() + '\n'
  102. + "over your existing DMDirc install located in:\n"
  103. + " " + FileUtils.getApplicationPath(Main.class);
  104. }
  105. }
  106. return "";
  107. }
  108. @Override
  109. public String getFriendlyVersion() {
  110. return identityController.getGlobalConfiguration().getOption("version", "version");
  111. }
  112. @Override
  113. public boolean doInstall(final Path path) throws IOException {
  114. final Path targetFile = baseDirectory.resolve(".DMDirc.jar");
  115. Files.deleteIfExists(targetFile);
  116. Files.move(path, targetFile);
  117. if (requiresManualInstall()) {
  118. // @deprecated Should be removed when updater UI changes are
  119. // implemented.
  120. final String message = getManualInstructions(path);
  121. eventBus.publishAsync(new StatusBarMessageEvent(new StatusMessage(message,
  122. identityController.getGlobalConfiguration())));
  123. }
  124. return true;
  125. }
  126. }