Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CoreActionExtractor.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.actions;
  23. import com.dmdirc.DMDircMBassador;
  24. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  25. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  26. import com.dmdirc.events.UserErrorEvent;
  27. import com.dmdirc.interfaces.ActionController;
  28. import com.dmdirc.logger.ErrorLevel;
  29. import com.dmdirc.util.io.FileUtils;
  30. import java.io.IOException;
  31. import java.nio.file.Path;
  32. import javax.inject.Inject;
  33. import javax.inject.Singleton;
  34. /**
  35. * Utility class that can extract bundled actions.
  36. */
  37. @Singleton
  38. public class CoreActionExtractor {
  39. /** The action manager to inform when actions are updated. */
  40. private final ActionController actionManager;
  41. /** The directory to extract actions to. */
  42. private final Path actionsDir;
  43. /** The event bus to post events to. */
  44. private final DMDircMBassador eventBus;
  45. /**
  46. * Creates a new instance of {@link CoreActionExtractor}.
  47. *
  48. * @param actionManager The action manager to inform when actions are updated.
  49. * @param actionsDir The directory to extract actions to.
  50. * @param eventBus The event bus to post events to.
  51. */
  52. @Inject
  53. public CoreActionExtractor(final ActionController actionManager,
  54. @Directory(DirectoryType.ACTIONS) final Path actionsDir,
  55. final DMDircMBassador eventBus) {
  56. this.actionManager = actionManager;
  57. this.actionsDir = actionsDir;
  58. this.eventBus = eventBus;
  59. }
  60. /**
  61. * Extracts actions bundled with DMDirc to the user's profile's actions directory.
  62. */
  63. public void extractCoreActions() {
  64. try {
  65. FileUtils.copyResourcesContents(getClass().getResource("/com/dmdirc/actions/defaults/"),
  66. actionsDir);
  67. actionManager.loadUserActions();
  68. } catch (IOException ex) {
  69. eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
  70. "Failed to extract actions: " + ex.getMessage(), ""));
  71. }
  72. }
  73. }