Support manually created world pack
This commit is contained in:
@@ -85,7 +85,8 @@ public class WorldListPage extends ListPage<WorldListItem> {
|
|||||||
}).setInitialText(world.getWorldName());
|
}).setInitialText(world.getWorldName());
|
||||||
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
Logging.LOG.log(Level.WARNING, "Unable to parse datapack file " + zipFile, e);
|
Logging.LOG.log(Level.WARNING, "Unable to parse world file " + zipFile, e);
|
||||||
|
Controllers.dialog(i18n("world.import.invalid"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ world.game_version=Game Version
|
|||||||
world.import.already_exists=This world already exists.
|
world.import.already_exists=This world already exists.
|
||||||
world.import.choose=Choose the save zip to be imported
|
world.import.choose=Choose the save zip to be imported
|
||||||
world.import.failed=Unable to import this world: %s
|
world.import.failed=Unable to import this world: %s
|
||||||
|
world.import.invalid=Not a valid world zip
|
||||||
world.name=World Name
|
world.name=World Name
|
||||||
world.name.enter=Enter the world name
|
world.name.enter=Enter the world name
|
||||||
world.time=EEE, MMM d, yyyy HH:mm:ss
|
world.time=EEE, MMM d, yyyy HH:mm:ss
|
||||||
|
|||||||
@@ -270,6 +270,7 @@ world.extension=存檔壓縮檔
|
|||||||
world.import.already_exists=此世界已經存在
|
world.import.already_exists=此世界已經存在
|
||||||
world.import.choose=選擇要導入的存檔壓縮檔
|
world.import.choose=選擇要導入的存檔壓縮檔
|
||||||
world.import.failed=無法導入此世界: %s
|
world.import.failed=無法導入此世界: %s
|
||||||
|
world.import.invalid=無法識別的存檔壓縮包
|
||||||
world.game_version=遊戲版本
|
world.game_version=遊戲版本
|
||||||
world.name=世界名稱
|
world.name=世界名稱
|
||||||
world.name.enter=輸入世界名稱
|
world.name.enter=輸入世界名稱
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ world.game_version=游戏版本
|
|||||||
world.import.already_exists=此世界已经存在
|
world.import.already_exists=此世界已经存在
|
||||||
world.import.choose=选择要导入的存档压缩包
|
world.import.choose=选择要导入的存档压缩包
|
||||||
world.import.failed=无法导入此世界:%s
|
world.import.failed=无法导入此世界:%s
|
||||||
|
world.import.invalid=无法识别的存档压缩包
|
||||||
world.name=世界名称
|
world.name=世界名称
|
||||||
world.name.enter=输入世界名称
|
world.name.enter=输入世界名称
|
||||||
world.time=yyyy 年 MM 月 dd 日 HH:mm:ss
|
world.time=yyyy 年 MM 月 dd 日 HH:mm:ss
|
||||||
|
|||||||
@@ -87,17 +87,27 @@ public class World {
|
|||||||
return gameVersion;
|
return gameVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadFromZipImpl(Path root) throws IOException {
|
||||||
|
Path levelDat = root.resolve("level.dat");
|
||||||
|
if (!Files.exists(levelDat))
|
||||||
|
throw new IllegalArgumentException("Not a valid world zip file since level.dat cannot be found.");
|
||||||
|
|
||||||
|
getWorldName(levelDat);
|
||||||
|
}
|
||||||
|
|
||||||
private void loadFromZip() throws IOException {
|
private void loadFromZip() throws IOException {
|
||||||
try (FileSystem fs = CompressingUtils.readonly(file).setAutoDetectEncoding(true).build()) {
|
try (FileSystem fs = CompressingUtils.readonly(file).setAutoDetectEncoding(true).build()) {
|
||||||
|
Path cur = fs.getPath("/level.dat");
|
||||||
|
if (Files.isRegularFile(cur)) {
|
||||||
|
fileName = FileUtils.getName(file);
|
||||||
|
loadFromZipImpl(fs.getPath("/"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Path root = Files.list(fs.getPath("/")).filter(Files::isDirectory).findAny()
|
Path root = Files.list(fs.getPath("/")).filter(Files::isDirectory).findAny()
|
||||||
.orElseThrow(() -> new IOException("Not a valid world zip file"));
|
.orElseThrow(() -> new IOException("Not a valid world zip file"));
|
||||||
|
|
||||||
Path levelDat = root.resolve("level.dat");
|
|
||||||
if (!Files.exists(levelDat))
|
|
||||||
throw new IllegalArgumentException("Not a valid world zip file since level.dat cannot be found.");
|
|
||||||
|
|
||||||
fileName = FileUtils.getName(root);
|
fileName = FileUtils.getName(root);
|
||||||
getWorldName(levelDat);
|
loadFromZipImpl(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,17 +159,24 @@ public class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Files.isRegularFile(file)) {
|
if (Files.isRegularFile(file)) {
|
||||||
String subDirectoryName;
|
try (FileSystem fs = CompressingUtils.readonly(file).setAutoDetectEncoding(true).build()) {
|
||||||
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(file)) {
|
Path cur = fs.getPath("/level.dat");
|
||||||
List<Path> subDirs = Files.list(fs.getPath("/")).collect(Collectors.toList());
|
if (Files.isRegularFile(cur)) {
|
||||||
if (subDirs.size() != 1) {
|
fileName = FileUtils.getName(file);
|
||||||
throw new IOException("World zip malformed");
|
|
||||||
|
new Unzipper(file, worldDir).unzip();
|
||||||
|
} else {
|
||||||
|
List<Path> subDirs = Files.list(fs.getPath("/")).collect(Collectors.toList());
|
||||||
|
if (subDirs.size() != 1) {
|
||||||
|
throw new IOException("World zip malformed");
|
||||||
|
}
|
||||||
|
String subDirectoryName = FileUtils.getName(subDirs.get(0));
|
||||||
|
new Unzipper(file, worldDir)
|
||||||
|
.setSubDirectory("/" + subDirectoryName + "/")
|
||||||
|
.unzip();
|
||||||
}
|
}
|
||||||
subDirectoryName = FileUtils.getName(subDirs.get(0));
|
|
||||||
}
|
}
|
||||||
new Unzipper(file, worldDir)
|
|
||||||
.setSubDirectory("/" + subDirectoryName + "/")
|
|
||||||
.unzip();
|
|
||||||
new World(worldDir).rename(name);
|
new World(worldDir).rename(name);
|
||||||
} else if (Files.isDirectory(file)) {
|
} else if (Files.isDirectory(file)) {
|
||||||
FileUtils.copyDirectory(file, worldDir);
|
FileUtils.copyDirectory(file, worldDir);
|
||||||
|
|||||||
Reference in New Issue
Block a user