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:
parent
aed5163a83
commit
e535a88840
|
@ -18,6 +18,8 @@
|
|||
|
||||
package itdelatrisu.opsu;
|
||||
|
||||
import itdelatrisu.opsu.beatmap.BeatmapWatchService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
|
@ -62,6 +64,9 @@ public class OszUnpacker {
|
|||
}
|
||||
|
||||
// unpack OSZs
|
||||
BeatmapWatchService ws = (Options.isWatchServiceEnabled()) ? BeatmapWatchService.get() : null;
|
||||
if (ws != null)
|
||||
ws.pause();
|
||||
for (File file : files) {
|
||||
fileIndex++;
|
||||
String dirName = file.getName().substring(0, file.getName().lastIndexOf('.'));
|
||||
|
@ -73,6 +78,8 @@ public class OszUnpacker {
|
|||
dirs.add(songDir);
|
||||
}
|
||||
}
|
||||
if (ws != null)
|
||||
ws.resume();
|
||||
|
||||
fileIndex = -1;
|
||||
files = null;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package itdelatrisu.opsu.beatmap;
|
||||
|
||||
import itdelatrisu.opsu.ErrorHandler;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.audio.MusicController;
|
||||
import itdelatrisu.opsu.db.BeatmapDB;
|
||||
|
@ -199,11 +200,16 @@ public class BeatmapSetList {
|
|||
BeatmapDB.delete(dir.getName());
|
||||
|
||||
// delete the associated directory
|
||||
BeatmapWatchService ws = (Options.isWatchServiceEnabled()) ? BeatmapWatchService.get() : null;
|
||||
if (ws != null)
|
||||
ws.pause();
|
||||
try {
|
||||
Utils.deleteToTrash(dir);
|
||||
} catch (IOException e) {
|
||||
ErrorHandler.error("Could not delete song group.", e, true);
|
||||
}
|
||||
if (ws != null)
|
||||
ws.resume();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -247,11 +253,16 @@ public class BeatmapSetList {
|
|||
BeatmapDB.delete(file.getParentFile().getName(), file.getName());
|
||||
|
||||
// delete the associated file
|
||||
BeatmapWatchService ws = (Options.isWatchServiceEnabled()) ? BeatmapWatchService.get() : null;
|
||||
if (ws != null)
|
||||
ws.pause();
|
||||
try {
|
||||
Utils.deleteToTrash(file);
|
||||
} catch (IOException e) {
|
||||
ErrorHandler.error("Could not delete song.", e, true);
|
||||
}
|
||||
if (ws != null)
|
||||
ws.resume();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user