+ return 0;
+ }
+
+ private static int handleCommands(Namespace ns, Manager m) {
+ String commandKey = ns.getString("command");
+ final Map<String, Command> commands = Commands.getCommands();
+ if (commands.containsKey(commandKey)) {
+ Command command = commands.get(commandKey);
+
+ if (command instanceof LocalCommand) {
+ return ((LocalCommand) command).handleCommand(ns, m);
+ } else if (command instanceof DbusCommand) {
+ return ((DbusCommand) command).handleCommand(ns, new DbusSignalImpl(m));
+ } else if (command instanceof ExtendedDbusCommand) {
+ System.err.println(commandKey + " only works via dbus");
+ }
+ return 1;
+ }
+ return 0;
+ }
+
+ /**
+ * Uses $XDG_DATA_HOME/signal-cli if it exists, or if none of the legacy directories exist:
+ * - $HOME/.config/signal
+ * - $HOME/.config/textsecure
+ *
+ * @return the data directory to be used by signal-cli.
+ */
+ private static String getDefaultDataPath() {
+ String dataPath = IOUtils.getDataHomeDir() + "/signal-cli";
+ if (new File(dataPath).exists()) {
+ return dataPath;
+ }
+
+ String legacySettingsPath = System.getProperty("user.home") + "/.config/signal";
+ if (new File(legacySettingsPath).exists()) {
+ return legacySettingsPath;
+ }
+
+ legacySettingsPath = System.getProperty("user.home") + "/.config/textsecure";
+ if (new File(legacySettingsPath).exists()) {
+ return legacySettingsPath;
+ }
+
+ return dataPath;