- final String username = ns.getString("username");
-
- final File dataPath;
- String config = ns.getString("config");
- if (config != null) {
- dataPath = new File(config);
- } else {
- dataPath = getDefaultDataPath();
- }
-
- final SignalServiceConfiguration serviceConfiguration = ServiceConfig.createDefaultServiceConfiguration(
- BaseConfig.USER_AGENT);
-
- if (!ServiceConfig.getCapabilities().isGv2()) {
- logger.warn("WARNING: Support for new group V2 is disabled,"
- + " because the required native library dependency is missing: libzkgroup");
- }
-
- if (username == null) {
- ProvisioningManager pm = new ProvisioningManager(dataPath, serviceConfiguration, BaseConfig.USER_AGENT);
- return handleCommand(command, ns, pm);
- }
-
- if (command instanceof RegistrationCommand) {
- final RegistrationManager manager;
- try {
- manager = RegistrationManager.init(username, dataPath, serviceConfiguration, BaseConfig.USER_AGENT);
- } catch (Throwable e) {
- logger.error("Error loading or creating state file: {}", e.getMessage());
- return 2;
- }
- try (RegistrationManager m = manager) {
- return handleCommand(command, ns, m);
- } catch (Exception e) {
- logger.error("Cleanup failed", e);
- return 3;
- }
- }
-
- Manager manager;
- try {
- manager = Manager.init(username, dataPath, serviceConfiguration, BaseConfig.USER_AGENT);
- } catch (NotRegisteredException e) {
- System.err.println("User is not registered.");
- return 1;
- } catch (Throwable e) {
- logger.error("Error loading state file: {}", e.getMessage());
- return 2;
- }
-
- try (Manager m = manager) {
- try {
- m.checkAccountState();
- } catch (IOException e) {
- logger.error("Error while checking account: {}", e.getMessage());
- return 2;
- }
-
- return handleCommand(command, ns, m);
- } catch (IOException e) {
- logger.error("Cleanup failed", e);
- return 3;
- }
- }
-
- private static int initDbusClient(final Command command, final Namespace ns, final boolean systemBus) {