int nDir = 0;
for ( int n = 0; n < files.length; n++ ) {
File f = files[n];
if ( f.isDirectory() ) {
// Create the matching folder
PhotoFolder subfolder = null;
if ( folder != null ) {
String folderName = f.getName();
if ( folderName.length() > PhotoFolder.NAME_LENGTH ) {
folderName = folderName.substring( 0, PhotoFolder.NAME_LENGTH );
}
subfolder = findSubfolderByName( folder, folderName );
if ( subfolder == null ) {
subfolder = PhotoFolder.create( folderName, folder );
newFolderCount++;
} else {
foldersNotFound.remove( subfolder );
}
}
/*
Calclate the start & end percentages to use when indexing this
directory. Formula goes so that we estimate that to index current
dirctory completely we must index files in subDirCount+1 directories
(all subdirs + current directory). So we divide endPercent - startPercent
into this many steps)
*/
int subdirStart = c.getProgress();
nDir++;
c.setProcessedSubdirs( nDir );
int subdirEnd = c.getProgress();
indexDirectory( f, subfolder, subdirStart, subdirEnd );
percentComplete = c.getProgress();
} else {
if ( f.canRead() ) {
currentEvent = new ExtVolIndexerEvent( this );
PhotoInfo p = indexFile( f );
if ( p != null ) {
if ( photoInstanceCounts.containsKey( p ) ) {
// The photo is already in this folder
int refCount = ((Integer)photoInstanceCounts.get( p ) ).intValue();
photoInstanceCounts.remove( p );
photoInstanceCounts.put( p, new Integer( refCount+1 ));
} else {
// The photo is not yet in this folder
folder.addPhoto( p );
photoInstanceCounts.put( p, new Integer( 1 ));
}
}
nFile++;
c.setProcessedFiles( nFile );
percentComplete = c.getProgress();
notifyListeners( currentEvent );
}
}
}
/*
Check if some of the photos that were in folder before were not found in
this directory
*/
Iterator iter = photoInstanceCounts.keySet().iterator();
while ( iter.hasNext() ) {
PhotoInfo p = (PhotoInfo ) iter.next();
int refCount = ((Integer)photoInstanceCounts.get( p )).intValue();
if ( refCount == 0 ) {
folder.removePhoto( p );
}
}
// Delete folders that were not anymore found
iter = foldersNotFound.iterator();
while ( iter.hasNext() ) {
PhotoFolder subfolder = (PhotoFolder)iter.next();
subfolder.delete();
}
}