List of usage examples for com.badlogic.gdx.files FileHandle exists
public boolean exists()
From source file:be.ac.ucl.lfsab1509.bouboule.game.MyGame.java
License:Open Source License
/** * @param cNewMusic should be a file that can be read by GDX * in 'assets/music/levels'/* w ww.j a v a2 s.com*/ */ public void setNewLoopMusic(final String cNewMusic) { Gdx.app.log("SCREEN", "New music: " + cNewMusic + " " + (screenGame == null)); if (screenGame == null) { // not loaded yet. return; } if (cNewMusic != null) { FileHandle pMusicFile = Gdx.files.internal("music/levels/" + cNewMusic); if (pMusicFile.exists()) { screenGame.setNewLoopMusic(pMusicFile); return; } } // load the default one (if it's not currently playing) screenGame.setDefaultLoopMusicPath(); }
From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java
License:Apache License
/** <p> * Convert a text JSON file into binary JSON. The new file will be saved in the same folder as the original one with the * {@code gd3b} extension.// ww w . j a v a 2 s .com * </p> * * @param g3djFile Handle to the original G3DJ file. * @param overwrite If {@code true} the new file will overwrite any previous file with the same name. Otherwise append a * counter at the end of the file name to make it unique. * @throws IOException If there's an exception while reading the input file or writing the output file. */ public void convert(FileHandle g3djFile, boolean overwrite) throws IOException { FileHandle newFile = new FileHandle(g3djFile.pathWithoutExtension() + ".g3db"); int noOverwriteCounter = 0; while (!overwrite && newFile.exists()) { newFile = new FileHandle(g3djFile.pathWithoutExtension() + "(" + (++noOverwriteCounter) + ").g3db"); } OutputStream fileOutputStream = newFile.write(false); UBJsonWriter writer = new UBJsonWriter(fileOutputStream); JsonReader reader = new JsonReader(); try { JsonValue root = reader.parse(g3djFile); writeObject(root, writer); } finally { writer.close(); } }
From source file:CB_Core.DAO.CacheListDAO.java
License:Open Source License
public void delCacheImagesByPath(String path, ArrayList<String> list) { for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { final String GcCode = iterator.next().toLowerCase(); String directory = path + "/" + GcCode.substring(0, 4); if (!FileIO.DirectoryExists(directory)) continue; FileHandle dir = new FileHandle(directory); FileHandle[] files = dir.list(); for (int i = 0; i < files.length; i++) { // simplyfied for startswith gccode, thumbs_gccode + ooverwiewthumbs_gccode if (!files[i].name().toLowerCase().contains(GcCode)) continue; String filename = directory + "/" + files[i].name(); FileHandle file = new FileHandle(filename); if (file.exists()) { if (!file.delete()) Log.err(log, "Error deleting : " + filename); }// w w w. j a v a 2 s .c om } } }
From source file:CB_Translation_Base.TranslationEngine.Translation.java
License:Open Source License
private ArrayList<Lang> getLangs(String FilePath) { ArrayList<Lang> Temp = new ArrayList<Lang>(); FileHandle Dir = Gdx.files.getFileHandle(FilePath, mFiletype); final FileHandle[] files; if (Dir.type() == FileType.Classpath) { // Cannot list a classpath directory // so we hardcoded the lang path files = new FileHandle[] { // Gdx.files.classpath("data/lang/cs"), // Gdx.files.classpath("data/lang/de"), // Gdx.files.classpath("data/lang/en-GB"), // Gdx.files.classpath("data/lang/fr"), // Gdx.files.classpath("data/lang/hu"), // Gdx.files.classpath("data/lang/nl"), // Gdx.files.classpath("data/lang/pl"), // Gdx.files.classpath("data/lang/pt-PT"),// };/* www. jav a2 s . c o m*/ } else { files = Dir.list(); } for (FileHandle tmp : files) { try { String stringFile = tmp + "/strings.ini"; FileHandle langFile = Gdx.files.getFileHandle(stringFile, mFiletype); if (langFile.exists()) { String tmpName = getLangNameFromFile(stringFile); Temp.add(new Lang(tmpName, stringFile)); } } catch (IOException e) { e.printStackTrace(); } } return Temp; }
From source file:CB_UI.GL_UI.SoundCache.java
License:Open Source License
private static Music getMusikFromSetting(SettingsAudio set) { String path = set.getValue().Path; FileHandle handle = set.getValue().Class_Absolute ? Gdx.files.absolute(path) : GlobalCore.getInternalFileHandle(path); if (handle == null || !handle.exists() || handle.isDirectory() || path.length() == 0) { path = set.getDefaultValue().Path; handle = set.getValue().Class_Absolute ? Gdx.files.absolute(path) : GlobalCore.getInternalFileHandle(path); if (handle != null && handle.exists()) { set.loadDefault();//from w ww . ja v a 2 s .c o m set.setDirty(); } } if (handle == null || !handle.exists()) { Log.err(log, "LoadSound: " + set.getValue().Path); return null; } Music ret; try { ret = Gdx.audio.newMusic(handle); } catch (Exception e) { Log.err(log, "LoadSound: " + set.getValue().Path); return null; } return ret; }
From source file:CB_UI_Base.GL_UI.Fonts.java
License:Open Source License
/** * Ldt die verwendeten Bitmap Fonts und berechnet die entsprechenden Gren *///w w w . ja v a2 s . c o m public static void loadFonts(SkinBase skin) { cfg = skin.getSettings(); COLOR.loadColors(skin); FreeTypeFontGenerator generator = null; // get the first found ttf-font FileHandle font = null; if (cfg.SkinFolder.isDirectory()) { FileHandle[] ttfFonts = cfg.SkinFolder.list(); for (FileHandle file : ttfFonts) { if (file.extension().equalsIgnoreCase("ttf")) { font = file; break; } } } if (font == null || !font.exists()) { // no skin font found, use default font font = Global.getInternalFileHandle("skins/default/DroidSans-Bold.ttf"); } Log.debug(log, "Generate scaled Fonts from " + font); generator = new FreeTypeFontGenerator(font); double density = UiSizes.that.getScale(); compass = loadFontFromFile(generator, (int) (cfg.SizeBiggest * density)); big = loadFontFromFile(generator, (int) (cfg.SizeBig * density)); normal = loadFontFromFile(generator, (int) (cfg.SizeNormal * density)); small = loadFontFromFile(generator, (int) (cfg.SizeSmall * density)); normalBubble = loadFontFromFile(generator, (int) (cfg.SizeNormalbubble * density)); smallBubble = loadFontFromFile(generator, (int) (cfg.SizeSmallBubble * density)); generator.dispose(); }
From source file:com.agateau.pixelwheels.sound.SoundAtlas.java
License:Open Source License
public void load(String filename, String name) { FileHandle file = mRootDir.child(filename); Assert.check(file.exists(), "No sound named " + filename + " in " + mRootDir.path()); if ("".equals(name)) { name = file.nameWithoutExtension(); }//from www . j av a2s .co m NLog.i("Loading sound %s from %s", name, file.path()); mSounds.put(name, Gdx.audio.newSound(file)); }
From source file:com.agateau.pixelwheels.vehicledef.VehicleIO.java
License:Open Source License
public static VehicleDef get(String id) { String fileName = "vehicles/" + id + ".xml"; FileHandle handle = FileUtils.assets(fileName); if (!handle.exists()) { throw new RuntimeException("No such file " + fileName); }/*w w w . j a va2s . com*/ XmlReader.Element root = FileUtils.parseXml(handle); try { return get(root, id); } catch (Exception e) { NLog.e("Error loading vehicle from %s: %s", fileName, e); e.printStackTrace(); throw new RuntimeException("Error loading vehicle from " + fileName); } }
From source file:com.andgate.ikou.io.LevelDatabaseService.java
License:Open Source License
public static LevelData[] readLevelDatas(FileHandle[] levelFolder, ProgressDatabase progressDB) { Array<LevelData> levelDatas = new Array<>(); for (int i = 0; i < levelFolder.length; i++) { FileHandle levelFile = levelFolder[i]; if (levelFile.exists() && levelFile.extension().equals(Constants.LEVEL_EXTENSION_NO_DOT)) { try { levelDatas.add(getLevelData(levelFile, progressDB)); } catch (final IOException e) { final String errorMessage = "Error reading level data."; Gdx.app.error(TAG, errorMessage, e); }/*from ww w . j av a 2s . c om*/ } } return levelDatas.toArray(new LevelData[levelDatas.size].getClass().getComponentType()); }
From source file:com.andgate.ikou.io.LevelLoader.java
License:Open Source License
public static Level load(LevelData levelData) throws IOException { String levelFileName = levelData.name + Constants.LEVEL_EXTENSION; FileHandle levelFileInternal = Gdx.files.external(Constants.LEVELS_INTERNAL_PATH + levelFileName); if (levelFileInternal.exists()) { return LevelService.read(levelFileInternal); }//from ww w . ja v a 2 s . c om FileHandle levelFileExternal = Gdx.files.external(Constants.LEVELS_EXTERNAL_PATH + levelFileName); return LevelService.read(levelFileExternal); }