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 49 public class InstallMultipleFile extends AbstractInstallable 50 implements Installable 51 { 52 public final static int SLEEP_TIME=50; 54 protected File sourceDirectory; 55 protected File targetDirectory; 56 protected int perms; 57 protected Vector fileList; 59 68 public InstallMultipleFile( String nodeName, 69 int perms, 70 String srcDir, 71 String destDir, 72 String filename ) 73 { 74 this( nodeName, perms, new File(srcDir), new File(destDir), 75 new String [] { filename } ); 76 } 77 78 90 public InstallMultipleFile( String nodeName, 91 int perms, 92 File srcDir, 93 File destDir, 94 String filename ) 95 { 96 this( nodeName, perms, srcDir, destDir, new String [] { filename } ); 97 } 98 99 100 111 public InstallMultipleFile( String nodeName, 112 int perms, 113 String srcDir, 114 String destDir, 115 String [] filenames ) 116 { 117 this( nodeName, perms, new File(srcDir), new File(destDir), filenames ); 118 } 119 120 131 public InstallMultipleFile( String nodeName, 132 int perms, 133 File sourceDir, 134 File targetDir, 135 String [] filenames ) 136 { 137 super( nodeName, null, true ); 138 this.nodeName = nodeName; 139 this.perms = perms; 140 sourceDirectory = sourceDir; 141 targetDirectory = targetDir; 142 fileList = new Vector(); 143 for (int j=0; j<filenames.length; ++j) 144 if ( filenames[j] != null ) 145 fileList.addElement( filenames[j] ); 146 } 147 148 152 public Component getVisualComponent() 153 { 154 return (null); 155 } 156 157 161 public Component getConfigurableComponent() 162 { 163 return (null); 164 } 165 166 173 public void install() throws InstallException 174 { 175 FreeInstallerApplication theApp = 176 FreeInstallerApplication.getInstance(); 177 178 if ( !sourceDirectory.isDirectory() ) 179 throw new InstallException("no such source directory:`"+sourceDirectory.getAbsolutePath()+"'" ); 180 181 if ( !targetDirectory.exists() ) 182 targetDirectory.mkdirs(); 183 184 if ( !targetDirectory.isDirectory() ) 185 throw new InstallException( 186 "no such target directory:`"+targetDirectory.getAbsolutePath()+"'" ); 187 188 uninstallable.addFile( targetDirectory ); 190 191 JProgressBar pbar = theApp.getProgressFrame().getProgressBarNode(); 193 JProgressBar pbarFile = theApp.getProgressFrame().getProgressBarFile(); 194 int numFiles = fileList.size(); 195 196 SwingUtilities.invokeLater( new ResetProgressBar( pbar, 0, numFiles, 0 ) ); 201 202 for (int j=0; j<fileList.size(); ++j) { 203 SwingUtilities.invokeLater( new UpdateProgressBar( pbar, j+1 ) ); 205 206 try { Thread.sleep(SLEEP_TIME); } catch (InterruptedException ie) { ; } 207 208 String filename = (String )fileList.elementAt(j); 209 File srcFile = new File( sourceDirectory, filename ); 210 if ( !srcFile.exists() ) { 211 if (pedantic) 212 throw new InstallException( 213 "["+j+"] no such explicit file:`" + srcFile.getPath() +"'"); 214 else 215 theApp.printWarning( "["+j+"] no such explicit file:`" + srcFile.getPath() +"'" ); 216 continue; 217 } 218 if ( srcFile.isFile() ) { 219 File dstFile = new File( targetDirectory, filename ); 221 theApp.printInfo( "["+j+"] explicit copying: `" + srcFile.getPath() + "' to `" + dstFile.getPath()+"'" ); 222 InstallUtilities.copyFile( pbarFile, srcFile, dstFile, true ); 223 InstallUtilities.setFilePermissions( dstFile, perms ); 224 uninstallable.addFile( dstFile ); 225 } 226 } 227 } 228 229 232 public void cleanup() throws InstallException 233 { 234 } 236 } 237 238 | Popular Tags |