List of usage examples for com.badlogic.gdx.files FileHandle moveTo
public void moveTo(FileHandle dest)
From source file:es.eucm.ead.editor.control.actions.editor.OpenGame.java
License:Open Source License
private void recoverBackups(FileHandle folder) { for (FileHandle child : folder.list()) { if (child.isDirectory()) { recoverBackups(child);/* w w w.j a va 2s.c om*/ } else if (child.name().endsWith(Save.BACKUP_SUFFIX)) { Gdx.app.debug("OpenGame", "Found backup file. Recovering " + child.name()); FileHandle file = child.sibling(child.nameWithoutExtension()); child.moveTo(file); } } }
From source file:es.eucm.ead.editor.control.actions.editor.Save.java
License:Open Source License
/** * Does the actual saving following the next steps * <ol>/*w ww. j a va2s. co m*/ * <li>Updates game version codes to those specified by the application (see * <a href="https://github.com/e-ucm/ead/wiki/Model-API-versions" * target="_blank">https://github.com/e-ucm/ead/wiki/Model-API-versions</a> * and <a href="https://github.com/e-ucm/ead/wiki/Releasing" * target="_blank">https://github.com/e-ucm/ead/wiki/Releasing</a>)</li> * <li>Removes all the modified files from the project. That is to ensure * that if an entity was deleted from the model, it is actually removed from * persistent state.</li> * <li>Iterates through the model's entities, and saves the modified * resources to disk.</li> * </ol> */ protected void save() { updateGameVersions(); deleteRemovedResources(); EditorGameAssets gameAssets = controller.getEditorGameAssets(); for (Map.Entry<String, Resource> nextEntry : controller.getModel().listNamedResources()) { Resource resource = nextEntry.getValue(); if (resource.isModified()) { FileHandle oldFile = gameAssets.resolve(nextEntry.getKey()); FileHandle tmpFile = null; boolean oldFileExists = oldFile.exists(); if (oldFileExists) { tmpFile = oldFile.sibling(oldFile.name() + BACKUP_SUFFIX); oldFile.moveTo(tmpFile); } if (resource.getObject() instanceof ModelEntity) { ModelEntity currentEntity = (ModelEntity) resource.getObject(); Exporter.createInitComponent(currentEntity); } gameAssets.toJsonPath(resource.getObject(), nextEntry.getKey()); if (oldFileExists) { tmpFile.delete(); } resource.setModified(false); } } controller.getCommands().updateSavePoint(); }
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();/*from w w w. j a va 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; }
From source file:es.eucm.ead.repobuilder.RepoLibraryBuilder.java
License:Open Source License
private void exportRepoLibrary(RepoLibrary repoLibrary, FileHandle outputFH) { // Update version for library repoLibrary.setVersion(properties.get(VERSION)); // Make temp folder FileHandle tempFolder = FileHandle.tempDirectory("repolibrary"); tempFolder.mkdirs();//from w ww. java 2 s .c om // Update version code in entity and get id String id = repoLibrary.getId(); // Write model entity to json, if id is not null if (id != null) { FileHandle fh = tempFolder.child(id + ".json"); Gdx.app.debug(LOG_TAG, "Saving " + id + " to: " + fh.file().getAbsolutePath()); gameAssets.toJson(repoLibrary, null, fh); // Copy thumbnail paths FileHandle zipThumbnails = tempFolder.child(ZIP_THUMBNAILS_SUBPATH); zipThumbnails.mkdirs(); for (FileHandle thumbnail : rootFolder.child(id).list()) { thumbnail.moveTo(zipThumbnails); } // Zip temp folder to destiny FileHandle libsFolder = outputFH.child(LIBRARIES_SUBFOLDER); libsFolder.mkdirs(); FileHandle libZipFH = libsFolder.child(id + ".zip"); ZipUtils.zip(tempFolder, libZipFH); } else { Gdx.app.error(LOG_TAG, "Null id for repo library, it will be skipped while exporting: " + gameAssets.toJson(repoLibrary)); } // Delete temp folder tempFolder.deleteDirectory(); }
From source file:es.eucm.piel.GenerateSkins.java
License:Apache License
public void execute(File inputDir, File outputDir, SkinsConfig skinsConfig, FontsConfig fontsConfig, AtlasConfig atlasConfig) {/*from w w w.j av a 2 s . c o m*/ boolean updated = false; File pngOutput = new File(inputDir, skinsConfig.png); if (new GeneratePNGs().execute(new File(inputDir, skinsConfig.svgs), new File(inputDir, skinsConfig.patches), pngOutput, fontsConfig)) { updated = true; } if (new GenerateImages().execute(new File(inputDir, skinsConfig.images), pngOutput, fontsConfig)) { updated = true; } if (fontsConfig.fonts != null) { FileHandle fontsCached = new FileHandle(new File(pngOutput, ".ttffonts")); // TODO remove cached font and not present in the given // configuration String generated = ""; for (FontConfig font : fontsConfig.fonts) { generated += font.file; generated += font.characters; for (int size : font.sizes) { generated += size + ";"; } } for (float scale : fontsConfig.scales) { generated += scale + ";"; } generated += fontsConfig.atlasSize; if (fontsConfig.force || (!fontsCached.exists() || !generated.equals(fontsCached.readString()))) { System.out.println("Generating fonts from TTFs"); new GenerateFonts().execute(pngOutput, fontsConfig); fontsCached.writeString(generated, false); updated = true; } else { System.out.println("No TTF fonts updates."); } } if (updated) { System.out.println("Resources were updated. Regenerating skins..."); new GenerateAtlas().execute(pngOutput, outputDir, atlasConfig); // Extra tasks // Copy .fnt for (FileHandle folder : new FileHandle(pngOutput).list()) { if (folder.isDirectory()) { for (FileHandle fnt : folder.list(".fnt")) { fnt.moveTo(new FileHandle(new File(outputDir, folder.name() + "/" + fnt.name()))); } } } } else { System.out.println("No updates were found."); } // Copy skin.json to all scales FileHandle skin = new FileHandle(new File(outputDir, "skin.json")); if (skin.exists()) { for (float scale : fontsConfig.scales) { skin.copyTo(skin.parent().child(Float.toString(scale)).child("skin.json")); } } }