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.

CommandLineOptionsModule.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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.commandline;
  23. import java.io.File;
  24. import java.nio.file.Path;
  25. import javax.inject.Qualifier;
  26. import javax.inject.Singleton;
  27. import dagger.Module;
  28. import dagger.Provides;
  29. /**
  30. * Provides options based on the command line.
  31. */
  32. @Module(library = true, complete = false)
  33. public class CommandLineOptionsModule {
  34. /**
  35. * Enumeration of directory types supported by the client.
  36. */
  37. public static final class DirectoryType {
  38. /**
  39. * The base directory, where everything else lives.
  40. */
  41. public static final String BASE = "base";
  42. /**
  43. * The directory that identities are stored in.
  44. */
  45. public static final String IDENTITIES = "identities";
  46. /**
  47. * The directory that plugins are stored in.
  48. */
  49. public static final String PLUGINS = "plugins";
  50. /**
  51. * The directory that themes are stored in.
  52. */
  53. public static final String THEMES = "themes";
  54. /**
  55. * The directory that actions are stored in.
  56. */
  57. public static final String ACTIONS = "actions";
  58. /**
  59. * The directory that error reports are stored in.
  60. */
  61. public static final String ERRORS = "errors";
  62. /**
  63. * The directory to use for temporary files (downloads in flight, caches, etc).
  64. */
  65. public static final String TEMPORARY = "temp";
  66. private DirectoryType() {
  67. }
  68. }
  69. /**
  70. * Provides a mean of identifying the type of directory a class wants injected.
  71. */
  72. @Qualifier
  73. public @interface Directory {
  74. String value();
  75. }
  76. /**
  77. * Provides the base directory that all DMDirc user data is stored in.
  78. *
  79. * @param parser The parser to get the user-supplied directory from.
  80. * @param locator Base directory locator to find default config directory.
  81. *
  82. * @return The base directory.
  83. */
  84. @Provides
  85. @Singleton
  86. @Directory(DirectoryType.BASE)
  87. public String getBaseDirectory(final CommandLineParser parser,
  88. final BaseDirectoryLocator locator) {
  89. if (parser.getConfigDirectory() == null) {
  90. return locator.getDefaultBaseDirectory();
  91. } else {
  92. return parser.getConfigDirectory();
  93. }
  94. }
  95. /**
  96. * Provides the path to the plugins directory.
  97. *
  98. * @param baseDirectory The base DMDirc directory.
  99. *
  100. * @return The plugin directory.
  101. */
  102. @Provides
  103. @Singleton
  104. @Directory(DirectoryType.PLUGINS)
  105. public String getPluginsDirectory(@Directory(DirectoryType.BASE) final String baseDirectory) {
  106. return baseDirectory + "plugins" + File.separator;
  107. }
  108. /**
  109. * Provides the path to the actions directory.
  110. *
  111. * @param baseDirectory The base DMDirc directory.
  112. *
  113. * @return The actions directory.
  114. */
  115. @Provides
  116. @Singleton
  117. @Directory(DirectoryType.ACTIONS)
  118. public String getActionsDirectory(@Directory(DirectoryType.BASE) final String baseDirectory) {
  119. return baseDirectory + "actions" + File.separator;
  120. }
  121. /**
  122. * Provides the path to the identities directory.
  123. *
  124. * @param baseDirectory The base DMDirc directory.
  125. *
  126. * @return The identities directory.
  127. */
  128. @Provides
  129. @Singleton
  130. @Directory(DirectoryType.IDENTITIES)
  131. public String getIdentitiesDirectory(@Directory(DirectoryType.BASE) final String baseDirectory) {
  132. return baseDirectory + "identities" + File.separator;
  133. }
  134. /**
  135. * Provides the path to the errors directory.
  136. *
  137. * @param baseDirectory The base DMDirc directory.
  138. *
  139. * @return The identities directory.
  140. */
  141. @Provides
  142. @Singleton
  143. @Directory(DirectoryType.ERRORS)
  144. public String getErrorsDirectory(@Directory(DirectoryType.BASE) final String baseDirectory) {
  145. return baseDirectory + "errors" + File.separator;
  146. }
  147. /**
  148. * Provides the path to the themes directory.
  149. *
  150. * @param baseDirectory The base DMDirc directory.
  151. *
  152. * @return The themes directory.
  153. */
  154. @Provides
  155. @Singleton
  156. @Directory(DirectoryType.THEMES)
  157. public String getThemesDirectory(@Directory(DirectoryType.BASE) final String baseDirectory) {
  158. return baseDirectory + "themes" + File.separator;
  159. }
  160. /**
  161. * Provides the path to a DMDirc pseudo-temporary directory. This is somewhere the client can
  162. * use to store limited-use files such as downloads not yet installed, or cached update
  163. * information. It is not automatically purged - items placed there must be cleaned up
  164. * explicitly.
  165. *
  166. * @param baseDirectory The base DMDirc directory.
  167. *
  168. * @return The temporary directory.
  169. */
  170. @Provides
  171. @Singleton
  172. @Directory(DirectoryType.TEMPORARY)
  173. public String getTempDirectory(@Directory(DirectoryType.BASE) final String baseDirectory) {
  174. return baseDirectory;
  175. }
  176. @Provides
  177. @Singleton
  178. @Directory(DirectoryType.TEMPORARY)
  179. public Path getTempDirectory(@Directory(DirectoryType.BASE) final Path baseDirectory) {
  180. return baseDirectory;
  181. }
  182. @Provides
  183. @Singleton
  184. @Directory(DirectoryType.BASE)
  185. public Path getBasePath(@Directory(DirectoryType.BASE) final String directory) {
  186. return new File(directory).toPath();
  187. }
  188. @Provides
  189. @Singleton
  190. @Directory(DirectoryType.PLUGINS)
  191. public Path getPluginsPath(@Directory(DirectoryType.PLUGINS) final String directory) {
  192. return new File(directory).toPath();
  193. }
  194. @Provides
  195. @Singleton
  196. @Directory(DirectoryType.ACTIONS)
  197. public Path getActionsPath(@Directory(DirectoryType.ACTIONS) final String directory) {
  198. return new File(directory).toPath();
  199. }
  200. @Provides
  201. @Singleton
  202. @Directory(DirectoryType.IDENTITIES)
  203. public Path getIdentitiesPath(@Directory(DirectoryType.IDENTITIES) final String directory) {
  204. return new File(directory).toPath();
  205. }
  206. @Provides
  207. @Singleton
  208. @Directory(DirectoryType.ERRORS)
  209. public Path getErrorsPath(@Directory(DirectoryType.ERRORS) final String directory) {
  210. return new File(directory).toPath();
  211. }
  212. @Provides
  213. @Singleton
  214. @Directory(DirectoryType.THEMES)
  215. public Path getThemesPath(@Directory(DirectoryType.THEMES) final String directory) {
  216. return new File(directory).toPath();
  217. }
  218. }