List of usage examples for com.badlogic.gdx.files FileHandle emptyDirectory
public void emptyDirectory()
From source file:es.eucm.ead.repobuilder.RepoLibraryBuilder.java
License:Open Source License
private FileHandle exportElement(ModelEntity modelEntity, FileHandle outputFH) { // Make a list of all binaries referenced by this modelEntity Array<String> binaryPaths = ProjectUtils.listRefBinaries(modelEntity); // Copy all binaries to a temp folder FileHandle tempFolder = FileHandle.tempDirectory("modelentity"); tempFolder.mkdirs();// w ww. j ava 2 s . c o m for (String binary : binaryPaths) { FileHandle destinyFH = tempFolder.child(binary); rootFolder.child(binary).copyTo(destinyFH); } // Update version code in entity and get id String id = null; RepoElement repoElement = null; for (ModelComponent modelComponent : modelEntity.getComponents()) { if (modelComponent instanceof RepoElement) { repoElement = (RepoElement) modelComponent; repoElement.setVersion(properties.get(VERSION)); id = modelComponent.getId(); } } // Write model entity to json, if id is not null if (repoElement != null) { FileHandle fh = tempFolder.child(id + ".json"); Gdx.app.debug(LOG_TAG, "Saving " + id + " to: " + fh.file().getAbsolutePath()); gameAssets.toJson(modelEntity, null, fh); // Zip contents FileHandle contentsZip = FileHandle.tempFile(id); ZipUtils.zip(tempFolder, contentsZip); // Clear temp folder tempFolder.emptyDirectory(); // Move contents back to temp file contentsZip.moveTo(tempFolder.child(ZIP_CONTENTS_SUBPATH)); // Write descriptor gameAssets.toJson(repoElement, null, tempFolder.child(ZIP_DESCRIPTOR_SUBPATH)); // Copy thumbnail paths FileHandle zipThumbnails = tempFolder.child(ZIP_THUMBNAILS_SUBPATH); zipThumbnails.mkdirs(); for (FileHandle thumbnail : rootFolder.child(getTempSubfolderForThumbnails(id)).list()) { thumbnail.moveTo(zipThumbnails); } // Zip temp folder to destiny FileHandle entitiesFolder = outputFH.child(ELEMENTS_SUBFOLDER); entitiesFolder.mkdirs(); FileHandle elementZipFH = entitiesFolder.child(id + ".zip"); ZipUtils.zip(tempFolder, elementZipFH); } else { Gdx.app.error(LOG_TAG, "Null id for element, it will be skipped while exporting: " + gameAssets.toJson(modelEntity)); } return tempFolder; }