Java Code Examples for com.badlogic.gdx.files.FileHandle#name()

The following examples show how to use com.badlogic.gdx.files.FileHandle#name() . 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: ProjectController.java    From talos with Apache License 2.0 6 votes vote down vote up
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 2
Source File: MainMenu.java    From talos with Apache License 2.0 6 votes vote down vote up
public void updateRecentsList(Array<String> list) {
    openRecentPopup.clear();

    for(String path: list) {
        final FileHandle handle = Gdx.files.absolute(path);
        if(!handle.exists()) continue;;
        String name = handle.name();
        MenuItem item = new MenuItem(name);
        item.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if(handle.extension().equals("tls")) {
                    TalosMain.Instance().ProjectController().setProject(ProjectController.TLS);
                    TalosMain.Instance().ProjectController().loadProject(handle);
                } else {
                    TalosMain.Instance().Addons().projectFileDrop(handle);
                }
            }
        });
        openRecentPopup.addItem(item);
    }
}
 
Example 3
Source File: PolylineModuleWrapper.java    From talos with Apache License 2.0 6 votes vote down vote up
private FileHandle tryAndFineTexture(String path) {
    FileHandle fileHandle = Gdx.files.absolute(path);
    String fileName = fileHandle.name();
    if(!fileHandle.exists()) {
        if(TalosMain.Instance().ProjectController().getCurrentProjectPath() != null) {
            FileHandle parent = Gdx.files.absolute(TalosMain.Instance().ProjectController().getCurrentProjectPath()).parent();
            fileHandle = Gdx.files.absolute(parent.path() + "/" + fileName);
        }

        if(!fileHandle.exists()) {
            fileHandle = Gdx.files.absolute(TalosMain.Instance().Prefs().getString(SettingsDialog.ASSET_PATH) + File.separator + fileName);
        }
    }

    return fileHandle;
}
 
Example 4
Source File: TextureDropModuleWrapper.java    From talos with Apache License 2.0 6 votes vote down vote up
private FileHandle tryAndFindTexture(String path) {
    FileHandle fileHandle = Gdx.files.absolute(path);
    String fileName = fileHandle.name();
    if(!fileHandle.exists()) {
        if(TalosMain.Instance().ProjectController().getCurrentProjectPath() != null) {
            FileHandle parent = Gdx.files.absolute(TalosMain.Instance().ProjectController().getCurrentProjectPath()).parent();
            fileHandle = Gdx.files.absolute(parent.path() + "/" + fileName);
        }

        if(!fileHandle.exists()) {
            fileHandle = Gdx.files.absolute(TalosMain.Instance().Prefs().getString(SettingsDialog.ASSET_PATH) + File.separator + fileName);
        }
    }

    return fileHandle;
}
 
Example 5
Source File: GDXFacebookMultiPartRequest.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
private static byte[] loadFile(FileHandle fileHandle) throws IOException {
    InputStream is = fileHandle.read();

    long length = fileHandle.length();
    if (length > Integer.MAX_VALUE) {
        throw new IOException("File size to large");
    }
    byte[] bytes = new byte[(int) length];

    int offset = 0;
    int numRead;
    while (offset < bytes.length
            && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
        offset += numRead;
    }

    if (offset < bytes.length) {
        throw new IOException("Could not completely read file " + fileHandle.name());
    }

    is.close();
    return bytes;
}
 
Example 6
Source File: VfxGLUtils.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public static ShaderProgram compileShader(FileHandle vertexFile, FileHandle fragmentFile, String defines) {
    if (fragmentFile == null) {
        throw new IllegalArgumentException("Vertex shader file cannot be null.");
    }
    if (vertexFile == null) {
        throw new IllegalArgumentException("Fragment shader file cannot be null.");
    }
    if (defines == null) {
        throw new IllegalArgumentException("Defines cannot be null.");
    }

    StringBuilder sb = new StringBuilder();
    sb.append("Compiling \"").append(vertexFile.name()).append('/').append(fragmentFile.name()).append('\"');
    if (defines.length() > 0) {
        sb.append(" w/ (").append(defines.replace("\n", ", ")).append(")");
    }
    sb.append("...");
    Gdx.app.log(TAG, sb.toString());

    String prependVert = prependVertexCode + defines;
    String prependFrag = prependFragmentCode + defines;
    String srcVert = vertexFile.readString();
    String srcFrag = fragmentFile.readString();

    ShaderProgram shader = new ShaderProgram(prependVert + "\n" + srcVert, prependFrag + "\n" + srcFrag);

    if (!shader.isCompiled()) {
        throw new GdxRuntimeException("Shader compile error: " + vertexFile.name() + "/" + fragmentFile.name() + "\n" + shader.getLog());
    }
    return shader;
}
 
Example 7
Source File: ProjectController.java    From talos with Apache License 2.0 5 votes vote down vote up
public FileHandle findFile(FileHandle initialFile) {
    String fileName = initialFile.name();

    // local is priority, then the path, then the default lookup
    // do we currently have project loaded?
    if(currentProjectPath != null) {
        // we can look for local file then
        FileHandle currentProjectHandle = Gdx.files.absolute(currentProjectPath);
        if(currentProjectHandle.exists()) {
            String localPath = currentProjectHandle.parent().path() + File.separator + fileName;
            FileHandle localTry = Gdx.files.absolute(localPath);
            if(localTry.exists()) {
                return localTry;
            }
        }
    }

    //Maybe the absolute path was a better ideas
    if(initialFile.exists()) return initialFile;

    //oh crap it's nowhere to be found, default path to the rescue!
    FileHandle lastHopeHandle = currentProject.findFileInDefaultPaths(fileName);
    if(lastHopeHandle != null && lastHopeHandle.exists()) {
        return lastHopeHandle;
    }

    // well we did all we could. seppuku is imminent
    return null;
}
 
Example 8
Source File: BatchConvertDialog.java    From talos with Apache License 2.0 5 votes vote down vote up
private void convertOne(FileHandle fileHandle) {
    String subPath;

    if (inputPathField.getText().length() == fileHandle.parent().path().length()) {
        subPath = File.separator;
    } else {
         subPath = fileHandle.parent().path().substring(inputPathField.getText().length() + 1) + File.separator;
    }
    String projectPath = outputPath + File.separator + "projects" +  File.separator + subPath + fileHandle.nameWithoutExtension() + ".tls";
    String runtimePath = outputPath + File.separator + "runtime" +  File.separator + subPath + fileHandle.nameWithoutExtension() + ".p";

    FileHandle projectDestination = Gdx.files.absolute(projectPath);
    FileHandle exportDestination = Gdx.files.absolute(runtimePath);

    String result = "ok";
    try {
        TalosMain.Instance().TalosProject().importFromLegacyFormat(fileHandle);
        // now that it's done save TLS file
        TalosMain.Instance().ProjectController().saveProject(projectDestination);
        TalosMain.Instance().TalosProject().exportProject(exportDestination);

    } catch (Exception e) {
        result = "nok";
    }

    String text = "converting: " + fileHandle.name() + "        " + result + "\n";


    logItems.add(new Label(text, getSkin()));
    logArea.setItems(logItems);
    Label lbl = logArea.getItems().get(logArea.getItems().size-1);
    logArea.setSelected(lbl);
    scrollPane.layout();
    scrollPane.scrollTo(0, 0, 0, 0);
}
 
Example 9
Source File: FileHandleMetadata.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private FileHandleMetadata (FileHandle file) {
	this.name = file.name();
	this.directory = file.isDirectory();
	this.lastModified = file.lastModified();
	this.length = file.length();
	this.readableFileSize = FileUtils.readableFileSize(length);
}
 
Example 10
Source File: ProjectController.java    From talos with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example 11
Source File: FileListItem.java    From gdx-soundboard with MIT License 4 votes vote down vote up
public FileListItem(FileHandle file) {
    this(file.name(), file);
}