Changeset 17805 for release-kits
- Timestamp:
- 2008-11-11T12:16:22+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
release-kits/shared/uninstaller/Uninstaller.java
r17792 r17805 1 1 import java.util.ResourceBundle; 2 2 import java.awt.*; 3 3 import java.awt.event.*; … … 14 14 import javax.swing.Box; 15 15 import javax.swing.JDialog; 16 import javax.swing.JMenuItem; 17 import javax.swing.JPopupMenu; 18 16 19 import java.io.File; 17 20 import java.io.BufferedReader; 18 21 import java.io.FileReader; 19 import java.io.File; 22 import java.io.FileNotFoundException; 23 import java.io.FileWriter; 24 import java.io.IOException; 25 20 26 import java.util.regex.Pattern; 21 27 import java.util.regex.Matcher; 22 28 import java.util.ArrayList; 23 29 24 import java.awt.event.ActionEvent; 25 import java.awt.event.ActionListener; 26 import java.awt.event.MouseAdapter; 27 import java.awt.event.MouseEvent; 28 import java.io.FileNotFoundException; 29 import java.io.FileWriter; 30 import java.io.IOException; 31 import javax.swing.JMenuItem; 32 import javax.swing.JPopupMenu; 33 import javax.swing.JTextArea; 30 import javax.swing.SwingUtilities; 31 34 32 35 33 public class Uninstaller { … … 61 59 62 60 JScrollPane logPane; 63 JTextArea log;61 FollowingJTextArea log; 64 62 JButton uninstallButton; 63 64 boolean confirmationGiven = false; 65 Thread mainThread = null; 65 66 66 67 67 public static void main( String[] args ) { 68 68 (new Uninstaller()).go(); … … 70 70 71 71 public void go() { 72 73 mainThread = Thread.currentThread(); 72 74 73 75 frame = new JFrame(); … … 91 93 logPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 92 94 progressPanel.add( BorderLayout.NORTH, new JLabel("Progress") ); 93 progressPanel.add( BorderLayout.CENTER, log );95 progressPanel.add( BorderLayout.CENTER, logPane ); 94 96 95 97 //initial toolbar … … 148 150 System.exit(0); 149 151 } 152 153 //block and wait for signal to do the uninstall 154 do { 155 try { 156 Thread.sleep( Long.MAX_VALUE ); 157 } catch ( InterruptedException ie ) { 158 } 159 } while ( !confirmationGiven ); 160 161 doUninstall(); 150 162 151 163 } … … 208 220 frame.getContentPane().remove(introPanel); 209 221 frame.getContentPane().add( BorderLayout.CENTER, progressPanel ); 210 progressPanel.setVisible( true ); 211 212 //start the unstinall 213 doUninstall(); 222 223 initialToolbar.setVisible( false ); 224 frame.getContentPane().remove( initialToolbar ); 225 frame.getContentPane().add( BorderLayout.SOUTH, finishToolbar); 226 227 confirmationGiven = true; 228 mainThread.interrupt(); 214 229 } 215 230 } … … 221 236 222 237 if ( !gs2InstallProps.exists() && !gs3InstallProps.exists() ) { 223 log .append( bundle.getString("uninstaller.error.couldnt.find.install.props") + "\n" );238 log( bundle.getString("uninstaller.error.couldnt.find.install.props") + "\n" ); 224 239 JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.error.couldnt.find.install.props"), bundle.getString("uninstaller.error"), 0); 225 240 return false; … … 227 242 return true; 228 243 244 } 245 246 public void log( String s ) { 247 SwingUtilities.invokeLater( new LogAppender( s ) ); 248 //log.append( s ); 249 229 250 } 230 251 … … 257 278 258 279 if ( startMenuPath == null ) { 259 log.append( bundle.getString("uninstaller.info.no.startmenu") + "\n" ); 260 log.repaint(); 280 281 log( bundle.getString("uninstaller.info.no.startmenu") + "\n" ); 282 261 283 } else { 262 log .append( "StartMenu Path: " + startMenuPath.getAbsolutePath() + "\n" );263 log.repaint(); 284 log( "StartMenu Path: " + startMenuPath.getAbsolutePath() + "\n" ); 285 264 286 try { 265 287 recursiveDelete( startMenuPath, null ); 266 288 } catch ( CancelledException ce ) { 267 log .append( bundle.getString("uninstaller.cancelled") + "\n" );289 log( bundle.getString("uninstaller.cancelled") + "\n" ); 268 290 changeToFinishToolbar(); 269 291 JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.cancelled"), bundle.getString("uninstaller.complete"), 1); … … 310 332 recursiveDelete( cd , ex ); 311 333 } catch ( CancelledException ce ) { 312 log.append( bundle.getString("uninstaller.cancelled") + "\n" ); 313 log.repaint(); 334 log( bundle.getString("uninstaller.cancelled") + "\n" ); 314 335 JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.cancelled"), bundle.getString("uninstaller.complete"), 1); 315 336 changeToFinishToolbar(); … … 321 342 (new File("uninst.flag")).createNewFile(); 322 343 } catch (Exception e) { 323 log.append( bundle.getString("uninstaller.couldnt-create-flagfile") + "\n" ); 324 log.repaint(); 344 log( bundle.getString("uninstaller.couldnt-create-flagfile") + "\n" ); 325 345 } 326 346 327 347 changeToFinishToolbar(); 348 log( bundle.getString("uninstaller.finished") ); 328 349 JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.finished"), bundle.getString("uninstaller.complete"), 1); 350 } 351 352 class LogAppender implements Runnable { 353 String s; 354 355 public LogAppender( String s ) { 356 this.s = s; 357 } 358 359 public void run() { 360 log.append( s ); 361 } 362 329 363 } 330 364 … … 373 407 // Make sure the file or directory exists 374 408 if (!f.exists()) { 375 log.append( Strings.replaceAll( bundle.getString("uninstaller.warning.nonexistent"), "{file}", f.getAbsolutePath() ) + "\n" ); 376 log.repaint(); 409 log( Strings.replaceAll( bundle.getString("uninstaller.warning.nonexistent"), "{file}", f.getAbsolutePath() ) + "\n" ); 377 410 return; 378 411 } … … 384 417 try { 385 418 if ( f.equals( exceptions[i] ) || f.getCanonicalPath().equals(exceptions[i].getCanonicalPath()) ) { 386 log .append( Strings.replaceAll( bundle.getString("uninstaller.info.skipping"), "{file}", f.getAbsolutePath() ) + "\n" );419 log( Strings.replaceAll( bundle.getString("uninstaller.info.skipping"), "{file}", f.getAbsolutePath() ) + "\n" ); 387 420 return; 388 421 } … … 396 429 //check existance 397 430 if ( !f.exists() ) { 398 log.append( Strings.replaceAll( bundle.getString("uninstaller.error.nonexistent"), "{file}", f.getAbsolutePath() ) + "\n" ); 399 log.repaint(); 431 log( Strings.replaceAll( bundle.getString("uninstaller.error.nonexistent"), "{file}", f.getAbsolutePath() ) + "\n" ); 400 432 return; 401 433 } … … 426 458 Object[] options = null; 427 459 int n = 0; 428 log.append( Strings.replaceAll( bundle.getString("uninstaller.deleting"), "{file}", f.getAbsolutePath() ) + "\n" ); 429 log.repaint(); 430 try{ Thread.sleep( 50 ); } catch( Exception e ) {} 431 /* 432 //disable the uninstall button 433 434 options = new Object[1]; 435 options = new Object[1]; 436 options[0] = "OK"; 437 n = JOptionPane.showOptionDialog( 438 frame, 439 "repainting", 440 "repainting", 441 JOptionPane.OK_OPTION, 442 JOptionPane.INFORMATION_MESSAGE, 443 null, 444 options, 445 options[0] 446 ); 447 */ 448 449 while ( !f.delete() ) { 450 log.append( Strings.replaceAll( bundle.getString("uninstaller.warning.couldnt.delete"), "{file}", f.getAbsolutePath() ) + "\n" ); 451 log.repaint(); 452 453 if ( ignoreReadOnlys ) { 454 return; 455 } 456 457 options[0] = bundle.getString("uninstaller.retry"); 458 options[1] = bundle.getString("uninstaller.skip"); 459 options[2] = bundle.getString("uninstaller.skip.all"); 460 options[3] = bundle.getString("uninstaller.cancel"); 461 n = JOptionPane.showOptionDialog( 462 frame, 463 Strings.replaceAll( bundle.getString("uninstaller.warning.readonly"), "{file}", f.getAbsolutePath() ), 464 bundle.getString("uninstaller.readonly"), 465 JOptionPane.YES_NO_CANCEL_OPTION, 466 JOptionPane.QUESTION_MESSAGE, 467 null, 468 options, 469 options[2] 470 ); 471 472 if ( n == 3 ) { 473 throw new CancelledException(); 474 } else if ( n == 1 ) { 475 return; 476 } else if ( n == 2 ) { 477 ignoreReadOnlys = true; 478 return; 479 } 480 460 log( Strings.replaceAll( bundle.getString("uninstaller.deleting"), "{file}", f.getAbsolutePath() ) + "\n" ); 461 462 if ( !f.delete() ) { 463 log( "*********\n" + Strings.replaceAll( bundle.getString("uninstaller.warning.couldnt.delete"), "{file}", f.getAbsolutePath() ) + "\n*********\n" ); 464 return; 481 465 } 482 466 } … … 511 495 } 512 496 513 514 515 516 class FollowingJTextArea extends JTextArea{ 497 class FollowingJTextArea extends JTextArea { 517 498 518 499 private boolean follow = true; … … 561 542 private JPopupMenu getPopupMenu() { 562 543 JPopupMenu contextMenu = new JPopupMenu("Options"); 563 JMenuItem saveMenu = new JMenuItem("Save Text");564 /*565 saveMenu.addActionListener(new ActionListener() {566 public void actionPerformed(ActionEvent e) {567 SelectFileAction action = new SelectFileAction("Save Output", null, null);568 try {569 action.actionPerformed(new ActionEvent(this, 0, "Save Output"));570 if (action.selectedFile != null) {571 FileWriter fos = new FileWriter(action.selectedFile);572 fos.write(getText());573 fos.close();574 }575 576 }577 catch (FileNotFoundException ex) {578 System.err.println("FileNotFoundException");579 }580 catch (IOException ex) {581 System.err.println("IOException");582 }583 }584 });585 contextMenu.add(saveMenu);586 */587 544 588 545 JMenuItem toggleFollowMenu = new JMenuItem("Toggle Follow");
Note:
See TracChangeset
for help on using the changeset viewer.