Skip to content

Commit 45d1944

Browse files
authored
Merge pull request #436 from wcko87/filepath_resolve_invalidpathexception
Fix beatoraja crash when path.resolve() is called with file name = ???
2 parents 8bc3e7f + b934d23 commit 45d1944

File tree

3 files changed

+74
-56
lines changed

3 files changed

+74
-56
lines changed

src/bms/player/beatoraja/audio/AbstractAudioDriver.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import bms.model.*;
44
import bms.player.beatoraja.ResourcePool;
55

6+
import java.nio.file.InvalidPathException;
67
import java.nio.file.Path;
78
import java.nio.file.Paths;
89
import java.util.*;
@@ -249,37 +250,40 @@ public synchronized void setModel(BMSModel model) {
249250
return;
250251
}
251252
String name = model.getWavList()[wavid];
252-
for (Note note : waventry.getValue()) {
253-
// 音切りあり・なし両方のデータが必要になるケースがある
254-
if (note.getMicroStarttime() == 0 && note.getMicroDuration() == 0) {
255-
// 音切りなしのケース
256-
Path p = dpath.resolve(name);
257-
wavmap[wavid] = cache.get(new AudioKey(p.toString(), note));
258-
if (wavmap[wavid] == null) {
259-
break;
260-
}
261-
} else {
262-
// 音切りありのケース
263-
boolean b = true;
264-
if (slicesound[note.getWav()] == null) {
265-
slicesound[note.getWav()] = new Array<SliceWav<T>>();
266-
}
267-
for (SliceWav<T> slice : slicesound[note.getWav()]) {
268-
if (slice.starttime == note.getMicroStarttime() && slice.duration == note.getMicroDuration()) {
269-
b = false;
253+
try {
254+
Path p = dpath.resolve(name);
255+
for (Note note : waventry.getValue()) {
256+
// 音切りあり・なし両方のデータが必要になるケースがある
257+
if (note.getMicroStarttime() == 0 && note.getMicroDuration() == 0) {
258+
// 音切りなしのケース
259+
wavmap[wavid] = cache.get(new AudioKey(p.toString(), note));
260+
if (wavmap[wavid] == null) {
270261
break;
271262
}
272-
}
273-
if (b) {
274-
Path p = dpath.resolve(name);
275-
T sliceaudio = cache.get(new AudioKey(p.toString(), note));
276-
if (sliceaudio != null) {
277-
slicesound[note.getWav()].add(new SliceWav<T>(note, sliceaudio));
278-
} else {
279-
return;
263+
} else {
264+
// 音切りありのケース
265+
boolean b = true;
266+
if (slicesound[note.getWav()] == null) {
267+
slicesound[note.getWav()] = new Array<SliceWav<T>>();
268+
}
269+
for (SliceWav<T> slice : slicesound[note.getWav()]) {
270+
if (slice.starttime == note.getMicroStarttime() && slice.duration == note.getMicroDuration()) {
271+
b = false;
272+
break;
273+
}
274+
}
275+
if (b) {
276+
T sliceaudio = cache.get(new AudioKey(p.toString(), note));
277+
if (sliceaudio != null) {
278+
slicesound[note.getWav()].add(new SliceWav<T>(note, sliceaudio));
279+
} else {
280+
return;
281+
}
280282
}
281283
}
282284
}
285+
} catch (InvalidPathException e) {
286+
Logger.getGlobal().warning(e.getMessage());
283287
}
284288
progress.incrementAndGet();
285289
});

src/bms/player/beatoraja/play/bga/BGAProcessor.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,44 +121,48 @@ public synchronized void setModel(BMSModel model) {
121121
break;
122122
}
123123
Path f = null;
124-
if (Files.exists(dpath.resolve(name))) {
125-
final int index = name.lastIndexOf('.');
126-
String fex = null;
127-
if (index != -1) {
128-
fex = name.substring(index + 1).toLowerCase();
124+
try {
125+
if (Files.exists(dpath.resolve(name))) {
126+
final int index = name.lastIndexOf('.');
127+
String fex = null;
128+
if (index != -1) {
129+
fex = name.substring(index + 1).toLowerCase();
130+
}
131+
if(fex != null && !(Arrays.asList(mov_extension).contains(fex))){
132+
f = dpath.resolve(name);
133+
}else if(fex != null){
134+
name = name.substring(0, index);
135+
for (String mov : mov_extension) {
136+
final Path mpgfile = dpath.resolve(name + "." + mov);
137+
if (Files.exists(mpgfile)) {
138+
f = mpgfile;
139+
break;
140+
}
141+
}
142+
}
129143
}
130-
if(fex != null && !(Arrays.asList(mov_extension).contains(fex))){
131-
f = dpath.resolve(name);
132-
}else if(fex != null){
133-
name = name.substring(0, index);
144+
if (f == null) {
145+
final int index = name.lastIndexOf('.');
146+
if (index != -1) {
147+
name = name.substring(0, index);
148+
}
134149
for (String mov : mov_extension) {
135150
final Path mpgfile = dpath.resolve(name + "." + mov);
136151
if (Files.exists(mpgfile)) {
137152
f = mpgfile;
138153
break;
139154
}
140155
}
141-
}
142-
}
143-
if (f == null) {
144-
final int index = name.lastIndexOf('.');
145-
if (index != -1) {
146-
name = name.substring(0, index);
147-
}
148-
for (String mov : mov_extension) {
149-
final Path mpgfile = dpath.resolve(name + "." + mov);
150-
if (Files.exists(mpgfile)) {
151-
f = mpgfile;
152-
break;
153-
}
154-
}
155-
for (String mov : BGImageProcessor.pic_extension) {
156-
final Path picfile = dpath.resolve(name + "." + mov);
157-
if (Files.exists(picfile)) {
158-
f = picfile;
159-
break;
156+
for (String mov : BGImageProcessor.pic_extension) {
157+
final Path picfile = dpath.resolve(name + "." + mov);
158+
if (Files.exists(picfile)) {
159+
f = picfile;
160+
break;
161+
}
160162
}
161163
}
164+
} catch (InvalidPathException e) {
165+
Logger.getGlobal().warning(e.getMessage());
162166
}
163167

164168
if (f != null) {

src/bms/player/beatoraja/select/PreviewMusicProcessor.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package bms.player.beatoraja.select;
22

3+
import java.nio.file.InvalidPathException;
34
import java.nio.file.Paths;
45
import java.util.Deque;
56
import java.util.concurrent.ConcurrentLinkedDeque;
7+
import java.util.logging.Logger;
68

79
import bms.player.beatoraja.Config;
810
import bms.player.beatoraja.audio.AudioDriver;
@@ -44,8 +46,16 @@ public void start(SongData song) {
4446
preview.start();
4547
}
4648
current = song;
47-
commands.add(song != null && song.getPreview() != null && song.getPreview().length() > 0 ?
48-
Paths.get(song.getPath()).getParent().resolve(song.getPreview()).toString() : "");
49+
50+
String previewPath = "";
51+
if (song != null && song.getPreview() != null && song.getPreview().length() > 0) {
52+
try {
53+
previewPath = Paths.get(song.getPath()).getParent().resolve(song.getPreview()).toString();
54+
} catch (InvalidPathException e) {
55+
Logger.getGlobal().warning(e.getMessage());
56+
}
57+
}
58+
commands.add(previewPath);
4959
}
5060

5161
public SongData getSongData() {

0 commit comments

Comments
 (0)