Stop firing BeatmapWatchService events for intended file modifications.

Specifically, during OSZ unpacking and for file deletion through the song menu.  Triggering the beatmap reload event in these scenarios would be redundant.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-08-30 23:21:58 -05:00
parent aed5163a83
commit e535a88840
3 changed files with 36 additions and 2 deletions

View File

@@ -162,6 +162,9 @@ public class BeatmapWatchService {
/** The Executor. */
private ExecutorService service;
/** Whether the watch service is paused (i.e. does not fire events). */
private boolean paused = false;
/**
* Creates the WatchService.
* @throws IOException if an I/O error occurs
@@ -242,6 +245,7 @@ public class BeatmapWatchService {
if (dir == null)
continue;
boolean isPaused = paused;
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
if (kind == StandardWatchEventKinds.OVERFLOW)
@@ -254,8 +258,10 @@ public class BeatmapWatchService {
//System.out.printf("%s: %s\n", kind.name(), child);
// fire listeners
for (BeatmapWatchServiceListener listener : listeners)
listener.eventReceived(kind, child);
if (!isPaused) {
for (BeatmapWatchServiceListener listener : listeners)
listener.eventReceived(kind, child);
}
// if directory is created, then register it and its sub-directories
if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
@@ -272,4 +278,14 @@ public class BeatmapWatchService {
}
}
}
/**
* Stops listener events from being fired.
*/
public void pause() { paused = true; }
/**
* Resumes firing listener events.
*/
public void resume() { paused = false; }
}