Java Code Examples for com.badlogic.gdx.files.FileHandle#path()
The following examples show how to use
com.badlogic.gdx.files.FileHandle#path() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicEventManager.java From gdx-soundboard with MIT License | 6 votes |
/** * Load a save file. * * @param fileName * The path to the file. */ public void load(FileHandle file) { this.clear(); final Json json = new Json(JsonWriter.OutputType.json); container = json.fromJson(Container.class, file.readString()); String path = file.path(); int lastSlash = path.lastIndexOf("/"); container.basePath = path.substring(0, lastSlash); for (int i = 0; i < container.states.size; i++) { final MusicState state = container.states.get(i); add(state); } }
Example 2
Source File: ProjectController.java From talos with Apache License 2.0 | 6 votes |
public void saveProject (FileHandle destination) { try { String data = currentProject.getProjectString(); destination.writeString(data, false); reportProjectFileInterraction(destination); TalosMain.Instance().Prefs().putString("lastSave" + currentProject.getExtension(), destination.parent().path()); TalosMain.Instance().Prefs().flush(); currentTab.setDirty(false); currentTab.setWorthy(); currentProjectPath = destination.path(); projectFileName = destination.name(); if (!currentTab.getFileName().equals(projectFileName)) { clearCache(currentTab.getFileName()); currentTab.setFileName(projectFileName); TalosMain.Instance().UIStage().tabbedPane.updateTabTitle(currentTab); fileCache.put(projectFileName, data); } } catch (Exception e) { TalosMain.Instance().reportException(e); } }
Example 3
Source File: ProjectController.java From talos with Apache License 2.0 | 6 votes |
public void reportProjectFileInterraction(FileHandle handle) { Preferences prefs = TalosMain.Instance().Prefs(); String data = prefs.getString("recents"); Array<RecentsEntry> list = new Array<>(); //read Json json = new Json(); try { if (data != null && !data.isEmpty()) { list = json.fromJson(list.getClass(), data); } } catch( Exception e) { } RecentsEntry newEntry = new RecentsEntry(handle.path(), TimeUtils.millis()); list.removeValue(newEntry, false); list.add(newEntry); //sort list.sort(recentsEntryComparator); //write String result = json.toJson(list); prefs.putString("recents", result); prefs.flush(); updateRecentsList(); }
Example 4
Source File: PreviewWidget.java From talos with Apache License 2.0 | 6 votes |
public void addPreviewImage (String[] paths) { if (paths.length == 1) { String resourcePath = paths[0]; FileHandle fileHandle = Gdx.files.absolute(resourcePath); final String extension = fileHandle.extension(); if (extension.endsWith("png") || extension.endsWith("jpg")) { fileHandle = TalosMain.Instance().ProjectController().findFile(fileHandle); if(fileHandle != null && fileHandle.exists()) { final TextureRegion textureRegion = new TextureRegion(new Texture(fileHandle)); if (textureRegion != null) { previewImage.setDrawable(new TextureRegionDrawable(textureRegion)); previewController.setImageWidth(10); backgroundImagePath = fileHandle.path(); TalosMain.Instance().ProjectController().setDirty(); } } } } }
Example 5
Source File: GLTFDemo.java From gdx-gltf with Apache License 2.0 | 6 votes |
private void load(FileHandle glFile){ Gdx.app.log(TAG, "loading " + glFile.name()); lastFileName = glFile.path(); if(USE_ASSET_MANAGER){ assetManager.load(lastFileName, SceneAsset.class); assetManager.finishLoading(); rootModel = assetManager.get(lastFileName, SceneAsset.class); }else{ if(glFile.extension().equalsIgnoreCase("glb")){ rootModel = new GLBLoader().load(glFile); }else if(glFile.extension().equalsIgnoreCase("gltf")){ rootModel = new GLTFLoader().load(glFile); } } load(); Gdx.app.log(TAG, "loaded " + glFile.path()); new GLTFInspector().inspect(rootModel); }
Example 6
Source File: KryoManager.java From Mundus with Apache License 2.0 | 6 votes |
/** * Loads the project context .pro. * * Does however not load the scenes (only the scene names as reference) or * meshes/textures (see ProjectManager). * * @param ref * project to load * @return loaded project context without scenes * @throws FileNotFoundException */ public ProjectContext loadProjectContext(ProjectRef ref) throws FileNotFoundException { // find .pro file FileHandle projectFile = null; for (FileHandle f : Gdx.files.absolute(ref.getPath()).list()) { if (f.extension().equals(ProjectManager.PROJECT_EXTENSION)) { projectFile = f; break; } } if (projectFile != null) { Input input = new Input(new FileInputStream(projectFile.path())); ProjectDescriptor projectDescriptor = kryo.readObjectOrNull(input, ProjectDescriptor.class); ProjectContext context = DescriptorConverter.convert(projectDescriptor); context.activeSceneName = projectDescriptor.getCurrentSceneName(); return context; } return null; }
Example 7
Source File: AndroidModLoader.java From Cubes with MIT License | 6 votes |
public static String hashFile(FileHandle fileHandle) throws Exception { InputStream inputStream = fileHandle.read(); try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] bytesBuffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(bytesBuffer)) != -1) { digest.update(bytesBuffer, 0, bytesRead); } byte[] hashedBytes = digest.digest(); return convertByteArrayToHexString(hashedBytes); } catch (IOException ex) { throw new CubesException("Could not generate hash from file " + fileHandle.path(), ex); } finally { StreamUtils.closeQuietly(inputStream); } }
Example 8
Source File: ProjectController.java From talos with Apache License 2.0 | 5 votes |
public String getLastDir(String action, IProject projectType) { String path = TalosMain.Instance().Prefs().getString("last" + action + projectType.getExtension()); FileHandle handle = Gdx.files.absolute(path); if(handle.exists()) { return handle.path(); } return ""; }
Example 9
Source File: PolylineModuleWrapper.java From talos with Apache License 2.0 | 5 votes |
public void setTexture(String path) { FileHandle fileHandle = tryAndFineTexture(path); if(fileHandle.exists()) { TextureRegion region = new TextureRegion(new Texture(fileHandle)); module.setRegion(fileHandle.nameWithoutExtension(), region); dropWidget.setDrawable(new TextureRegionDrawable(region)); } filePath = fileHandle.path(); regionName = fileHandle.nameWithoutExtension(); }
Example 10
Source File: TextureDropModuleWrapper.java From talos with Apache License 2.0 | 5 votes |
public void setTexture(String path) { FileHandle fileHandle = tryAndFindTexture(path); if(fileHandle.exists()) { Sprite region = new Sprite(new Texture(fileHandle)); setModuleRegion(fileHandle.nameWithoutExtension(), region); dropWidget.setDrawable(new TextureRegionDrawable(region)); } filePath = fileHandle.path(); regionName = fileHandle.nameWithoutExtension(); }
Example 11
Source File: AtlasLoader.java From AzurLaneSpineCharacterDecoder with MIT License | 5 votes |
Map<String, Array<Integer>> getRegion(FileHandle atlasFile) throws FileNotFoundException { if (!atlasFile.exists()) throw new FileNotFoundException("file:" + atlasFile.path() + "do not exist"); Map<String, Array<Integer>> reValue = new HashMap<String, Array<Integer>>(); String fileData = atlasFile.readString().replace("\r\n", "\n"); Matcher match = value.matcher(fileData); int count=0; while (match.find()) { count++; //System.out.println(match.group(0)); int x, y, w, h; String region = match.group(); String[] perLine = region.split("\n\\s{2}"); String name = perLine[0]; String xy = perLine[2].replace("\n",""), size = perLine[3].replace("\n",""); int post_1 = xy.lastIndexOf(","), post_2 = size.lastIndexOf(","); x = Integer.parseInt(xy.substring(4, post_1)); y = Integer.parseInt(xy.substring(post_1 + 2)); w = Integer.parseInt(size.substring(6, post_2)); h = Integer.parseInt(size.substring(post_2 + 2)); Array<Integer> temp = new Array<Integer>(); temp.add(x); temp.add(y); temp.add(w); temp.add(h); reValue.put(name, temp); /*System.out.println(name); System.out.println(xy); System.out.println(size); System.out.println(x); System.out.println(y); System.out.println(w); System.out.println(h); */ } return reValue; }
Example 12
Source File: Utils.java From skin-composer with MIT License | 5 votes |
public static void openFileExplorer(FileHandle startDirectory) throws IOException { if (startDirectory.exists()) { File file = startDirectory.file(); Desktop desktop = Desktop.getDesktop(); desktop.open(file); } else { throw new IOException("Directory doesn't exist: " + startDirectory.path()); } }
Example 13
Source File: ClassFinder.java From libgdx-snippets with MIT License | 5 votes |
private FileHandle relativeTo(FileHandle file, FileHandle root) { if (root == null) { return file; } String r = root.path(); String f = file.path(); if (!f.startsWith(r)) { return file; } return new FileHandle(f.substring(r.length() + 1)); }
Example 14
Source File: Compatibility.java From Cubes with MIT License | 5 votes |
public void makeBaseFolder() { FileHandle baseFolder = getBaseFolder(); baseFolder.mkdirs(); if (!baseFolder.isDirectory()) { FileHandle parent = baseFolder.parent(); if (!parent.isDirectory()) Log.error("Parent directory '" + parent.path() + "' doesn't exist!"); throw new CubesException("Failed to make Cubes folder! '" + baseFolder.path() + "'"); } }
Example 15
Source File: SinglePlayer.java From uracer-kotd with Apache License 2.0 | 4 votes |
/** Load from disk all the replays for the specified trackId, pruning while loading respecting the ReplayManager.MaxReplays * constant. Any previous Replay will be cleared from the lapManager instance. */ private int loadReplaysFromDiskFor (String trackId) { lapManager.removeAllReplays(); int reloaded = 0; for (FileHandle userdir : Gdx.files.external(Storage.ReplaysRoot + gameWorld.getLevelId()).list()) { if (userdir.isDirectory()) { for (FileHandle userreplay : userdir.list()) { Replay replay = Replay.load(userreplay.path()); if (replay != null) { // add replays even if slower ReplayResult ri = lapManager.addReplay(replay); if (ri.is_accepted) { ReplayUtils.pruneReplay(ri.pruned); // prune if needed reloaded++; Gdx.app.log("SinglePlayer", "Loaded replay #" + ri.accepted.getShortId()); } else { String msg = ""; switch (ri.reason) { case Null: msg = "null replay (" + userreplay.path() + ")"; break; case InvalidMinDuration: msg = "invalid lap (" + ri.discarded.getSecondsStr() + "s < " + GameplaySettings.ReplayMinDurationSecs + "s) (#" + ri.discarded.getShortId() + ")"; break; case Invalid: msg = "the specified replay is not valid. (" + userreplay.path() + ")"; break; case WrongTrack: msg = "the specified replay belongs to another game track (#" + ri.discarded.getShortId() + ")"; break; case Slower: msg = "too slow! (#" + ri.discarded.getShortId() + ")"; ReplayUtils.pruneReplay(ri.discarded); break; case Accepted: break; } Gdx.app.log("SinglePlayer", "Discarded at loading time, " + msg); } } } } } Gdx.app.log("SinglePlayer", "Building opponents list:"); rebindAllReplays(); int pos = 1; for (Replay r : lapManager.getReplays()) { Gdx.app.log("SinglePlayer", "#" + pos + ", #" + r.getShortId() + ", secs=" + r.getSecondsStr() + ", ct=" + r.getCreationTimestamp()); pos++; } Gdx.app.log("SinglePlayer", "Reloaded " + reloaded + " opponents."); return reloaded; }
Example 16
Source File: MusicEventManager.java From gdx-soundboard with MIT License | 4 votes |
/** * Create a new project. * * @param handle The base path. */ public void create(FileHandle handle){ this.clear(); container = new Container(); container.basePath = handle.path(); }
Example 17
Source File: PreferencesIO.java From vis-ui with Apache License 2.0 | 4 votes |
public FileHandleData (FileHandle file) { type = file.type(); path = file.path(); }
Example 18
Source File: ProjectController.java From talos with Apache License 2.0 | 4 votes |
public void loadProject (FileHandle projectFileHandle) { try { if (projectFileHandle.exists()) { FileTab prevTab = currentTab; boolean removingUnworthy = false; if (currentTab != null) { if (currentTab.getProjectType() == currentProject && currentTab.isUnworthy()) { removingUnworthy = true; clearCache(currentTab.getFileName()); } else { IProject tmp = currentProject; currentProject = currentTab.getProjectType(); saveProjectToCache(projectFileName); currentProject = tmp; } } currentProjectPath = projectFileHandle.path(); projectFileName = projectFileHandle.name(); loading = true; currentTab = new FileTab(projectFileName, currentProject); // trackers need to know what current tab is String string = projectFileHandle.readString(); currentProject.loadProject(string); snapshotTracker.reset(string); reportProjectFileInterraction(projectFileHandle); loading = false; if (lastDirTracking) { TalosMain.Instance().Prefs().putString("lastOpen" + currentProject.getExtension(), projectFileHandle.parent().path()); TalosMain.Instance().Prefs().flush(); } TalosMain.Instance().UIStage().tabbedPane.add(currentTab); final Array<String> savedResourcePaths = currentProject.getSavedResourcePaths(); TalosMain.Instance().FileTracker().addSavedResourcePathsFor(currentTab, savedResourcePaths); if (removingUnworthy) { safeRemoveTab(prevTab); } } else { //error handle } } catch (Exception e) { TalosMain.Instance().reportException(e); } }