Фикс indexAsset

This commit is contained in:
Gravit 2019-01-09 06:41:31 +07:00
parent 669ca83bec
commit 2a957a6303
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 8 additions and 19 deletions

View file

@ -12,6 +12,7 @@
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.command.CommandException; import ru.gravit.launchserver.command.CommandException;
@ -35,11 +36,11 @@ public IndexObject(long size, String hash) {
} }
private static final class IndexAssetVisitor extends SimpleFileVisitor<Path> { private static final class IndexAssetVisitor extends SimpleFileVisitor<Path> {
private final JsonArray objects; private final JsonObject objects;
private final Path inputAssetDir; private final Path inputAssetDir;
private final Path outputAssetDir; private final Path outputAssetDir;
private IndexAssetVisitor(JsonArray objects, Path inputAssetDir, Path outputAssetDir) { private IndexAssetVisitor(JsonObject objects, Path inputAssetDir, Path outputAssetDir) {
this.objects = objects; this.objects = objects;
this.inputAssetDir = inputAssetDir; this.inputAssetDir = inputAssetDir;
this.outputAssetDir = outputAssetDir; this.outputAssetDir = outputAssetDir;
@ -53,7 +54,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
// Add to index and copy file // Add to index and copy file
String digest = SecurityHelper.toHex(SecurityHelper.digest(DigestAlgorithm.SHA1, file)); String digest = SecurityHelper.toHex(SecurityHelper.digest(DigestAlgorithm.SHA1, file));
IndexObject obj = new IndexObject(attrs.size(), digest); IndexObject obj = new IndexObject(attrs.size(), digest);
objects.add(gson.toJsonTree(obj)); objects.add(name, gson.toJsonTree(obj));
IOHelper.copy(file, resolveObjectFile(outputAssetDir, digest)); IOHelper.copy(file, resolveObjectFile(outputAssetDir, digest));
// Continue visiting // Continue visiting
@ -106,7 +107,7 @@ public void invoke(String... args) throws Exception {
Files.createDirectory(outputAssetDir); Files.createDirectory(outputAssetDir);
// Index objects // Index objects
JsonArray objects = new JsonArray(); JsonObject objects = new JsonObject();
LogHelper.subInfo("Indexing objects"); LogHelper.subInfo("Indexing objects");
IOHelper.walk(inputAssetDir, new IndexAssetVisitor(objects, inputAssetDir, outputAssetDir), false); IOHelper.walk(inputAssetDir, new IndexAssetVisitor(objects, inputAssetDir, outputAssetDir), false);
@ -114,7 +115,9 @@ public void invoke(String... args) throws Exception {
LogHelper.subInfo("Writing asset index file: '%s'", indexFileName); LogHelper.subInfo("Writing asset index file: '%s'", indexFileName);
try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) { try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) {
writer.write(gson.toJson(objects)); JsonObject result = new JsonObject();
result.add("objects",objects);
writer.write(gson.toJson(result));
} }
// Finished // Finished

View file

@ -28,17 +28,3 @@ DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates");
if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) { if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) {
java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir); java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir);
} }
//====== SERVERS CONFIG ====== //
var serversConfig = {
defaults: {
// Лозунг сервера
description: "Мир в котором возможно все"
},
getServerProperty: function(profile, property){
if(serversConfig[profile]==null || serversConfig[profile][property]==null){
return serversConfig.defaults[property];
}
return serversConfig[profile][property];
}
};