greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 17805

Show
Ignore:
Timestamp:
2008-11-11 12:16:22 (2 months ago)
Author:
oranfry
Message:

the uninstaller now gives output as it goes rather than all in one bang at the end

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • release-kits/shared/uninstaller/Uninstaller.java

    r17792 r17805  
    1        import java.util.ResourceBundle; 
     1import java.util.ResourceBundle; 
    22import java.awt.*; 
    33import java.awt.event.*; 
     
    1414import javax.swing.Box; 
    1515import javax.swing.JDialog; 
     16import javax.swing.JMenuItem; 
     17import javax.swing.JPopupMenu; 
     18 
    1619import java.io.File; 
    1720import java.io.BufferedReader; 
    1821import java.io.FileReader; 
    19 import java.io.File; 
     22import java.io.FileNotFoundException; 
     23import java.io.FileWriter; 
     24import java.io.IOException; 
     25 
    2026import java.util.regex.Pattern; 
    2127import java.util.regex.Matcher; 
    2228import java.util.ArrayList; 
    2329 
    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; 
     30import javax.swing.SwingUtilities; 
     31 
    3432 
    3533public class Uninstaller { 
     
    6159 
    6260        JScrollPane logPane; 
    63         JTextArea log; 
     61        FollowingJTextArea log; 
    6462        JButton uninstallButton; 
     63 
     64        boolean confirmationGiven = false; 
     65        Thread mainThread = null; 
    6566         
    66  
    6767        public static void main( String[] args ) { 
    6868                (new Uninstaller()).go(); 
     
    7070 
    7171        public void go() { 
     72 
     73                mainThread = Thread.currentThread(); 
    7274 
    7375                frame =  new JFrame(); 
     
    9193                logPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 
    9294                progressPanel.add( BorderLayout.NORTH, new JLabel("Progress") ); 
    93                 progressPanel.add( BorderLayout.CENTER, log ); 
     95                progressPanel.add( BorderLayout.CENTER, logPane ); 
    9496 
    9597                //initial toolbar 
     
    148150                        System.exit(0); 
    149151                } 
     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(); 
    150162 
    151163        } 
     
    208220                        frame.getContentPane().remove(introPanel); 
    209221                        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(); 
    214229                } 
    215230        } 
     
    221236 
    222237                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" ); 
    224239                        JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.error.couldnt.find.install.props"), bundle.getString("uninstaller.error"), 0); 
    225240                        return false; 
     
    227242                return true; 
    228243                                 
     244        } 
     245 
     246        public void log( String s ) { 
     247                SwingUtilities.invokeLater( new LogAppender( s ) ); 
     248                //log.append( s ); 
     249                 
    229250        } 
    230251 
     
    257278 
    258279                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 
    261283                } else { 
    262                         log.append( "StartMenu Path: " + startMenuPath.getAbsolutePath() + "\n" ); 
    263                         log.repaint(); 
     284                        log( "StartMenu Path: " + startMenuPath.getAbsolutePath() + "\n" ); 
     285 
    264286                        try { 
    265287                                recursiveDelete( startMenuPath, null ); 
    266288                        } catch ( CancelledException ce ) { 
    267                                 log.append( bundle.getString("uninstaller.cancelled") + "\n" ); 
     289                                log( bundle.getString("uninstaller.cancelled") + "\n" ); 
    268290                                changeToFinishToolbar(); 
    269291                                JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.cancelled"), bundle.getString("uninstaller.complete"), 1); 
     
    310332                        recursiveDelete( cd , ex ); 
    311333                } catch ( CancelledException ce ) { 
    312                         log.append( bundle.getString("uninstaller.cancelled") + "\n" ); 
    313                         log.repaint(); 
     334                        log( bundle.getString("uninstaller.cancelled") + "\n" ); 
    314335                        JOptionPane.showMessageDialog(frame, bundle.getString("uninstaller.cancelled"), bundle.getString("uninstaller.complete"), 1); 
    315336                        changeToFinishToolbar(); 
     
    321342                        (new File("uninst.flag")).createNewFile(); 
    322343                } 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" ); 
    325345                } 
    326346 
    327347                changeToFinishToolbar(); 
     348                log( bundle.getString("uninstaller.finished") ); 
    328349                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 
    329363        } 
    330364 
     
    373407                // Make sure the file or directory exists 
    374408                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" ); 
    377410                        return; 
    378411                } 
     
    384417                                try { 
    385418                                        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" ); 
    387420                                                return; 
    388421                                        } 
     
    396429                //check existance 
    397430                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" ); 
    400432                        return; 
    401433                } 
     
    426458                        Object[] options = null; 
    427459                        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; 
    481465                        } 
    482466                } 
     
    511495} 
    512496 
    513  
    514  
    515  
    516 class FollowingJTextArea extends JTextArea{ 
     497class FollowingJTextArea extends JTextArea { 
    517498 
    518499    private boolean follow = true; 
     
    561542    private JPopupMenu getPopupMenu() { 
    562543        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 */ 
    587544 
    588545        JMenuItem toggleFollowMenu = new JMenuItem("Toggle Follow");