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.

ModeAliasesComponent.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.components;
  18. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  19. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  20. import com.dmdirc.config.provider.AggregateConfigProvider;
  21. import com.dmdirc.interfaces.config.IdentityController;
  22. import com.dmdirc.updater.UpdateComponent;
  23. import com.dmdirc.updater.Version;
  24. import com.dmdirc.util.resourcemanager.ZipResourceManager;
  25. import java.io.IOException;
  26. import java.nio.file.Files;
  27. import java.nio.file.Path;
  28. import javax.inject.Inject;
  29. /**
  30. * Represents the mode alias identities.
  31. */
  32. public class ModeAliasesComponent implements UpdateComponent {
  33. /** The controller to read settings from. */
  34. private final IdentityController identityController;
  35. /** The directory to put mode aliases in. */
  36. private final String directory;
  37. /**
  38. * Creates a new instance of {@link DefaultsComponent}.
  39. *
  40. * @param identityController The controller to read settings from.
  41. * @param directory The directory to place mode aliases in.
  42. */
  43. @Inject
  44. public ModeAliasesComponent(
  45. final IdentityController identityController,
  46. @Directory(DirectoryType.IDENTITIES) final String directory) {
  47. this.identityController = identityController;
  48. this.directory = directory;
  49. }
  50. @Override
  51. public String getName() {
  52. return "modealiases";
  53. }
  54. @Override
  55. public String getFriendlyName() {
  56. return "Mode aliases";
  57. }
  58. @Override
  59. public String getFriendlyVersion() {
  60. return String.valueOf(getVersion());
  61. }
  62. @Override
  63. public Version getVersion() {
  64. final AggregateConfigProvider globalConfig = identityController.getGlobalConfiguration();
  65. if (globalConfig.hasOptionString("identity", "modealiasversion")) {
  66. return new Version(globalConfig.getOption("identity",
  67. "modealiasversion"));
  68. } else {
  69. return new Version(-1);
  70. }
  71. }
  72. @Override
  73. public boolean requiresRestart() {
  74. return false;
  75. }
  76. @Override
  77. public boolean requiresManualInstall() {
  78. return false;
  79. }
  80. @Override
  81. public String getManualInstructions(final Path path) {
  82. return "";
  83. }
  84. @Override
  85. public boolean doInstall(final Path path) throws IOException {
  86. final ZipResourceManager ziprm =
  87. ZipResourceManager.getInstance(path.toAbsolutePath().toString());
  88. ziprm.extractResources("", directory);
  89. identityController.loadUserIdentities();
  90. Files.delete(path);
  91. return false;
  92. }
  93. }