mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 07:16:27 -04:00
Fix: java.nio.file.InvalidPathException
This commit is contained in:
parent
be22d55cec
commit
e0ebb02530
@ -33,7 +33,9 @@ import org.jackhuang.hmcl.util.Logging;
|
|||||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.file.FileAlreadyExistsException;
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
|
import java.nio.file.InvalidPathException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -117,6 +119,8 @@ public class WorldListPage extends ListPageBase<WorldListItem> {
|
|||||||
}, e -> {
|
}, e -> {
|
||||||
if (e instanceof FileAlreadyExistsException)
|
if (e instanceof FileAlreadyExistsException)
|
||||||
reject.accept(i18n("world.import.failed", i18n("world.import.already_exists")));
|
reject.accept(i18n("world.import.failed", i18n("world.import.already_exists")));
|
||||||
|
else if (e instanceof IOException && e.getCause() instanceof InvalidPathException)
|
||||||
|
reject.accept(i18n("world.import.failed", i18n("install.new_game.malformed")));
|
||||||
else
|
else
|
||||||
reject.accept(i18n("world.import.failed", e.getClass().getName() + ": " + e.getLocalizedMessage()));
|
reject.accept(i18n("world.import.failed", e.getClass().getName() + ": " + e.getLocalizedMessage()));
|
||||||
}).start();
|
}).start();
|
||||||
|
@ -32,10 +32,7 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.FileAlreadyExistsException;
|
import java.nio.file.*;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -157,7 +154,13 @@ public class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void install(Path savesDir, String name) throws IOException {
|
public void install(Path savesDir, String name) throws IOException {
|
||||||
Path worldDir = savesDir.resolve(name);
|
Path worldDir;
|
||||||
|
try {
|
||||||
|
worldDir = savesDir.resolve(name);
|
||||||
|
} catch (InvalidPathException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
|
||||||
if (Files.isDirectory(worldDir)) {
|
if (Files.isDirectory(worldDir)) {
|
||||||
throw new FileAlreadyExistsException("World already exists");
|
throw new FileAlreadyExistsException("World already exists");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user