aboutsummaryrefslogtreecommitdiff
path: root/subsonic-booter/src/main/java/net/sourceforge/subsonic/booter/Main.java
blob: b7879e129fe02d53b49d99ce2ae4fed45dc8dd3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package net.sourceforge.subsonic.booter;

import java.util.Arrays;
import java.util.List;

import javax.swing.JOptionPane;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import net.sourceforge.subsonic.booter.agent.SettingsPanel;
import net.sourceforge.subsonic.booter.agent.SubsonicAgent;

/**
 * Application entry point for Subsonic booter.
 * <p/>
 * Use command line argument "-agent" to start the Windows service monitoring agent,
 * or "-mac" to start the Mac version of the deployer.
 *
 * @author Sindre Mehus
 */
public class Main {

    public Main(String contextName, List<String> args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext" + contextName + ".xml");

        if ("-agent".equals(contextName)) {

            SubsonicAgent agent = (SubsonicAgent) context.getBean("agent");
            SettingsPanel settingsPanel = (SettingsPanel) context.getBean("settingsPanel");

            agent.setElevated(args.contains("-elevated"));

            if (args.contains("-balloon")) {
                agent.showTrayIconMessage();
            }

            if (args.contains("-stop")) {
                agent.startOrStopService(false);
                agent.showStatusPanel();
            } else if (args.contains("-start")) {
                agent.startOrStopService(true);
                agent.showStatusPanel();
            }

            if (args.contains("-settings")) {
                String[] settings = args.get(args.indexOf("-settings") + 1).split(",");
                try {
                    agent.showSettingsPanel();
                    settingsPanel.saveSettings(Integer.valueOf(settings[0]), Integer.valueOf(settings[1]), Integer.valueOf(settings[2]), settings[3]);
                    settingsPanel.readValues();
                } catch (Exception x) {
                    JOptionPane.showMessageDialog(settingsPanel, x.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
                }
            }
        }
    }

    public static void main(String[] args) {
        String context = "-deployer";
        if (args.length > 0) {
            context = args[0];
        }
        new Main(context, Arrays.asList(args));
    }
}