+ this.pluginRespirator = pluginRespirator;
+
+ /* create a configuration. */
+ Configuration oldConfiguration;
+ Configuration newConfiguration = null;
+ boolean firstStart = !new File("sone.properties").exists();
+ boolean newConfig = false;
+ try {
+ oldConfiguration = new Configuration(new MapConfigurationBackend(new File("sone.properties"), false));
+ newConfiguration = oldConfiguration;
+ } catch (ConfigurationException ce1) {
+ newConfig = true;
+ logger.log(Level.INFO, "Could not load configuration file, trying plugin store…", ce1);
+ try {
+ newConfiguration = new Configuration(new MapConfigurationBackend(new File("sone.properties"), true));
+ logger.log(Level.INFO, "Created new configuration file.");
+ } catch (ConfigurationException ce2) {
+ logger.log(Level.SEVERE, "Could not create configuration file, using Plugin Store!", ce2);
+ }
+ try {
+ oldConfiguration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator));
+ logger.log(Level.INFO, "Plugin store loaded.");
+ } catch (PersistenceDisabledException pde1) {
+ logger.log(Level.SEVERE, "Could not load any configuration, using empty configuration!");
+ oldConfiguration = new Configuration(new MapConfigurationBackend());
+ }
+ }
+
+ final Configuration startConfiguration;
+ if ((newConfiguration != null) && (oldConfiguration != newConfiguration)) {
+ logger.log(Level.INFO, "Setting configuration to file-based configuration.");
+ startConfiguration = newConfiguration;
+ } else {
+ startConfiguration = oldConfiguration;
+ }
+ final EventBus eventBus = new EventBus();
+
+ /* Freenet injector configuration. */
+ AbstractModule freenetModule = new AbstractModule() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ protected void configure() {
+ bind(PluginRespirator.class).toInstance(SonePlugin.this.pluginRespirator);
+ bind(Node.class).toInstance(SonePlugin.this.pluginRespirator.getNode());
+ }
+ };
+ /* Sone injector configuration. */
+ AbstractModule soneModule = new AbstractModule() {
+
+ @Override
+ protected void configure() {
+ bind(EventBus.class).toInstance(eventBus);
+ bind(Configuration.class).toInstance(startConfiguration);
+ Context context = new Context("Sone");
+ bind(Context.class).toInstance(context);
+ bind(getOptionalContextTypeLiteral()).toInstance(of(context));
+ bind(SonePlugin.class).toInstance(SonePlugin.this);
+ bind(Version.class).toInstance(VERSION);
+ if (startConfiguration.getBooleanValue("Developer.LoadFromFilesystem").getValue(false)) {
+ String path = startConfiguration.getStringValue("Developer.FilesystemPath").getValue(null);
+ if (path != null) {
+ bind(Loaders.class).toInstance(new DebugLoaders(path));
+ }
+ }
+ bindListener(Matchers.any(), new TypeListener() {
+
+ @Override
+ public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) {
+ typeEncounter.register(new InjectionListener<I>() {
+
+ @Override
+ public void afterInjection(I injectee) {
+ eventBus.register(injectee);
+ }
+ });
+ }
+ });
+ }
+
+ private TypeLiteral<Optional<Context>> getOptionalContextTypeLiteral() {
+ return new TypeLiteral<Optional<Context>>() {
+ };
+ }
+
+ };
+ Injector injector = Guice.createInjector(freenetModule, soneModule);
+ core = injector.getInstance(Core.class);
+
+ /* create web of trust connector. */
+ webOfTrustConnector = injector.getInstance(WebOfTrustConnector.class);
+
+ /* create FCP interface. */
+ fcpInterface = injector.getInstance(FcpInterface.class);
+
+ /* create the web interface. */
+ webInterface = injector.getInstance(WebInterface.class);
+
+ /* start core! */
+ core.start();
+ webInterface.start();
+ webInterface.setFirstStart(firstStart);
+ webInterface.setNewConfig(newConfig);