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();
}
catch (Exception ex) {
ExceptionHandler.reportException(ex);
}
finally {
profileManager.save();
}
// FIXME [Michele] For some reasons there is some thread still alive if you run the remote interface
RemoteController.getInstance().stopServer();
if (null == System.getProperty("net.sourceforge.fullsync.skipExit")) {