+
+ 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;