1*d127360fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*d127360fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*d127360fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*d127360fSAndrew Rist * distributed with this work for additional information 6*d127360fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*d127360fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*d127360fSAndrew Rist * "License"); you may not use this file except in compliance 9*d127360fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*d127360fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*d127360fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*d127360fSAndrew Rist * software distributed under the License is distributed on an 15*d127360fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d127360fSAndrew Rist * KIND, either express or implied. See the License for the 17*d127360fSAndrew Rist * specific language governing permissions and limitations 18*d127360fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*d127360fSAndrew Rist *************************************************************/ 21*d127360fSAndrew Rist 22*d127360fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.help; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.FileInputStream; 27cdf0e10cSrcweir import java.io.FileOutputStream; 28cdf0e10cSrcweir import java.util.Arrays; 29cdf0e10cSrcweir import java.util.HashSet; 30cdf0e10cSrcweir import java.util.List; 31cdf0e10cSrcweir import java.util.zip.ZipEntry; 32cdf0e10cSrcweir import java.util.zip.ZipOutputStream; 33cdf0e10cSrcweir import java.util.zip.CRC32; 34cdf0e10cSrcweir import org.apache.lucene.analysis.standard.StandardAnalyzer; 35cdf0e10cSrcweir import org.apache.lucene.analysis.cjk.CJKAnalyzer; 36cdf0e10cSrcweir import org.apache.lucene.analysis.Analyzer; 37cdf0e10cSrcweir import org.apache.lucene.index.IndexWriter; 38cdf0e10cSrcweir 39cdf0e10cSrcweir import java.io.File; 40cdf0e10cSrcweir import java.io.FileNotFoundException; 41cdf0e10cSrcweir import java.io.IOException; 42cdf0e10cSrcweir import java.util.Date; 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** 46cdf0e10cSrcweir When this tool is used with long path names on Windows, that is paths which start 47cdf0e10cSrcweir with \\?\, then the caller must make sure that the path is unique. This is achieved 48cdf0e10cSrcweir by removing '.' and '..' from the path. Paths which are created by 49cdf0e10cSrcweir osl_getSystemPathFromFileURL fulfill this requirement. This is necessary because 50cdf0e10cSrcweir lucene is patched to not use File.getCanonicalPath. See long_path.patch in the lucene 51cdf0e10cSrcweir module. 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir public class HelpIndexerTool 54cdf0e10cSrcweir { 55cdf0e10cSrcweir public HelpIndexerTool() 56cdf0e10cSrcweir { 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir /** 61cdf0e10cSrcweir * @param args the command line arguments 62cdf0e10cSrcweir */ 63cdf0e10cSrcweir public static void main( String[] args ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir boolean bExtensionMode = false; 66cdf0e10cSrcweir mainImpl( args, bExtensionMode ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir public static void mainImpl( String[] args, boolean bExtensionMode ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir String aDirToZipStr = ""; 72cdf0e10cSrcweir String aSrcDirStr = ""; 73cdf0e10cSrcweir String aLanguageStr = ""; 74cdf0e10cSrcweir String aModule = ""; 75cdf0e10cSrcweir String aTargetZipFileStr = ""; 76cdf0e10cSrcweir String aCfsName = ""; 77cdf0e10cSrcweir String aSegmentName = ""; 78cdf0e10cSrcweir 79cdf0e10cSrcweir // Scan arguments 80cdf0e10cSrcweir //If this tool is invoked in the build process for extensions help, 81cdf0e10cSrcweir //then -extension must be set. 82cdf0e10cSrcweir boolean bExtension = false; 83cdf0e10cSrcweir boolean bLang = false; 84cdf0e10cSrcweir boolean bMod = false; 85cdf0e10cSrcweir boolean bZipDir = false; 86cdf0e10cSrcweir boolean bSrcDir = false; 87cdf0e10cSrcweir boolean bOutput = false; 88cdf0e10cSrcweir boolean bCfsName = false; 89cdf0e10cSrcweir boolean bSegmentName = false; 90cdf0e10cSrcweir 91cdf0e10cSrcweir int nArgCount = args.length; 92cdf0e10cSrcweir for( int i = 0 ; i < nArgCount ; i++ ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir if( "-extension".equals(args[i]) ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir bExtension = true; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir else if( "-lang".equals(args[i]) ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir if( i + 1 < nArgCount ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir aLanguageStr = args[i + 1]; 103cdf0e10cSrcweir bLang = true; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir i++; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir else if( "-mod".equals(args[i]) ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir if( i + 1 < nArgCount ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir aModule = args[i + 1]; 112cdf0e10cSrcweir bMod = true; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir i++; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir else if( "-zipdir".equals(args[i]) ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir if( i + 1 < nArgCount ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir aDirToZipStr = args[i + 1]; 121cdf0e10cSrcweir bZipDir = true; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir i++; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else if( "-srcdir".equals(args[i]) ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir if( i + 1 < nArgCount ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir aSrcDirStr = args[i + 1]; 130cdf0e10cSrcweir bSrcDir = true; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir i++; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else if( "-o".equals(args[i]) ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir if( i + 1 < nArgCount ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir aTargetZipFileStr = args[i + 1]; 139cdf0e10cSrcweir bOutput = true; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir i++; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir else if( "-checkcfsandsegname".equals(args[i]) ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir if( i + 1 < nArgCount ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir aCfsName = args[i + 1] + ".cfs"; 148cdf0e10cSrcweir bCfsName = true; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir i++; 151cdf0e10cSrcweir if( i + 1 < nArgCount ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir aSegmentName = "segments" + args[i + 1]; 154cdf0e10cSrcweir bSegmentName = true; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir i++; 157cdf0e10cSrcweir if (!(bCfsName && bSegmentName)) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir System.out.println("Usage: HelpIndexer -checkcfsandsegname _0 _3 (2 arguments needed)"); 160cdf0e10cSrcweir System.exit( -1 ); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir if( !bLang || !bMod || !bZipDir || (!bOutput && !bExtensionMode && !bExtension) ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir if( bExtensionMode ) 168cdf0e10cSrcweir return; 169cdf0e10cSrcweir 170cdf0e10cSrcweir System.out.println("Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -zipdir TempZipDir -o OutputZipFile"); 171cdf0e10cSrcweir System.out.println("Usage: HelpIndexer -extension -lang ISOLangCode -mod HelpModule -zipdir PathToLangDir"); 172cdf0e10cSrcweir System.exit( -1 ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir String aIndexDirName = aModule + ".idxl"; 176cdf0e10cSrcweir File aIndexDir = new File( aDirToZipStr + File.separator + aIndexDirName ); 177cdf0e10cSrcweir if( !bSrcDir ) 178cdf0e10cSrcweir aSrcDirStr = aDirToZipStr; 179cdf0e10cSrcweir File aCaptionFilesDir = new File( aSrcDirStr + File.separator + "caption" ); 180cdf0e10cSrcweir File aContentFilesDir = new File( aSrcDirStr + File.separator + "content" ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir try 183cdf0e10cSrcweir { 184cdf0e10cSrcweir Date start = new Date(); 185cdf0e10cSrcweir Analyzer analyzer = aLanguageStr.equals("ja") ? (Analyzer)new CJKAnalyzer() : (Analyzer)new StandardAnalyzer(); 186cdf0e10cSrcweir IndexWriter writer = new IndexWriter( aIndexDir, analyzer, true ); 187cdf0e10cSrcweir if( !bExtensionMode ) 188cdf0e10cSrcweir System.out.println( "Lucene: Indexing to directory '" + aIndexDir + "'..." ); 189cdf0e10cSrcweir int nRet = indexDocs( writer, aModule, bExtensionMode, aCaptionFilesDir, aContentFilesDir ); 190cdf0e10cSrcweir if( nRet != -1 ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir if( !bExtensionMode ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir System.out.println(); 195cdf0e10cSrcweir System.out.println( "Optimizing ..." ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir writer.optimize(); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir writer.close(); 200cdf0e10cSrcweir 201cdf0e10cSrcweir boolean bCfsFileOk = true; 202cdf0e10cSrcweir boolean bSegmentFileOk = true; 203cdf0e10cSrcweir if( bCfsName && bSegmentName && !bExtensionMode && nRet != -1 ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir String aCompleteCfsFileName = aDirToZipStr + File.separator + aIndexDirName + File.separator + aCfsName; 206cdf0e10cSrcweir String aCompleteSegmentFileName = aDirToZipStr + File.separator + aIndexDirName + File.separator + aSegmentName; 207cdf0e10cSrcweir File aCfsFile = new File( aCompleteCfsFileName ); 208cdf0e10cSrcweir File aSegmentFile = new File( aCompleteSegmentFileName ); 209cdf0e10cSrcweir bCfsFileOk = aCfsFile.exists(); 210cdf0e10cSrcweir bSegmentFileOk = aSegmentFile.exists(); 211cdf0e10cSrcweir System.out.println( "Checking cfs file " + aCfsName+ ": " + (bCfsFileOk ? "Found" : "Not found") ); 212cdf0e10cSrcweir System.out.println( "Checking segment file " + aSegmentName+ ": " + (bSegmentFileOk ? "Found" : "Not found") ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir if( bExtensionMode || bExtension) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir if( !bSrcDir ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir deleteRecursively( aCaptionFilesDir ); 220cdf0e10cSrcweir deleteRecursively( aContentFilesDir ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir else 224cdf0e10cSrcweir { 225cdf0e10cSrcweir if( nRet == -1 ) 226cdf0e10cSrcweir deleteRecursively( aIndexDir ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir if( bCfsFileOk && bSegmentFileOk ) 229cdf0e10cSrcweir System.out.println( "Zipping ..." ); 230cdf0e10cSrcweir File aDirToZipFile = new File( aDirToZipStr ); 231cdf0e10cSrcweir createZipFile( aDirToZipFile, aTargetZipFileStr ); 232cdf0e10cSrcweir deleteRecursively( aDirToZipFile ); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir if( !bCfsFileOk ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir System.out.println( "cfs file check failed, terminating..." ); 238cdf0e10cSrcweir System.exit( -1 ); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir if( !bSegmentFileOk ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir System.out.println( "segment file check failed, terminating..." ); 244cdf0e10cSrcweir System.exit( -1 ); 245cdf0e10cSrcweir } 246cdf0e10cSrcweir 247cdf0e10cSrcweir Date end = new Date(); 248cdf0e10cSrcweir if( !bExtensionMode ) 249cdf0e10cSrcweir System.out.println(end.getTime() - start.getTime() + " total milliseconds"); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir catch (IOException e) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir if( bExtensionMode ) 254cdf0e10cSrcweir return; 255cdf0e10cSrcweir 256cdf0e10cSrcweir System.out.println(" caught a " + e.getClass() + 257cdf0e10cSrcweir "\n with message: " + e.getMessage()); 258cdf0e10cSrcweir System.exit( -1 ); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir private static int indexDocs(IndexWriter writer, String aModule, boolean bExtensionMode, 263cdf0e10cSrcweir File aCaptionFilesDir, File aContentFilesDir) throws IOException 264cdf0e10cSrcweir { 265cdf0e10cSrcweir if( !aCaptionFilesDir.canRead() || !aCaptionFilesDir.isDirectory() ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir if( !bExtensionMode ) 268cdf0e10cSrcweir System.out.println( "Not found: " + aCaptionFilesDir ); 269cdf0e10cSrcweir return -1; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir if( !aContentFilesDir.canRead() || !aContentFilesDir.isDirectory() ) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir if( !bExtensionMode ) 274cdf0e10cSrcweir System.out.println( "Not found: " + aContentFilesDir ); 275cdf0e10cSrcweir return -1; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir 278cdf0e10cSrcweir String[] aCaptionFiles = aCaptionFilesDir.list(); 279cdf0e10cSrcweir List aCaptionFilesList = Arrays.asList( aCaptionFiles ); 280cdf0e10cSrcweir HashSet aCaptionFilesHashSet = new HashSet( aCaptionFilesList ); 281cdf0e10cSrcweir 282cdf0e10cSrcweir String[] aContentFiles = aContentFilesDir.list(); 283cdf0e10cSrcweir List aContentFilesList = Arrays.asList( aContentFiles ); 284cdf0e10cSrcweir HashSet aContentFilesHashSet = new HashSet( aContentFilesList ); 285cdf0e10cSrcweir 286cdf0e10cSrcweir // Loop over caption files and find corresponding content file 287cdf0e10cSrcweir if( !bExtensionMode ) 288cdf0e10cSrcweir System.out.println( "Indexing, adding files" ); 289cdf0e10cSrcweir int nCaptionFilesLen = aCaptionFiles.length; 290cdf0e10cSrcweir for( int i = 0 ; i < nCaptionFilesLen ; i++ ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir String aCaptionFileStr = aCaptionFiles[i]; 293cdf0e10cSrcweir File aCaptionFile = new File( aCaptionFilesDir, aCaptionFileStr ); 294cdf0e10cSrcweir File aContentFile = null; 295cdf0e10cSrcweir if( aContentFilesHashSet.contains( aCaptionFileStr ) ) 296cdf0e10cSrcweir aContentFile = new File( aContentFilesDir, aCaptionFileStr ); 297cdf0e10cSrcweir 298cdf0e10cSrcweir if( !bExtensionMode ) 299cdf0e10cSrcweir System.out.print( "." ); 300cdf0e10cSrcweir writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) ); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir // Loop over content files to find remaining files not mapped to caption files 304cdf0e10cSrcweir int nContentFilesLen = aContentFiles.length; 305cdf0e10cSrcweir for( int i = 0 ; i < nContentFilesLen ; i++ ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir String aContentFileStr = aContentFiles[i]; 308cdf0e10cSrcweir if( !aCaptionFilesHashSet.contains( aContentFileStr ) ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir // Not already handled in caption files loop 311cdf0e10cSrcweir File aCaptionFile = null; 312cdf0e10cSrcweir File aContentFile = new File( aContentFilesDir, aContentFileStr ); 313cdf0e10cSrcweir if( !bExtensionMode ) 314cdf0e10cSrcweir System.out.print( "." ); 315cdf0e10cSrcweir writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) ); 316cdf0e10cSrcweir } 317cdf0e10cSrcweir } 318cdf0e10cSrcweir return 0; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir public static void createZipFile( File aDirToZip, String aTargetZipFileStr ) 322cdf0e10cSrcweir throws FileNotFoundException, IOException 323cdf0e10cSrcweir { 324cdf0e10cSrcweir FileOutputStream fos = new FileOutputStream( aTargetZipFileStr ); 325cdf0e10cSrcweir ZipOutputStream zos = new ZipOutputStream( fos ); 326cdf0e10cSrcweir 327cdf0e10cSrcweir File[] aChildrenFiles = aDirToZip.listFiles(); 328cdf0e10cSrcweir int nFileCount = aChildrenFiles.length; 329cdf0e10cSrcweir for( int i = 0 ; i < nFileCount ; i++ ) 330cdf0e10cSrcweir addToZipRecursively( zos, aChildrenFiles[i], null ); 331cdf0e10cSrcweir 332cdf0e10cSrcweir zos.close(); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir public static void addToZipRecursively( ZipOutputStream zos, File aFile, String aBasePath ) 336cdf0e10cSrcweir throws FileNotFoundException, IOException 337cdf0e10cSrcweir { 338cdf0e10cSrcweir if( aFile.isDirectory() ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir String aDirName = aFile.getName(); 341cdf0e10cSrcweir if( aDirName.equalsIgnoreCase( "caption" ) || aDirName.equalsIgnoreCase( "content" ) ) 342cdf0e10cSrcweir return; 343cdf0e10cSrcweir 344cdf0e10cSrcweir File[] aChildrenFiles = aFile.listFiles(); 345cdf0e10cSrcweir String aNewBasePath = ""; 346cdf0e10cSrcweir if( aBasePath != null ) 347cdf0e10cSrcweir aNewBasePath += aBasePath + File.separator; 348cdf0e10cSrcweir aNewBasePath += aDirName; 349cdf0e10cSrcweir 350cdf0e10cSrcweir int nFileCount = aChildrenFiles.length; 351cdf0e10cSrcweir for( int i = 0 ; i < nFileCount ; i++ ) 352cdf0e10cSrcweir addToZipRecursively( zos, aChildrenFiles[i], aNewBasePath ); 353cdf0e10cSrcweir 354cdf0e10cSrcweir return; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir // No directory 358cdf0e10cSrcweir // read contents of file we are going to put in the zip 359cdf0e10cSrcweir int fileLength = (int) aFile.length(); 360cdf0e10cSrcweir FileInputStream fis = new FileInputStream( aFile ); 361cdf0e10cSrcweir byte[] wholeFile = new byte[fileLength]; 362cdf0e10cSrcweir int bytesRead = fis.read( wholeFile, 0, fileLength ); 363cdf0e10cSrcweir fis.close(); 364cdf0e10cSrcweir 365cdf0e10cSrcweir String aFileName = aFile.getName(); 366cdf0e10cSrcweir String aEntryName = ""; 367cdf0e10cSrcweir if( aBasePath != null ) 368cdf0e10cSrcweir aEntryName += aBasePath + "/"; 369cdf0e10cSrcweir aEntryName += aFileName; 370cdf0e10cSrcweir ZipEntry aZipEntry = new ZipEntry( aEntryName ); 371cdf0e10cSrcweir aZipEntry.setTime( aFile.lastModified() ); 372cdf0e10cSrcweir aZipEntry.setSize( fileLength ); 373cdf0e10cSrcweir 374cdf0e10cSrcweir int nMethod = ( aFileName.toLowerCase().endsWith( ".jar" ) ) 375cdf0e10cSrcweir ? ZipEntry.STORED : ZipEntry.DEFLATED; 376cdf0e10cSrcweir aZipEntry.setMethod( nMethod ); 377cdf0e10cSrcweir 378cdf0e10cSrcweir CRC32 tempCRC = new CRC32(); 379cdf0e10cSrcweir tempCRC.update( wholeFile, 0, wholeFile.length ); 380cdf0e10cSrcweir aZipEntry.setCrc( tempCRC.getValue() ); 381cdf0e10cSrcweir 382cdf0e10cSrcweir // write the contents into the zip element 383cdf0e10cSrcweir zos.putNextEntry( aZipEntry ); 384cdf0e10cSrcweir zos.write( wholeFile, 0, fileLength ); 385cdf0e10cSrcweir zos.closeEntry(); 386cdf0e10cSrcweir } 387cdf0e10cSrcweir 388cdf0e10cSrcweir static public boolean deleteRecursively( File aFile ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir if( aFile.isDirectory() ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir File[] aChildrenFiles = aFile.listFiles(); 393cdf0e10cSrcweir int nFileCount = aChildrenFiles.length; 394cdf0e10cSrcweir for( int i = 0 ; i < nFileCount ; i++ ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir File aChildrenFile = aChildrenFiles[i]; 397cdf0e10cSrcweir boolean bSuccess = deleteRecursively( aChildrenFile ); 398cdf0e10cSrcweir if( !bSuccess ) 399cdf0e10cSrcweir return false; 400cdf0e10cSrcweir } 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir return aFile.delete(); 404cdf0e10cSrcweir } 405cdf0e10cSrcweir } 406cdf0e10cSrcweir 407