1 15 16 30 package ixenon.free.nodes; 31 32 import java.io.*; 33 import java.util.*; 34 import java.awt.*; 35 import java.awt.event.*; 36 37 import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; 41 import ixenon.free.swing.*; import ixenon.free.install.*; 44 48 public class InstallFilterFile extends AbstractInstallable 49 implements Installable 50 { 51 public final static int SLEEP_TIME=50; 53 54 protected File sourceDirectory; 55 56 protected File targetDirectory; 57 58 protected FilenameFilter filenameFilter; 59 60 protected int perms; 61 62 70 public InstallFilterFile( String nodeName, 71 int perms, 72 String srcDir, 73 String destDir, 74 FilenameFilter filenameFilter ) 75 { 76 this( nodeName, perms, new File(srcDir), new File(destDir), filenameFilter ); 77 } 78 79 87 public InstallFilterFile( String nodeName, 88 int perms, 89 File sourceDir, 90 File targetDir, 91 FilenameFilter filenameFilter ) 92 { 93 super( nodeName, null, true ); 94 sourceDirectory = sourceDir; 95 targetDirectory = targetDir; 96 this.filenameFilter = filenameFilter; 97 this.perms = perms; 98 } 99 100 104 public Component getVisualComponent() 105 { 106 return (null); 107 } 108 109 113 public Component getConfigurableComponent() 114 { 115 return (null); 116 } 117 118 125 public void install() throws InstallException 126 { 127 FreeInstallerApplication theApp = 128 FreeInstallerApplication.getInstance(); 129 130 if ( !sourceDirectory.isDirectory() ) 131 throw new InstallException("no such source directory:`"+sourceDirectory.getAbsolutePath()+"'" ); 132 133 if ( !targetDirectory.exists() ) 134 targetDirectory.mkdirs(); 135 136 if ( !targetDirectory.isDirectory() ) 137 throw new InstallException( 138 "no such target directory:`"+targetDirectory.getAbsolutePath()+"'" ); 139 140 uninstallable.addFile( targetDirectory ); 142 int j=0; 144 String [] selectedFiles = sourceDirectory.list( filenameFilter ); 145 146 JProgressBar pbar = theApp.getProgressFrame().getProgressBarNode(); 147 JProgressBar pbarFile = theApp.getProgressFrame().getProgressBarFile(); 148 int numFiles = selectedFiles.length; 149 theApp.getProgressFrame().setStatusText( getNodeName() ); 150 151 SwingUtilities.invokeLater( new ResetProgressBar( pbar, 0, numFiles, 0 ) ); 157 158 for (j=0; j<numFiles; ++j) { 160 161 SwingUtilities.invokeLater( new UpdateProgressBar( pbar, j+1 ) ); 163 164 try { Thread.sleep(SLEEP_TIME); } catch (InterruptedException ie) { ; } 165 166 File srcFile = new File( sourceDirectory, selectedFiles[j] ); 167 if ( !srcFile.exists() ) { 168 if (pedantic) 169 throw new InstallException( 170 "["+j+"] no such matched file:`" + srcFile.getPath()+"'" ); 171 else 172 theApp.printWarning( "["+j+"] no such matched file:`" + srcFile.getPath()+"'" ); 173 continue; 174 } 175 if ( srcFile.isFile() ) { 176 File dstFile = new File( targetDirectory, selectedFiles[j] ); 178 theApp.printInfo( "["+j+"] matched copying:`" + srcFile.getPath() + "' to `" + dstFile.getPath()+"'" ); 179 InstallUtilities.copyFile( pbarFile, srcFile, dstFile, true ); 180 InstallUtilities.setFilePermissions( dstFile, perms ); 181 182 uninstallable.addFile( dstFile ); 183 } 184 } 185 } 186 187 190 public void cleanup() throws InstallException 191 { 192 } 194 195 } 196 197 199 | Popular Tags |