Package net.sourceforge.fullsync.impl

Examples of net.sourceforge.fullsync.impl.ConfigurationPreferences


        if (!newPreferences.exists() && oldPreferences.exists()) {
          backupFile(oldPreferences, newPreferences, "preferences_old.properties");
        }
      }
      while (false); // variable scope
      final ConfigurationPreferences preferences = new ConfigurationPreferences(configDir + "preferences.properties");
     
      String profilesFile = "profiles.xml";
      if (line.hasOption("P")) {
        profilesFile = line.getOptionValue("P");
      }
      else {
        profilesFile = configDir + "profiles.xml";
        // upgrade code...
        File newProfiles = new File(profilesFile);
        File oldProfiles = new File("profiles.xml");
        if (!newProfiles.exists()) {
          if (!oldProfiles.exists()) {
            // on windows FullSync 0.9.1 installs itself into %ProgramFiles%\FullSync while 0.10.0 installs itself into %ProgramFiles%\FullSync\FullSync by default
            oldProfiles = new File(".." + File.separator + "profiles.xml");
          }
          if (oldProfiles.exists()) {
            backupFile(oldProfiles, newProfiles, "profiles_old.xml");
          }
        }
      }
      ProfileManager profileManager = new ProfileManager(profilesFile);

      final Synchronizer sync = new Synchronizer();

      // Apply executing options
      if (line.hasOption("r")) {
        Profile p = profileManager.getProfile(line.getOptionValue("r"));
        TaskTree tree = sync.executeProfile(p, false);
        sync.performActions(tree);
        p.setLastUpdate(new Date());
        profileManager.save();
        return;
      }

      boolean activateRemote = false;
      int port = 10000;
      String password = "admin";
      RemoteException listenerStarupException = null;

      if (line.hasOption("p")) {
        activateRemote = true;
        try {
          String portStr = line.getOptionValue("p");
          port = Integer.parseInt(portStr);
        }
        catch (NumberFormatException e) {
        }

        if (line.hasOption("a")) {
          password = line.getOptionValue("a");
        }
      }
      else {
        activateRemote = preferences.listeningForRemoteConnections();
        port = preferences.getRemoteConnectionsPort();
        password = preferences.getRemoteConnectionsPassword();
      }
      if (activateRemote) {
        try {
          Logger logger = LoggerFactory.getLogger("FullSync");

          RemoteController.getInstance().startServer(port, password, profileManager, sync);
          logger.info("Remote Interface available on port: " + port);
        }
        catch (RemoteException e) {
          ExceptionHandler.reportException(e);
          listenerStarupException = e;
        }
      }

      if (line.hasOption("d")) {
        profileManager.addSchedulerListener(new ProfileSchedulerListener() {
          @Override
          public void profileExecutionScheduled(Profile profile) {
            TaskTree tree = sync.executeProfile(profile, false);
            if (tree == null) {
              profile.setLastError(1, "An error occured while comparing filesystems.");
            }
            else {
              int errorLevel = sync.performActions(tree);
              if (errorLevel > 0) {
                profile.setLastError(errorLevel, "An error occured while copying files.");
              }
              else {
                profile.setLastUpdate(new Date());
              }
            }
          }
        });
        profileManager.startScheduler();
        /*
         * Object mutex = new Object();
         * synchronized (mutex) {
         * mutex.wait();
         * }
         */
      }
      else {
        try {
          GuiController guiController = new GuiController(preferences, profileManager, sync);
          guiController.startGui(line.hasOption('m'));

          if (!line.hasOption('P') && !preferences.getHelpShown() && (null == System.getProperty("net.sourceforge.fullsync.skipHelp"))) {
            preferences.setHelpShown(true);
            preferences.save();
            File f = new File("docs/manual/manual.html");
            if (f.exists()) {
              GuiController.launchProgram(f.getAbsolutePath());
            }
          }

          if (listenerStarupException != null) {
            ExceptionHandler.reportException("Unable to start incoming connections listener.", listenerStarupException);
          }

          if (preferences.getAutostartScheduler()) {
            profileManager.startScheduler();
          }

          guiController.run();
          guiController.disposeGui();
View Full Code Here

TOP

Related Classes of net.sourceforge.fullsync.impl.ConfigurationPreferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.