Procházet zdrojové kódy

Start support for unattended installs.

Issue 1319


git-svn-id: http://svn.dmdirc.com/trunk@4172 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Shane Mc Cormack před 16 roky
rodič
revize
243120c1ac

+ 23
- 24
src/com/dmdirc/installer/Installer.java Zobrazit soubor

@@ -35,35 +35,35 @@ import java.nio.channels.FileChannel;
35 35
  * @author Shane Mc Cormack
36 36
  */
37 37
 public abstract class Installer extends Thread {
38
-    
38
+	
39 39
 	/** Types of shortcut. */
40 40
 	public static enum ShortcutType {
41
-        /** Desktop shortcut. */
42
-        DESKTOP,
43
-        /** Menu (start/k/etc) shortcut. */
44
-        MENU,
45
-        /** Quick launch shortcut. */
46
-        QUICKLAUNCH,
47
-        /** The actual uninstaller (not a shortcut, as far as I can tell). */
48
-        UNINSTALLER,
49
-        /** Associate DMDirc with the irc:// protocol (not a shortcut). */
50
-        PROTOCOL;
51
-    }
41
+		/** Desktop shortcut. */
42
+		DESKTOP,
43
+		/** Menu (start/k/etc) shortcut. */
44
+		MENU,
45
+		/** Quick launch shortcut. */
46
+		QUICKLAUNCH,
47
+		/** The actual uninstaller (not a shortcut, as far as I can tell). */
48
+		UNINSTALLER,
49
+		/** Associate DMDirc with the irc:// protocol (not a shortcut). */
50
+		PROTOCOL;
51
+	}
52 52
 	
53 53
 	/** Step where things happen. */
54 54
 	protected StepInstall step;
55
-    
55
+	
56 56
 	/**
57 57
 	 * Create a new Installer.
58 58
 	 */
59 59
 	public Installer() {
60 60
 		super("Installer-Thread");
61
-	}    
61
+	}
62 62
 	
63 63
 	/**
64 64
 	 * Get the default install location.
65
-     * 
66
-     * @return The default install location
65
+	 *
66
+	 * @return The default install location
67 67
 	 */
68 68
 	public abstract String defaultInstallLocation();
69 69
 	
@@ -80,7 +80,7 @@ public abstract class Installer extends Thread {
80 80
 	/**
81 81
 	 * This step performs the installation, via the StepInstall step.
82 82
 	 */
83
-    @Override
83
+	@Override
84 84
 	public final void run() {
85 85
 		step.performInstall(this);
86 86
 	}
@@ -107,8 +107,8 @@ public abstract class Installer extends Thread {
107 107
 		try {
108 108
 			final File dir = new File(".");
109 109
 			final FilenameFilter filter = new FilenameFilter() {
110
-                /** {@inheritDoc} */
111
-                @Override
110
+				/** {@inheritDoc} */
111
+				@Override
112 112
 				public boolean accept(final File dir, final String name) {
113 113
 					return name.charAt(0) != '.' && validFile(name);
114 114
 				}
@@ -160,8 +160,8 @@ public abstract class Installer extends Thread {
160 160
 	 * Based on http://www.exampledepot.com/egs/java.io/CopyFile.html
161 161
 	 *
162 162
 	 * @param srcFile Original file
163
-     * @param dstFile New file
164
-     * @throws java.io.IOException If an exception occurs while copying
163
+	 * @param dstFile New file
164
+	 * @throws java.io.IOException If an exception occurs while copying
165 165
 	 */
166 166
 	protected final void copyFile(final String srcFile, final String dstFile) throws IOException {
167 167
 		if (new File(srcFile).exists()) {
@@ -184,7 +184,6 @@ public abstract class Installer extends Thread {
184 184
 	 * @param location Location where app was installed to.
185 185
 	 */
186 186
 	public void postInstall(final String location) {
187
-        // Nothing to do by default, installers may override
188
-    }
189
-    
187
+		// Nothing to do by default, installers may override
188
+	}
190 189
 }

+ 3
- 3
src/com/dmdirc/installer/LinuxInstaller.java Zobrazit soubor

@@ -47,7 +47,7 @@ public class LinuxInstaller extends Installer {
47 47
 	 * @param filename File to check
48 48
 	 * @return true If the file should be copied, else false.
49 49
 	 */
50
-    @Override
50
+	@Override
51 51
 	public boolean validFile(final String filename) {
52 52
 		return (!filename.equalsIgnoreCase("setup.sh") &&
53 53
 		        !filename.equalsIgnoreCase("getjre.sh") &&
@@ -56,7 +56,7 @@ public class LinuxInstaller extends Installer {
56 56
 	}
57 57
 
58 58
 	/** {@inheritDoc} */
59
-    @Override
59
+	@Override
60 60
 	public String defaultInstallLocation() {
61 61
 		String result = "";
62 62
 		if (CLIParser.getCLIParser().getParamNumber("-directory") > 0) {
@@ -78,7 +78,7 @@ public class LinuxInstaller extends Installer {
78 78
 	 * @param shortcutType Type of shortcut to check
79 79
 	 * @return True if this OS supports a given shortcut Type
80 80
 	 */
81
-    @Override
81
+	@Override
82 82
 	public boolean supportsShortcut(final ShortcutType shortcutType) {
83 83
 		switch (shortcutType) {
84 84
 			case QUICKLAUNCH:

+ 21
- 14
src/com/dmdirc/installer/Main.java Zobrazit soubor

@@ -42,8 +42,8 @@ import javax.swing.JOptionPane;
42 42
  * @author Shane Mc Cormack
43 43
  */
44 44
 public final class Main implements WizardListener {
45
-
46
-    /** Wizard dialog. */
45
+	
46
+	/** Wizard dialog. */
47 47
 	private static WizardFrame wizardDialog;
48 48
 	
49 49
 	/** Installer. */
@@ -51,7 +51,7 @@ public final class Main implements WizardListener {
51 51
 	
52 52
 	/** CLI Parser. */
53 53
 	private static CLIParser cli = CLIParser.getCLIParser();
54
-
54
+	
55 55
 	/**
56 56
 	 * Creates and Displays the Installer wizard.
57 57
 	 */
@@ -68,7 +68,7 @@ public final class Main implements WizardListener {
68 68
 		}
69 69
 		
70 70
 		setWizardFrame(new WizardFrame(releaseName + " Installer", new ArrayList<Step>(), this));
71
-        wizardDialog.setIconImage(IconManager.getIconManager().getImage("icon"));
71
+		wizardDialog.setIconImage(IconManager.getIconManager().getImage("icon"));
72 72
 		wizardDialog.setPreferredSize(new Dimension(400, 350));
73 73
 		wizardDialog.addWizardListener(this);
74 74
 
@@ -77,16 +77,18 @@ public final class Main implements WizardListener {
77 77
 		if (osName.startsWith("Mac OS")) {
78 78
 			wizardDialog.addStep(new StepError("Sorry, OSX Installation should be done using the downloadable dmg file, not this installer.\n\n"));
79 79
 		} else {
80
-			wizardDialog.addStep(new StepSettings());
81
-			wizardDialog.addStep(new StepConfirm(wizardDialog));
80
+			if (CLIParser.getCLIParser().getParamNumber("-unattended") == 0) {
81
+				wizardDialog.addStep(new StepSettings());
82
+				wizardDialog.addStep(new StepConfirm(wizardDialog));
83
+			}
82 84
 			wizardDialog.addStep(new StepInstall(wizardDialog));
83 85
 		}
84 86
 	}
85
-    
87
+		
86 88
 	/**
87 89
 	 * Called when the wizard finishes.
88 90
 	 */
89
-    @Override
91
+	@Override
90 92
 	public void wizardFinished() {
91 93
 		final Thread temp = myInstaller;
92 94
 		myInstaller = null;
@@ -97,17 +99,17 @@ public final class Main implements WizardListener {
97 99
 	/**
98 100
 	 * Called when the wizard is cancelled.
99 101
 	 */
100
-    @Override
102
+	@Override
101 103
 	public void wizardCancelled() {	
102 104
 		if (wizardDialog.getCurrentStep() != 3 && JOptionPane.showConfirmDialog(wizardDialog, "Are you sure you want to cancel?", "Cancel confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
103 105
 			wizardDialog.dispose();
104 106
 		}
105
-	}    
107
+	}
106 108
 	
107 109
 	/**
108 110
 	 * Get the Installer object for this OS.
109
-     * 
110
-     * @return The installer for this OS
111
+	 *
112
+	 * @return The installer for this OS
111 113
 	 */
112 114
 	public static synchronized Installer getInstaller() {
113 115
 		if (myInstaller == null) {
@@ -133,6 +135,11 @@ public final class Main implements WizardListener {
133 135
 		cli.add(new BooleanParam((char) 0, "isroot", "Installing as Root"));
134 136
 		cli.add(new StringParam('r', "release", "Release Name"));
135 137
 		cli.add(new StringParam('d', "directory", "Default install directory"));
138
+		cli.add(new BooleanParam('u', "unattended", "Perform an unattended installation"));
139
+		cli.add(new BooleanParam((char) 0, "no-shortcut-desktop", "Don't offer a desktop shortcut as the default"));
140
+		cli.add(new BooleanParam((char) 0, "no-shortcut-menu", "Don't offer a menu shortcut as the default"));
141
+		cli.add(new BooleanParam((char) 0, "no-shortcut-quicklaunch", "Don't offer a quick launch shortcut as the default"));
142
+		cli.add(new BooleanParam((char) 0, "no-shortcut-protocol", "Don't offer to handle irc:// links as the default"));
136 143
 	}
137 144
 	
138 145
 	/**
@@ -158,8 +165,8 @@ public final class Main implements WizardListener {
158 165
 
159 166
 	/**
160 167
 	 * Run the installer.
161
-     * 
162
-     * @param args Command line arguments
168
+	 *
169
+	 * @param args Command line arguments
163 170
 	 */
164 171
 	public static void main(final String[] args) {
165 172
 		setupCLIParser();

+ 6
- 3
src/com/dmdirc/installer/StepInstall.java Zobrazit soubor

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.installer;
24 24
 
25
+import com.dmdirc.installer.cliparser.CLIParser;
25 26
 import com.dmdirc.installer.Installer.ShortcutType;
26 27
 import com.dmdirc.ui.swing.dialogs.wizard.Step;
27 28
 import com.dmdirc.ui.swing.dialogs.wizard.StepListener;
@@ -92,7 +93,11 @@ public final class StepInstall extends Step implements StepListener {
92 93
 	 */
93 94
 	public void performInstall(final Installer myInstaller) {
94 95
 		infoLabel.setText("Beginning Install..\n");
95
-		final String location = ((StepSettings) Main.getWizardFrame().getStep(1)).getInstallLocation();
96
+		
97
+		final boolean isUnattended = (CLIParser.getCLIParser().getParamNumber("-unattended") == 0);
98
+		final StepSettings settings = (isUnattended) ? new StepSettings() : ((StepSettings) Main.getWizardFrame().getStep(1));
99
+		
100
+		final String location = settings.getInstallLocation();
96 101
 
97 102
 		addText("Installing files to: "+location);
98 103
 		if (!myInstaller.doSetup(location)) {
@@ -102,8 +107,6 @@ public final class StepInstall extends Step implements StepListener {
102 107
 			return;
103 108
 		}
104 109
 
105
-		StepSettings settings = ((StepSettings) Main.getWizardFrame().getStep(1));
106
-
107 110
 		if (Main.getInstaller().supportsShortcut(ShortcutType.MENU)) {
108 111
 			if (settings.getShortcutMenuState()) {
109 112
 				addText("Setting up "+Main.getInstaller().getMenuName()+" shortcut");

+ 5
- 4
src/com/dmdirc/installer/StepSettings.java Zobrazit soubor

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.installer;
24 24
 
25
+import com.dmdirc.installer.cliparser.CLIParser;
25 26
 import com.dmdirc.installer.Installer.ShortcutType;
26 27
 import com.dmdirc.ui.swing.dialogs.wizard.Step;
27 28
 import com.dmdirc.ui.swing.components.TextLabel;
@@ -79,10 +80,10 @@ public final class StepSettings extends Step {
79 80
 //		infoLabel.setBackground(getBackground());
80 81
 		infoLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, SMALL_BORDER, 0));
81 82
 
82
-		shortcutMenu.setSelected(true);
83
-		shortcutDesktop.setSelected(true);
84
-		shortcutQuick.setSelected(true);
85
-		shortcutProtocol.setSelected(true);
83
+		shortcutMenu.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-menu") == 0));
84
+		shortcutDesktop.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-desktop") == 0));
85
+		shortcutQuick.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-quicklaunch") == 0));
86
+		shortcutProtocol.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-protocol") == 0));
86 87
 
87 88
 		constraints.weightx = 1.0;
88 89
 		constraints.fill = constraints.BOTH;

+ 3
- 3
src/com/dmdirc/installer/StreamReader.java Zobrazit soubor

@@ -28,7 +28,7 @@ import java.io.InputStream;
28 28
 import java.io.InputStreamReader;
29 29
 
30 30
 public class StreamReader extends Thread {
31
-    
31
+	
32 32
 	/** This is the Input Stream we are reading */
33 33
 	private final InputStream stream;
34 34
 	
@@ -66,8 +66,8 @@ public class StreamReader extends Thread {
66 66
 		}
67 67
 	}
68 68
 
69
-    /** {@inheritDoc} */
70
-    @Override
69
+	/** {@inheritDoc} */
70
+	@Override
71 71
 	public void run() {
72 72
 		final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
73 73
 		try {

Načítá se…
Zrušit
Uložit