Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support to force rescan of tag info

  • Loading branch information...
commit ad6e5f594f73b3c6067289d9d5f98e63d270c602 1 parent 909914d
@nperrier nperrier authored
View
1  resources/locales/sockso.en.txt
@@ -226,6 +226,7 @@ gui.label.community=Community
gui.label.communityEnabled=List my server in the Sockso community
gui.label.scanEntireCollection=Entire collection
gui.label.scanSelectFolder=Select folder
+gui.label.rescanTags=Re-read tag info
#
# gui errors
View
26 src/com/pugh/sockso/gui/controls/RescanButton.java
@@ -103,8 +103,16 @@ public void actionPerformed( ActionEvent evt ) {
}
});
+ final JMenuItem rescanTags = new JMenuItem( locale.getString("gui.label.rescanTags") );
+ rescanTags.addActionListener( new ActionListener() {
+ public void actionPerformed( ActionEvent evt ) {
+ rescanTags();
+ }
+ });
+
menu.add( entireCollection );
menu.add( selectFolder );
+ menu.add( rescanTags );
}
@@ -186,7 +194,23 @@ public void run() {
}
}
-
+
+ /**
+ * Start a rescan on the entire collection
+ *
+ */
+
+ protected void rescanTags() {
+
+ new Thread() {
+
+ @Override
+ public void run() { cm.rescanTags(); }
+
+ }.start();
+
+ }
+
/**
* Prompts the user to select a folder to scan and returns the one they
* select, or null if then cancel the dialog
View
2  src/com/pugh/sockso/music/CollectionManager.java
@@ -104,5 +104,7 @@
*/
public void fireCollectionManagerEvent( final int type, final String message );
+
+ public void rescanTags();
}
View
19 src/com/pugh/sockso/music/DBCollectionManager.java
@@ -32,7 +32,7 @@
@Singleton
public class DBCollectionManager extends Thread implements CollectionManager, IndexListener {
- private static final Logger log = Logger.getLogger( CollectionManager.class );
+ private static final Logger log = Logger.getLogger( DBCollectionManager.class );
private final Database db;
private final Properties p;
@@ -68,19 +68,19 @@ public void indexChanged( final IndexEvent evt ) {
switch ( evt.getType() ) {
- case IndexEvent.UNKNOWN:
+ case UNKNOWN:
addFile( evt.getFileId(), evt.getFile() );
break;
- case IndexEvent.CHANGED:
+ case CHANGED:
checkTrack( getTrack(evt.getFileId()), evt.getFile() );
break;
- case IndexEvent.MISSING:
+ case MISSING:
removeTrack( evt.getFileId() );
break;
- case IndexEvent.COMPLETE:
+ case COMPLETE:
removeEmptyArtistsAndAlbums();
fireCollectionManagerEvent( CollectionManagerListener.UPDATE_COMPLETE, "Collection Updated!" );
break;
@@ -230,6 +230,15 @@ public void checkCollection() {
}
/**
+ * Re-reads tag information from files
+ */
+ public void rescanTags() {
+
+ indexer.scan(Indexer.ScanFilter.NONE, Indexer.ScanScope.ALL_FILES);
+
+ }
+
+ /**
* checks if the album tag information has changed, if it has then updates
* the database.
*
View
87 src/com/pugh/sockso/music/indexing/BaseIndexer.java
@@ -1,6 +1,7 @@
package com.pugh.sockso.music.indexing;
+import com.pugh.sockso.Utils;
import com.pugh.sockso.db.Database;
import org.apache.log4j.Logger;
@@ -13,7 +14,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Scans and indexes files in the collection.
*
@@ -33,7 +34,7 @@
private final Database db;
private final IndexCache cache;
- private boolean isIndexing;
+ private AtomicBoolean isIndexing;
/**
* Constructor
@@ -62,7 +63,7 @@ public BaseIndexer( final Database db, final IndexCache cache ) {
this.cache = cache;
indexListeners = new ArrayList<IndexListener>();
- isIndexing = false;
+ isIndexing = new AtomicBoolean(false);
}
@@ -103,28 +104,34 @@ public BaseIndexer( final Database db, final IndexCache cache ) {
@Override
public void scan() {
+
+ scan( ScanFilter.MODIFICATION_DATE, ScanScope.ALL_FILES );
+ }
- if ( !isIndexing ) {
- isIndexing = true;
+ public void scan( final ScanFilter filter, final ScanScope scope ) {
+
+ if ( isIndexing.compareAndSet( false, true ) ) {
final long start = System.currentTimeMillis();
log.debug( "scan() starting..." );
- checkIntegrity();
+ checkIntegrity( filter );
- log.debug( "integrity check done: " +(System.currentTimeMillis() - start) );
+ log.debug( "integrity check done: " + (System.currentTimeMillis() - start) );
- checkForNewFiles();
+ if ( !ScanScope.EXISTING_FILES.equals(scope) ) {
+ checkForNewFiles();
+ }
- log.debug( "scan() finished: " +(System.currentTimeMillis() - start) );
+ log.debug( "scan() finished: " + (System.currentTimeMillis() - start) );
fireIndexEvent(
- new IndexEvent( IndexEvent.COMPLETE, -1, new File("") )
+ new IndexEvent( IndexEvent.Type.COMPLETE, -1, new File("") )
);
- isIndexing = false;
+ isIndexing.set( false );
}
}
@@ -159,20 +166,20 @@ protected void checkForNewFiles() {
}
finally {
- try { rs.close(); }
- catch ( final SQLException e ) {}
+ Utils.close( rs );
}
}
/**
* Checks the files current in the index still are, if they are not then
- * a IndexEvent.MISSING event is fired. If they appear changed then a
- * IndexEvent.CHANGED event is fired.
+ * a IndexEvent.MISSING event is fired.
+ *
+ * If they appear changed then a IndexEvent.CHANGED event is fired.
*
*/
- protected void checkIntegrity() {
+ protected void checkIntegrity( final ScanFilter filter ) {
ResultSet rs = null;
@@ -186,12 +193,24 @@ protected void checkIntegrity() {
final int id = rs.getInt( "file_id" );
final File file = new File( path );
- if ( checkExists(file,id) ) {
- if ( checkModified(file,id,rs.getDate("index_last_modified")) ) {
- markFileModified( id, rs.getInt("index_id") );
+ if ( checkExists(file, id) ) {
+
+ boolean changed = false;
+
+ if ( ScanFilter.MODIFICATION_DATE.equals(filter) ) {
+ changed = checkModified(file, rs.getDate("index_last_modified"));
+ }
+ else if ( ScanFilter.NONE.equals(filter) ) {
+ changed = true;
+ }
+
+ if ( changed ) {
+ fireIndexEvent(new IndexEvent(IndexEvent.Type.CHANGED, id, file));
+ markFileModified(id, rs.getInt("index_id"));
}
- }
+ }
+
}
}
@@ -201,8 +220,7 @@ protected void checkIntegrity() {
}
finally {
- try { rs.close(); }
- catch ( final SQLException e ) {}
+ Utils.close( rs );
}
}
@@ -231,8 +249,7 @@ protected void updateCache() throws SQLException {
}
finally {
- try { rs.close(); }
- catch ( final SQLException e ) {}
+ Utils.close( rs );
}
}
@@ -278,7 +295,7 @@ protected void scan( final int directoryId, final File directory ) {
else if ( !cache.exists(file.getAbsolutePath()) ) {
fireIndexEvent(
- new IndexEvent( IndexEvent.UNKNOWN, directoryId, file )
+ new IndexEvent( IndexEvent.Type.UNKNOWN, directoryId, file )
);
}
@@ -366,8 +383,7 @@ public boolean markFileModified( final int fileId, final int indexId ) {
}
finally {
- try { st.close(); }
- catch ( final SQLException e ) {}
+ Utils.close( st );
}
return false;
@@ -391,7 +407,7 @@ protected boolean checkExists( final File file, final int id ) throws SQLExcepti
if ( !file.exists() ) {
fireIndexEvent(
- new IndexEvent( IndexEvent.MISSING, id, file )
+ new IndexEvent( IndexEvent.Type.MISSING, id, file )
);
return false;
}
@@ -401,7 +417,7 @@ protected boolean checkExists( final File file, final int id ) throws SQLExcepti
}
/**
- * Checks if a file has been modified. If it has then an IndexEvent.TRACK_CHANGED
+ * Checks if a file has been modified. If it has then an IndexEvent.Type.CHANGED
* event is fired and true returned.
*
* @param file
@@ -414,16 +430,9 @@ protected boolean checkExists( final File file, final int id ) throws SQLExcepti
*
*/
- protected boolean checkModified( final File file, final int id, final Date lastModified ) throws SQLException {
-
- if ( lastModified == null || lastModified.getTime() < file.lastModified() ) {
- fireIndexEvent(
- new IndexEvent( IndexEvent.CHANGED, id, file )
- );
- return true;
- }
-
- return false;
+ protected boolean checkModified( final File file, final Date lastModified ) {
+
+ return ( lastModified == null || lastModified.getTime() < file.lastModified() );
}
View
17 src/com/pugh/sockso/music/indexing/IndexEvent.java
@@ -10,12 +10,15 @@
public class IndexEvent {
- public static final int UNKNOWN = 1;
- public static final int MISSING = 2;
- public static final int CHANGED = 3;
- public static final int COMPLETE = 4;
+ public enum Type {
+ UNKNOWN,
+ MISSING,
+ CHANGED,
+ COMPLETE
+ }
- private final int type, fileId;
+ private final Type type;
+ private final int fileId;
private final File file;
/**
@@ -27,7 +30,7 @@
*
*/
- public IndexEvent( final int type, final int fileId, final File file ) {
+ public IndexEvent( Type type, final int fileId, final File file ) {
this.type = type;
this.fileId = fileId;
@@ -42,7 +45,7 @@ public IndexEvent( final int type, final int fileId, final File file ) {
*
*/
- public int getType() {
+ public Type getType() {
return type;
View
16 src/com/pugh/sockso/music/indexing/Indexer.java
@@ -5,6 +5,18 @@
public interface Indexer {
+
+ public enum ScanFilter {
+ MODIFICATION_DATE,
+ NONE
+ }
+
+ public enum ScanScope {
+ NEW_FILES,
+ EXISTING_FILES,
+ ALL_FILES
+ }
+
/**
* Performs a scan on the index
*
@@ -12,8 +24,10 @@
public void scan();
+ public void scan( ScanFilter filter, ScanScope scope );
+
/**
- * Scans a particluar directory that is part of the specified collection
+ * Scans a particular directory that is part of the specified collection
*
* @param collectionId
* @param directory
Please sign in to comment.
Something went wrong with that request. Please try again.