Fix invalid characters in replay name on Windows (fixes #715)

This commit is contained in:
Jonas Herzig
2022-04-10 13:48:47 +02:00
parent 463b947c2b
commit d6c6220bdd

View File

@@ -59,6 +59,7 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttribute;
@@ -185,7 +186,12 @@ public class Utils {
* Checks whether a given file name is actually usable with the file system / operating system at the given folder. * Checks whether a given file name is actually usable with the file system / operating system at the given folder.
*/ */
private static boolean isUsable(Path folder, String fileName) { private static boolean isUsable(Path folder, String fileName) {
Path path = folder.resolve(fileName); Path path;
try {
path = folder.resolve(fileName);
} catch (InvalidPathException e) {
return false; // file name contains invalid characters, definitely not usable
}
if (Files.exists(path)) { if (Files.exists(path)) {
return true; // if it already exits, it's definitely usable return true; // if it already exits, it's definitely usable
} }