Skip to content

Commit

Permalink
Extract verification and include song paths in error message, remove …
Browse files Browse the repository at this point in the history
…unused checks

Displayed error paths are capped to 30 lines to limit potential big dialog window size. More will be shown once the user deletes the folders.
  • Loading branch information
Chazoshtare committed Sep 8, 2021
1 parent 9dfca09 commit cd7a909
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
26 changes: 12 additions & 14 deletions src/bms/player/beatoraja/BMSResource.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package bms.player.beatoraja;

import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.logging.Logger;

import bms.model.BMSModel;
import bms.player.beatoraja.audio.AudioDriver;
import bms.player.beatoraja.play.bga.BGAProcessor;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.logging.Logger;

/**
* BMSの音源、BGAリソースを管理するクラス
*
Expand Down Expand Up @@ -100,16 +100,14 @@ public boolean setBMSFile(BMSModel model, final Path f, final Config config, BMS
bgaloaders.removeFirst();
}

if(MainLoader.getIllegalSongCount() == 0) {
// Audio, BGAともキャッシュがあるため、何があっても全リロードする
BGALoaderThread bgaloader = new BGALoaderThread(
config.getBga() == Config.BGA_ON || (config.getBga() == Config.BGA_AUTO && (mode.mode == BMSPlayerMode.Mode.AUTOPLAY || mode.mode == BMSPlayerMode.Mode.REPLAY)) ? model : null);
bgaloaders.addLast(bgaloader);
bgaloader.start();
AudioLoaderThread audioloader = new AudioLoaderThread(model);
audioloaders.addLast(audioloader);
audioloader.start();
}
// Audio, BGAともキャッシュがあるため、何があっても全リロードする
BGALoaderThread bgaloader = new BGALoaderThread(
config.getBga() == Config.BGA_ON || (config.getBga() == Config.BGA_AUTO && (mode.mode == BMSPlayerMode.Mode.AUTOPLAY || mode.mode == BMSPlayerMode.Mode.REPLAY)) ? model : null);
bgaloaders.addLast(bgaloader);
bgaloader.start();
AudioLoaderThread audioloader = new AudioLoaderThread(model);
audioloaders.addLast(audioloader);
audioloader.start();
return true;
}

Expand Down
38 changes: 19 additions & 19 deletions src/bms/player/beatoraja/MainLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.*;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import javax.swing.JOptionPane;

Expand Down Expand Up @@ -112,13 +113,7 @@ public static void play(Path f, BMSPlayerMode auto, boolean forceExit, Config co
config = Config.read();
}

for(SongData song : getScoreDatabaseAccessor().getSongDatas(SongUtils.illegalsongs)) {
MainLoader.putIllegalSong(song.getSha256());
}
if(illegalSongs.size() > 0) {
JOptionPane.showMessageDialog(null, "This Application detects " + illegalSongs.size() + " illegal BMS songs. \n Remove them, update song database and restart.", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
verifyIllegalSongs();

try {
MainController main = new MainController(f, config, player, auto, songUpdated);
Expand Down Expand Up @@ -193,6 +188,23 @@ public static void play(Path f, BMSPlayerMode auto, boolean forceExit, Config co
}
}

private static void verifyIllegalSongs() {
SongData[] foundIllegalSongs = getScoreDatabaseAccessor().getSongDatas(SongUtils.illegalsongs);
if (foundIllegalSongs.length > 0) {
String paths = Arrays.stream(foundIllegalSongs)
.limit(30)
.map(song -> Paths.get(song.getPath()).getParent().toString())
.distinct()
.collect(Collectors.joining("\n"));
JOptionPane.showMessageDialog(null,
"This Application detects " + foundIllegalSongs.length + " illegal BMS songs.\nRemove them, update song database and restart.\n\n" +
"Do not use this application to play copyrighted content.\n\n" + paths,
"Error",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}

public static Graphics.DisplayMode[] getAvailableDisplayMode() {
return LwjglApplicationConfiguration.getDisplayModes();
}
Expand Down Expand Up @@ -231,18 +243,6 @@ public static Path getBMSPath() {
return bmsPath;
}

public static void putIllegalSong(String hash) {
illegalSongs.add(hash);
}

public static String[] getIllegalSongs() {
return illegalSongs.toArray(new String[illegalSongs.size()]);
}

public static int getIllegalSongCount() {
return illegalSongs.size();
}

@Override
public void start(javafx.stage.Stage primaryStage) throws Exception {
Config config = Config.read();
Expand Down
4 changes: 1 addition & 3 deletions src/bms/player/beatoraja/select/BarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,7 @@ public boolean updateBar(Bar bar) {
Array<Bar> l = new Array<Bar>();
boolean showInvisibleCharts = false;

if (MainLoader.getIllegalSongCount() > 0) {
l.addAll(SongBar.toSongBarArray(select.getSongDatabase().getSongDatas(MainLoader.getIllegalSongs())));
} else if (bar == null) {
if (bar == null) {
if (dir.size > 0) {
prevbar = dir.first();
}
Expand Down

0 comments on commit cd7a909

Please sign in to comment.