1 | import java.util.ResourceBundle;
|
---|
2 | import java.awt.*;
|
---|
3 | import java.awt.event.*;
|
---|
4 | import javax.swing.JFrame;
|
---|
5 | import javax.swing.JPanel;
|
---|
6 | import javax.swing.JCheckBox;
|
---|
7 | import javax.swing.JLabel;
|
---|
8 | import javax.swing.JButton;
|
---|
9 | import javax.swing.BoxLayout;
|
---|
10 | import javax.swing.JTextArea;
|
---|
11 | import javax.swing.JScrollPane;
|
---|
12 | import javax.swing.border.EmptyBorder;
|
---|
13 | import javax.swing.JOptionPane;
|
---|
14 | import javax.swing.Box;
|
---|
15 | import javax.swing.JDialog;
|
---|
16 | import javax.swing.JMenuItem;
|
---|
17 | import javax.swing.JPopupMenu;
|
---|
18 |
|
---|
19 | import java.io.File;
|
---|
20 | import java.io.BufferedReader;
|
---|
21 | import java.io.FileReader;
|
---|
22 | import java.io.FileNotFoundException;
|
---|
23 | import java.io.FileWriter;
|
---|
24 | import java.io.IOException;
|
---|
25 |
|
---|
26 | import java.util.regex.Pattern;
|
---|
27 | import java.util.regex.Matcher;
|
---|
28 | import java.util.ArrayList;
|
---|
29 |
|
---|
30 | import javax.swing.SwingUtilities;
|
---|
31 |
|
---|
32 | import java.util.Enumeration;
|
---|
33 | import java.awt.Font;
|
---|
34 | import javax.swing.plaf.FontUIResource;
|
---|
35 | import javax.swing.UIManager;
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | public class Uninstaller {
|
---|
40 |
|
---|
41 | public static int SCREEN_WIDTH = 600;
|
---|
42 | public static int SCREEN_HEIGHT = 450;
|
---|
43 |
|
---|
44 | public static final ResourceBundle bundle = ResourceBundle.getBundle("resources.LanguagePack");
|
---|
45 |
|
---|
46 | public static final File gs2InstallProps = new File("../etc/installation.properties");
|
---|
47 | public static final File gs3InstallProps = new File("../installation.properties");
|
---|
48 |
|
---|
49 | boolean keepCollections = true;
|
---|
50 | //boolean keepModifiedFiles = false;
|
---|
51 | boolean ignoreReadOnlys = false;
|
---|
52 |
|
---|
53 | JFrame frame;
|
---|
54 | JCheckBox keepCollectionsCheckbox;
|
---|
55 | //JCheckBox keepModifiedFilesCheckbox;
|
---|
56 |
|
---|
57 | //panels
|
---|
58 | JPanel progressPanel;
|
---|
59 | JPanel introPanel;
|
---|
60 |
|
---|
61 | //toolbars
|
---|
62 | JPanel initialToolbar;
|
---|
63 | JPanel finishToolbar;
|
---|
64 |
|
---|
65 |
|
---|
66 | JScrollPane logPane;
|
---|
67 | FollowingJTextArea log;
|
---|
68 | JButton uninstallButton;
|
---|
69 | JButton finishButton;
|
---|
70 |
|
---|
71 | boolean confirmationGiven = false;
|
---|
72 | Thread mainThread = null;
|
---|
73 |
|
---|
74 | public static void main( String[] args ) {
|
---|
75 | (new Uninstaller()).go();
|
---|
76 | }
|
---|
77 |
|
---|
78 | public void go() {
|
---|
79 |
|
---|
80 | //set font
|
---|
81 | String new_default_font_str = null;
|
---|
82 | if ( System.getProperty("os.name").equals("Linux") ) {
|
---|
83 | new_default_font_str = "Bitstream Cyberbit";
|
---|
84 | } else if ( System.getProperty("os.name").startsWith("Windows") ) {
|
---|
85 | new_default_font_str = "Arial Unicode MS";
|
---|
86 | }
|
---|
87 |
|
---|
88 | if ( new_default_font_str != null ) {
|
---|
89 |
|
---|
90 | FontUIResource default_font = new FontUIResource(new_default_font_str, Font.PLAIN, 12);
|
---|
91 | Enumeration keys = UIManager.getDefaults().keys();
|
---|
92 | while (keys.hasMoreElements()) {
|
---|
93 | Object key = keys.nextElement();
|
---|
94 | Object value = UIManager.get(key);
|
---|
95 | if (value instanceof FontUIResource) {
|
---|
96 | UIManager.put(key, default_font);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | mainThread = Thread.currentThread();
|
---|
104 |
|
---|
105 | frame = new JFrame();
|
---|
106 | frame.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
---|
107 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
---|
108 | frame.setLocation(screenSize.width/2 - frame.getWidth()/2, screenSize.height/2 - frame.getHeight()/2);
|
---|
109 |
|
---|
110 | //The panel to introduce and ask for options
|
---|
111 | introPanel = new JPanel(new BorderLayout());
|
---|
112 | JPanel innerPanel = new JPanel();
|
---|
113 | innerPanel.setLayout( new BoxLayout(innerPanel,BoxLayout.Y_AXIS) );
|
---|
114 | innerPanel.setBorder( new EmptyBorder(10, 10, 5, 10) );
|
---|
115 | introPanel.add( BorderLayout.WEST, innerPanel );
|
---|
116 |
|
---|
117 | //The panel to be displayed while the uninstall is happening
|
---|
118 | progressPanel = new JPanel(new BorderLayout());
|
---|
119 | log = new FollowingJTextArea();
|
---|
120 | log.setEditable(false);
|
---|
121 | logPane = new JScrollPane(log);
|
---|
122 | logPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
---|
123 | logPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
---|
124 | progressPanel.add( BorderLayout.NORTH, new JLabel("Progress") );
|
---|
125 | progressPanel.add( BorderLayout.CENTER, logPane );
|
---|
126 |
|
---|
127 | //initial toolbar
|
---|
128 | initialToolbar = new JPanel();
|
---|
129 | uninstallButton = new JButton(bundle.getString("uninstaller.uninstall"));
|
---|
130 | uninstallButton.addActionListener( new StartUninstallListener() );
|
---|
131 | JButton cancelButton = new JButton(bundle.getString("uninstaller.cancel"));
|
---|
132 | cancelButton.addActionListener( new CancelListener() );
|
---|
133 | initialToolbar.add(uninstallButton);
|
---|
134 | initialToolbar.add(cancelButton);
|
---|
135 |
|
---|
136 | //finish toolbar
|
---|
137 | finishToolbar = new JPanel();
|
---|
138 | finishButton = new JButton(bundle.getString("uninstaller.finish"));
|
---|
139 | finishButton.addActionListener( new FinishListener() );
|
---|
140 | finishButton.setEnabled( false );
|
---|
141 | finishToolbar.add( finishButton );
|
---|
142 |
|
---|
143 |
|
---|
144 | String pwd = (new File(".")).getAbsolutePath();
|
---|
145 | if ( pwd.endsWith("/.") ) {
|
---|
146 | pwd = pwd.substring( 0, pwd.length()-2 );
|
---|
147 | }
|
---|
148 |
|
---|
149 | JLabel l;
|
---|
150 |
|
---|
151 | l = new JLabel(bundle.getString("uninstaller.will.uninstall.from"));
|
---|
152 | innerPanel.add( l );
|
---|
153 | innerPanel.add( Box.createRigidArea(new Dimension(5,5)) );
|
---|
154 |
|
---|
155 | l = new JLabel(" " + pwd);
|
---|
156 | l.setFont( new Font( "Monospaced", Font.BOLD, 14 ) );
|
---|
157 | innerPanel.add( l );
|
---|
158 | innerPanel.add( Box.createRigidArea(new Dimension(5,20)) );
|
---|
159 |
|
---|
160 | l = new JLabel(bundle.getString("uninstaller.uninstall.options"));
|
---|
161 | innerPanel.add( l );
|
---|
162 |
|
---|
163 | keepCollectionsCheckbox = new JCheckBox(bundle.getString("uninstaller.keep.collections"));
|
---|
164 | keepCollectionsCheckbox.setSelected(true);
|
---|
165 | innerPanel.add( keepCollectionsCheckbox );
|
---|
166 |
|
---|
167 | //keepModifiedFilesCheckbox = new JCheckBox("Keep Modified Files");
|
---|
168 | //innerPanel.add( keepModifiedFilesCheckbox );
|
---|
169 |
|
---|
170 | frame.setTitle( bundle.getString("uninstaller.greenstone.uninstaller") );
|
---|
171 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
172 |
|
---|
173 | //the initial screen
|
---|
174 | frame.getContentPane().add( BorderLayout.CENTER, introPanel );
|
---|
175 | frame.getContentPane().add( BorderLayout.SOUTH, initialToolbar );
|
---|
176 |
|
---|
177 | frame.setVisible(true);
|
---|
178 |
|
---|
179 | boolean ready = precheck();
|
---|
180 | if ( !ready ) {
|
---|
181 | System.exit(0);
|
---|
182 | }
|
---|
183 |
|
---|
184 | //block and wait for signal to do the uninstall
|
---|
185 | do {
|
---|
186 | try {
|
---|
187 | Thread.sleep( Long.MAX_VALUE );
|
---|
188 | } catch ( InterruptedException ie ) {
|
---|
189 | }
|
---|
190 | } while ( !confirmationGiven );
|
---|
191 |
|
---|
192 | doUninstall();
|
---|
193 | finishButton.setEnabled( true );
|
---|
194 |
|
---|
195 | }
|
---|
196 |
|
---|
197 | class CancelListener implements ActionListener {
|
---|
198 | public void actionPerformed( ActionEvent e ) {
|
---|
199 | System.exit(0);
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | class FinishListener implements ActionListener {
|
---|
204 | public void actionPerformed( ActionEvent e ) {
|
---|
205 | System.exit(0);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | class StartUninstallListener implements ActionListener {
|
---|
210 | public void actionPerformed( ActionEvent e ) {
|
---|
211 |
|
---|
212 | //The dialog to ask "are you sure"
|
---|
213 | Object[] options = { bundle.getString("uninstaller.uninstall"), bundle.getString("uninstaller.cancel") };
|
---|
214 | int n = JOptionPane.showOptionDialog(
|
---|
215 | frame,
|
---|
216 | bundle.getString("uninstaller.are.you.sure"),
|
---|
217 | bundle.getString("uninstaller.confirmation"),
|
---|
218 | JOptionPane.YES_NO_CANCEL_OPTION,
|
---|
219 | JOptionPane.QUESTION_MESSAGE,
|
---|
220 | null,
|
---|
221 | options,
|
---|
222 | options[0]
|
---|
223 | );
|
---|
224 | if ( n == 1 ) {
|
---|
225 | return;
|
---|
226 | }
|
---|
227 |
|
---|
228 | keepCollections = keepCollectionsCheckbox.isSelected();
|
---|
229 | //keepModifiedFiles = keepModifiedFilesCheckbox.isSelected();
|
---|
230 |
|
---|
231 | //confirm delete of collections
|
---|
232 | if ( !keepCollections ) {
|
---|
233 | options[0] = bundle.getString("uninstaller.continue");
|
---|
234 | options[1] = bundle.getString("uninstaller.cancel");
|
---|
235 | n = JOptionPane.showOptionDialog(
|
---|
236 | frame,
|
---|
237 | bundle.getString("uninstaller.are.you.sure.collections"),
|
---|
238 | bundle.getString("uninstaller.confirmation"),
|
---|
239 | JOptionPane.YES_NO_CANCEL_OPTION,
|
---|
240 | JOptionPane.WARNING_MESSAGE,
|
---|
241 | null,
|
---|
242 | options,
|
---|
243 | options[0]
|
---|
244 | );
|
---|
245 | if ( n == 1 ) {
|
---|
246 | return;
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | introPanel.setVisible( false );
|
---|
252 | frame.getContentPane().remove(introPanel);
|
---|
253 | frame.getContentPane().add( BorderLayout.CENTER, progressPanel );
|
---|
254 |
|
---|
255 | initialToolbar.setVisible( false );
|
---|
256 | frame.getContentPane().remove( initialToolbar );
|
---|
257 | frame.getContentPane().add( BorderLayout.SOUTH, finishToolbar);
|
---|
258 |
|
---|
259 | confirmationGiven = true;
|
---|
260 | mainThread.interrupt();
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Do some checks
|
---|
266 | */
|
---|
267 | public boolean precheck() {
|
---|
268 |
|
---|
269 | if ( !gs2InstallProps.exists() && !gs3InstallProps.exists() ) {
|
---|
270 | log( bundle.getString("uninstaller.error.couldnt.find.install.props") + "\n" );
|
---|
271 | JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.error.couldnt.find.install.props"), bundle.getString("uninstaller.error"), 0);
|
---|
272 | return false;
|
---|
273 | }
|
---|
274 | return true;
|
---|
275 |
|
---|
276 | }
|
---|
277 |
|
---|
278 | public void log( String s ) {
|
---|
279 | SwingUtilities.invokeLater( new LogAppender( s ) );
|
---|
280 | //log.append( s );
|
---|
281 |
|
---|
282 | }
|
---|
283 |
|
---|
284 | /**
|
---|
285 | * Does the uninstall
|
---|
286 | */
|
---|
287 | public void doUninstall() {
|
---|
288 |
|
---|
289 | File startMenuPath = null;
|
---|
290 |
|
---|
291 | //delete the start menu group if present
|
---|
292 |
|
---|
293 | if ( gs2InstallProps.exists() ) {
|
---|
294 | String smp = null;
|
---|
295 | try {
|
---|
296 | smp = getPropertyValue( "installed.startmenu.path", gs2InstallProps );
|
---|
297 | } catch ( Exception e ) {
|
---|
298 | System.err.println( e.getMessage() );
|
---|
299 | }
|
---|
300 | if ( smp != null ) {
|
---|
301 | startMenuPath = new File( smp );
|
---|
302 | }
|
---|
303 | } else if ( gs3InstallProps.exists() ) {
|
---|
304 | String smp = null;
|
---|
305 | try {
|
---|
306 | smp = getPropertyValue( "installed.startmenu.path", gs3InstallProps );
|
---|
307 | } catch ( Exception e ) {
|
---|
308 | System.err.println( e.getMessage() );
|
---|
309 | }
|
---|
310 | if ( smp != null ) {
|
---|
311 | startMenuPath = new File( smp );
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | if ( startMenuPath == null ) {
|
---|
316 |
|
---|
317 | log( bundle.getString("uninstaller.info.no.startmenu") + "\n" );
|
---|
318 |
|
---|
319 | } else {
|
---|
320 | log( "StartMenu Path: " + startMenuPath.getAbsolutePath() + "\n" );
|
---|
321 |
|
---|
322 | try {
|
---|
323 | recursiveDelete( startMenuPath, null );
|
---|
324 | } catch ( CancelledException ce ) {
|
---|
325 | log( bundle.getString("uninstaller.cancelled") + "\n" );
|
---|
326 | changeToFinishToolbar();
|
---|
327 | JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.cancelled"), bundle.getString("uninstaller.complete"), 1);
|
---|
328 | return;
|
---|
329 | }
|
---|
330 | }
|
---|
331 |
|
---|
332 | //delete the files
|
---|
333 | try {
|
---|
334 | ArrayList exceptions = new ArrayList();
|
---|
335 |
|
---|
336 | //never delete the things we are currently running
|
---|
337 | exceptions.add( new File("../bin/search4j.exe") );
|
---|
338 | exceptions.add( new File("../bin/search4j") );
|
---|
339 |
|
---|
340 | exceptions.add( new File("../bin/windows/search4j.exe") );
|
---|
341 | exceptions.add( new File("../bin/linux/search4j") );
|
---|
342 | exceptions.add( new File("../bin/darwin/search4j") );
|
---|
343 |
|
---|
344 | exceptions.add( new File("../packages/jre") );
|
---|
345 | exceptions.add( new File("../uninstall") );
|
---|
346 |
|
---|
347 | if ( keepCollections ) {
|
---|
348 | exceptions.add( new File("../web/sites/localsite/collect") );
|
---|
349 | exceptions.add( new File("../collect") );
|
---|
350 | }
|
---|
351 |
|
---|
352 |
|
---|
353 | File cd = null;
|
---|
354 | try {
|
---|
355 | cd = new File( new File(".").getCanonicalPath() );
|
---|
356 | } catch ( Exception e ) {
|
---|
357 | JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.failed.to.figure.cd"), bundle.getString("uninstaller.error") , 0);
|
---|
358 | System.exit(0);
|
---|
359 | }
|
---|
360 |
|
---|
361 | File[] ex = new File[exceptions.size()];
|
---|
362 | for ( int i=0; i<exceptions.size(); i++ ) {
|
---|
363 | ex[i] = (File)exceptions.get(i);
|
---|
364 | }
|
---|
365 |
|
---|
366 | //recursiveDelete( cd , ex );
|
---|
367 | selectiveDelete ( cd, ex );
|
---|
368 | } catch ( CancelledException ce ) {
|
---|
369 | log( bundle.getString("uninstaller.cancelled") + "\n" );
|
---|
370 | JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.cancelled"), bundle.getString("uninstaller.complete"), 1);
|
---|
371 | changeToFinishToolbar();
|
---|
372 | return;
|
---|
373 | }
|
---|
374 |
|
---|
375 | //create the flag file to indicate the uninstaller wants jre and uninst.jar to be deleted
|
---|
376 | try {
|
---|
377 | (new File("uninst.flag")).createNewFile();
|
---|
378 | } catch (Exception e) {
|
---|
379 | log( bundle.getString("uninstaller.couldnt-create-flagfile") + "\n" );
|
---|
380 | }
|
---|
381 |
|
---|
382 | changeToFinishToolbar();
|
---|
383 | log( bundle.getString("uninstaller.finished") );
|
---|
384 | JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.finished"), bundle.getString("uninstaller.complete"), 1);
|
---|
385 | }
|
---|
386 |
|
---|
387 | class LogAppender implements Runnable {
|
---|
388 | String s;
|
---|
389 |
|
---|
390 | public LogAppender( String s ) {
|
---|
391 | this.s = s;
|
---|
392 | }
|
---|
393 |
|
---|
394 | public void run() {
|
---|
395 | log.append( s );
|
---|
396 | }
|
---|
397 |
|
---|
398 | }
|
---|
399 |
|
---|
400 | public String getPropertyValue( String propertyName, File file ) throws Exception {
|
---|
401 |
|
---|
402 | String regex = "^" + propertyName.replaceAll("\\.","\\\\.") + "[:=]\\s*(.*)$";
|
---|
403 | Pattern wantedLine = Pattern.compile( regex );
|
---|
404 | BufferedReader in = null;
|
---|
405 | try {
|
---|
406 | in = new BufferedReader(new FileReader( file ));
|
---|
407 | } catch ( Exception e ) {
|
---|
408 | throw new Exception( "Error - couldn't open the properties file " + file );
|
---|
409 | }
|
---|
410 |
|
---|
411 | String line, value = null;
|
---|
412 |
|
---|
413 | try {
|
---|
414 | boolean found = false;
|
---|
415 | while ( (line = in.readLine()) != null && !found ) {
|
---|
416 |
|
---|
417 | Matcher matcher = wantedLine.matcher( line );
|
---|
418 | if ( matcher.matches() ) {
|
---|
419 | //found the property
|
---|
420 | //System.err.println( "found the property" );
|
---|
421 | value = matcher.group(1);
|
---|
422 | value = value.replaceAll( "#.*", "" ).trim();
|
---|
423 | return value;
|
---|
424 | }
|
---|
425 |
|
---|
426 | }
|
---|
427 |
|
---|
428 | //close the input stream
|
---|
429 | //System.err.println( "close the input stream" );
|
---|
430 | in.close();
|
---|
431 |
|
---|
432 | } catch ( Exception e ) {
|
---|
433 | throw new Exception( "Error - couldn't read from the properties file" );
|
---|
434 | }
|
---|
435 | return null;
|
---|
436 |
|
---|
437 | }
|
---|
438 |
|
---|
439 | public void selectiveDelete( File f, File[] exceptions ) throws CancelledException {
|
---|
440 |
|
---|
441 | File[] files = (new File(".")).listFiles();
|
---|
442 |
|
---|
443 | for ( int i=0; i < files.length; i++) {
|
---|
444 | if( files[i].getAbsolutePath().endsWith(".uninstall") ) {
|
---|
445 | String[] paths = getRelevantPathsFromUninstallFile(files[i]);
|
---|
446 |
|
---|
447 | for(int j=0; j < paths.length; j++) {
|
---|
448 | recursiveDelete( new File(".." + File.separator + paths[j]), exceptions );
|
---|
449 | }
|
---|
450 | }
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | public String[] getRelevantPathsFromUninstallFile ( File uninstallFile ) {
|
---|
455 |
|
---|
456 | ArrayList paths = new ArrayList();
|
---|
457 | try {
|
---|
458 | BufferedReader in = new BufferedReader(new FileReader(uninstallFile));
|
---|
459 |
|
---|
460 | String line;
|
---|
461 | while ( (line = in.readLine()) != null ) {
|
---|
462 | int separatorIndex = line.indexOf(File.separator);
|
---|
463 |
|
---|
464 | if ( separatorIndex == -1 && line.length() > 0 && !paths.contains(line)) {
|
---|
465 | paths.add(line);
|
---|
466 | }
|
---|
467 | else if ( separatorIndex > -1 && line.length() > 0) {
|
---|
468 | String path = line.substring(0, separatorIndex);
|
---|
469 | if ( !paths.contains(path) ) {
|
---|
470 | paths.add(path);
|
---|
471 | }
|
---|
472 | }
|
---|
473 | }
|
---|
474 |
|
---|
475 | in.close();
|
---|
476 | }
|
---|
477 | catch( Exception ex ) {
|
---|
478 | ex.printStackTrace();
|
---|
479 | return null;
|
---|
480 | }
|
---|
481 | return (String[]) paths.toArray(new String[0]);
|
---|
482 | }
|
---|
483 |
|
---|
484 | public void recursiveDelete( File f, File[] exceptions ) throws CancelledException {
|
---|
485 |
|
---|
486 | //log.append( "Processing: " + f.getAbsolutePath() + "\n" );
|
---|
487 |
|
---|
488 | // if this is an exception, return
|
---|
489 | if ( exceptions != null ) {
|
---|
490 | for ( int i=0; i<exceptions.length; i++ ) {
|
---|
491 | //System.out.println( "Comparing '" + f.getAbsolutePath() + "' with '" + exceptions[i].getAbsolutePath() + "'" );
|
---|
492 | try {
|
---|
493 | if ( f.equals( exceptions[i] ) || f.getCanonicalPath().equals(exceptions[i].getCanonicalPath()) ) {
|
---|
494 | log( Strings.replaceAll( bundle.getString("uninstaller.info.skipping"), "{file}", f.getAbsolutePath() ) + "\n" );
|
---|
495 | return;
|
---|
496 | }
|
---|
497 | } catch ( Exception e ) {
|
---|
498 | System.err.println("ERROR: Failed to resolve a path");
|
---|
499 | return;
|
---|
500 | }
|
---|
501 | }
|
---|
502 | }
|
---|
503 |
|
---|
504 | //if it is a directory, recurse
|
---|
505 | if (f.isDirectory()) {
|
---|
506 | File[] files = f.listFiles();
|
---|
507 | if ( files != null && files.length > 0) {
|
---|
508 | for ( int i=0; i<files.length; i++ ) {
|
---|
509 | try {
|
---|
510 | recursiveDelete( files[i], exceptions );
|
---|
511 | } catch ( CancelledException ce ) {
|
---|
512 | throw new CancelledException();
|
---|
513 | }
|
---|
514 | }
|
---|
515 | }
|
---|
516 | }
|
---|
517 |
|
---|
518 | //if this is now an empty directory, or a file, delete it
|
---|
519 | boolean doDelete = true;
|
---|
520 | if ( f.isDirectory() ) {
|
---|
521 | File[] files = f.listFiles();
|
---|
522 | doDelete = ( files == null || files.length == 0 );
|
---|
523 | }
|
---|
524 |
|
---|
525 | if ( doDelete ) {
|
---|
526 |
|
---|
527 | log( Strings.replaceAll( bundle.getString("uninstaller.deleting"), "{file}", f.getAbsolutePath() ) + "\n" );
|
---|
528 |
|
---|
529 | if ( !f.delete() ) {
|
---|
530 | log( "*********\n" + Strings.replaceAll( bundle.getString("uninstaller.warning.couldnt.delete"), "{file}", f.getAbsolutePath() ) + "\n*********\n" );
|
---|
531 | return;
|
---|
532 | }
|
---|
533 | }
|
---|
534 |
|
---|
535 | }
|
---|
536 |
|
---|
537 | class CancelledException extends Exception {}
|
---|
538 |
|
---|
539 | public void changeToFinishToolbar() {
|
---|
540 | initialToolbar.setVisible(false);
|
---|
541 | frame.getContentPane().remove(initialToolbar);
|
---|
542 | frame.getContentPane().add( BorderLayout.SOUTH, finishToolbar );
|
---|
543 | finishToolbar.setVisible(true);
|
---|
544 | }
|
---|
545 |
|
---|
546 | }
|
---|
547 |
|
---|
548 | class Strings {
|
---|
549 | static String replaceAll( String s, String nugget, String replacement ) {
|
---|
550 | StringBuffer string = new StringBuffer(s);
|
---|
551 | StringBuffer r = new StringBuffer();
|
---|
552 |
|
---|
553 | int io = 0;
|
---|
554 | while ( (io=string.toString().indexOf(nugget)) != -1 ) {
|
---|
555 | r.append( string.toString().substring( 0, io ) );
|
---|
556 | r.append( replacement );
|
---|
557 | string.delete( 0, io + nugget.length() );
|
---|
558 | }
|
---|
559 | r.append( string.toString() );
|
---|
560 | return r.toString();
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|
564 | class FollowingJTextArea extends JTextArea {
|
---|
565 |
|
---|
566 | private boolean follow = true;
|
---|
567 |
|
---|
568 | public FollowingJTextArea() {
|
---|
569 | jInit();
|
---|
570 | }
|
---|
571 |
|
---|
572 |
|
---|
573 | private void jInit(){
|
---|
574 | final JPopupMenu popUp = getPopupMenu();
|
---|
575 | this.add(popUp);
|
---|
576 | this.addMouseListener(new MouseAdapter(){
|
---|
577 | public void mouseClicked(MouseEvent e) {
|
---|
578 | if (e.getButton() == e.BUTTON3) {
|
---|
579 | popUp.show(FollowingJTextArea.this,e.getX(),e.getY());
|
---|
580 | }
|
---|
581 | }
|
---|
582 | });
|
---|
583 | }
|
---|
584 |
|
---|
585 | public boolean isFollow() {
|
---|
586 | return follow;
|
---|
587 | }
|
---|
588 | public void setFollow(boolean follow) {
|
---|
589 | this.follow = follow;
|
---|
590 | }
|
---|
591 |
|
---|
592 | private void scrollToEnd(){
|
---|
593 | setCaretPosition(getDocument().getLength());
|
---|
594 | }
|
---|
595 | private void toggleFollow(){
|
---|
596 | setFollow(!isFollow());
|
---|
597 | }
|
---|
598 |
|
---|
599 | /**
|
---|
600 | * Appends the given text to the end of the document.
|
---|
601 | *
|
---|
602 | * @param str the text to insert
|
---|
603 | * @todo Implement this javax.swing.JTextArea method
|
---|
604 | */
|
---|
605 | public void append(String str) {
|
---|
606 | super.append(str);
|
---|
607 | if(follow)scrollToEnd();
|
---|
608 | }
|
---|
609 | private JPopupMenu getPopupMenu() {
|
---|
610 | JPopupMenu contextMenu = new JPopupMenu("Options");
|
---|
611 |
|
---|
612 | JMenuItem toggleFollowMenu = new JMenuItem("Toggle Follow");
|
---|
613 | toggleFollowMenu.addActionListener(new ActionListener() {
|
---|
614 | public void actionPerformed(ActionEvent e) {
|
---|
615 | toggleFollow();
|
---|
616 | }
|
---|
617 | });
|
---|
618 | contextMenu.add(toggleFollowMenu);
|
---|
619 |
|
---|
620 | JMenuItem jumpToEndMenu = new JMenuItem("Jump To End");
|
---|
621 | jumpToEndMenu.addActionListener(new ActionListener() {
|
---|
622 | public void actionPerformed(ActionEvent e) {
|
---|
623 | setCaretPosition(getDocument().getLength());
|
---|
624 | }
|
---|
625 | });
|
---|
626 | contextMenu.add(toggleFollowMenu);
|
---|
627 |
|
---|
628 | JMenuItem clearTextMenu = new JMenuItem("Clear Text");
|
---|
629 | clearTextMenu.addActionListener(new ActionListener() {
|
---|
630 | public void actionPerformed(ActionEvent e) {
|
---|
631 | setText("");
|
---|
632 | }
|
---|
633 | });
|
---|
634 | contextMenu.add(clearTextMenu);
|
---|
635 | return contextMenu;
|
---|
636 | }
|
---|
637 | }
|
---|