use one asset directory

dev/0.11
asie 2018-11-05 14:41:15 +01:00
parent 10f134fcc2
commit 1691c8c2d8
6 changed files with 16 additions and 29 deletions

View File

@ -78,25 +78,12 @@ public class MinecraftLibraryProvider {
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
// get existing cache files
project.getLogger().lifecycle(":checking for existing asset files");
Multimap<String, File> assetFilenameToFile = HashMultimap.create();
for (File assetDir : Objects.requireNonNull(extension.getUserCache().listFiles((f) -> f.isDirectory() && f.getName().startsWith("assets-")))) {
File objectsDir = new File(assetDir, "objects");
if (objectsDir.exists() && objectsDir.isDirectory()) {
for (File subDir : Objects.requireNonNull(objectsDir.listFiles(File::isDirectory))) {
for (File subFile : Objects.requireNonNull(subDir.listFiles(File::isFile))) {
assetFilenameToFile.put("objects" + File.separator + subDir.getName() + File.separator + subFile.getName(), subFile);
}
}
}
}
File assets = new File(extension.getUserCache(), "assets-" + minecraftProvider.minecraftVersion);
File assets = new File(extension.getUserCache(), "assets");
if (!assets.exists()) {
assets.mkdirs();
}
File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.id + ".json");
File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.getFabricId(minecraftProvider.minecraftVersion) + ".json");
if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) {
project.getLogger().lifecycle(":downloading asset index");
FileUtils.copyURLToFile(new URL(assetIndex.url), assetsInfo);
@ -116,15 +103,6 @@ public class MinecraftLibraryProvider {
String sha1 = object.getHash();
String filename = "objects" + File.separator + sha1.substring(0, 2) + File.separator + sha1;
File file = new File(assets, filename);
if (!file.exists() && assetFilenameToFile.containsKey(filename)) {
project.getLogger().debug(":copying asset " + entry.getKey());
for (File srcFile : assetFilenameToFile.get(filename)) {
if (Checksum.equals(srcFile, sha1)) {
FileUtils.copyFile(srcFile, file);
break;
}
}
}
if (!file.exists() || !Checksum.equals(file, sha1)) {
project.getLogger().debug(":downloading asset " + entry.getKey());
@ -138,6 +116,7 @@ public class MinecraftLibraryProvider {
progressLogger.progress(assetName + " - " + position + "/" + totalSize + " (" + (int) ((position / (double) totalSize) * 100) + "%) assets downloaded");
position++;
}
progressLogger.completed();
}

View File

@ -77,7 +77,7 @@ public class PomfProvider {
GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(MAPPINGS_TINY_GZ));
FileOutputStream fileOutputStream = new FileOutputStream(MAPPINGS_TINY);
int length;
byte[] buffer = new byte[1024];
byte[] buffer = new byte[4096];
while ((length = gzipInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
}

View File

@ -53,7 +53,7 @@ public class RunClientTask extends JavaExec {
}
classpath(libs);
args("--tweakClass", Constants.FABRIC_CLIENT_TWEAKER, "--assetIndex", minecraftVersionInfo.assetIndex.id, "--assetsDir", new File(extension.getUserCache(), "assets-" + extension.getMinecraftProvider().minecraftVersion).getAbsolutePath(), "--fabricMappingFile", extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getAbsolutePath());
args("--tweakClass", Constants.FABRIC_CLIENT_TWEAKER, "--assetIndex", minecraftVersionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion), "--assetsDir", new File(extension.getUserCache(), "assets").getAbsolutePath(), "--fabricMappingFile", extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getAbsolutePath());
setWorkingDir(new File(getProject().getRootDir(), "run"));

View File

@ -93,7 +93,7 @@ public class IdeaRunConfig {
ideaClient.configName = "Minecraft Client";
ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
ideaClient.vmArgs = "-Dfabric.development=true";
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + minecraftVersionInfo.assetIndex.id + " --assetsDir \"" + new File(extension.getUserCache(), "assets-" + minecraftProvider.minecraftVersion).getAbsolutePath() + "\" --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + minecraftVersionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion) + " --assetsDir \"" + new File(extension.getUserCache(), "assets").getAbsolutePath() + "\" --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
return ideaClient;
}
@ -115,7 +115,7 @@ public class IdeaRunConfig {
}
public String fromDummy() throws IOException {
InputStream input = SetupIntelijRunConfigs.class.getClassLoader().getResourceAsStream("dummy_runconfig.xml");
InputStream input = SetupIntelijRunConfigs.class.getClassLoader().getResourceAsStream("idea_run_config_template.xml");
String dummyConfig = IOUtils.toString(input, StandardCharsets.UTF_8);
input.close();

View File

@ -44,9 +44,17 @@ public class MinecraftVersionInfo {
}
public class AssetIndex {
public String id;
private String id;
public String sha1;
public String url;
public String getId() {
return id;
}
public String getFabricId(String version) {
return id.equals(version) ? version : version + "-" + id;
}
}
public class Library {