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

The following examples show how to use com.badlogic.gdx.files.FileHandle#mkdirs() . 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: Utils.java    From skin-composer with MIT License 6 votes vote down vote up
/**
 * Extracts a zip file specified by the zipFilePath to a directory specified by
 * destDirectory (will be created if does not exists)
 * @param zipFile
 * @param destDirectory
 * @throws IOException
 */
public static void unzip(FileHandle zipFile, FileHandle destDirectory) throws IOException {
    destDirectory.mkdirs();
    
    InputStream is = zipFile.read();
    ZipInputStream zis = new ZipInputStream(is);
    
    ZipEntry entry = zis.getNextEntry();
    // iterates over entries in the zip file
    while (entry != null) {
        if (!entry.isDirectory()) {
            // if the entry is a file, extracts it
            extractFile(zis, destDirectory.child(entry.getName()));
        } else {
            // if the entry is a directory, make the directory
            destDirectory.child(entry.getName()).mkdirs();
        }
        zis.closeEntry();
        entry = zis.getNextEntry();
    }
    is.close();
    zis.close();
}
 
Example 2
Source File: LocalCloudSave.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void sync(UserData userData, IConflictResolver resolver) {
    FileHandle dir = Gdx.files.external(DIR);
    dir.mkdirs();
    final FileHandle saveFile = dir.child(SAVE_FILE_NAME);
    final FileHandle conflicted = dir.child(CONFLICT_FILE_NAME);
    if (saveFile.exists()) {
        DiceHeroes app = (DiceHeroes) Gdx.app.getApplicationListener();
        if (app.firstSession) {
            if (!conflicted.exists())
                conflicted.write(saveFile.read(), false);
        }
    }
    toFile(userData, saveFile);
    if (conflicted.exists()) {
        final Map local = fromFile(saveFile);
        final Map server = fromFile(conflicted);
        resolver.resolveConflict(server, new IConflictResolverCallback() {
            @Override public void onResolved(boolean useLocal) {
                conflicted.delete();
                toFile(useLocal ? local : server, saveFile);
            }
        });
    }
}
 
Example 3
Source File: DataValidationProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void processPackage(PackProcessingNode node) throws Exception {
    ProjectModel project = node.getProject();
    PackModel pack = node.getPack();

    if (Strings.isEmpty(pack.getOutputDir()))
        throw new IllegalStateException("Output directory is not specified");

    if (pack.getInputFiles().size == 0)
        throw new IllegalStateException("There is no input files to perform packing");

    // Create output dir if it doesn't exist
    FileHandle outputDir = Gdx.files.absolute(pack.getOutputDir());
    if (!outputDir.exists()) {
        System.out.println("Output directory doesn't exist. Creating: \"" + outputDir.file().getAbsolutePath() + "\"");
        outputDir.mkdirs();
    }
}
 
Example 4
Source File: AndroidModLoader.java    From Cubes with MIT License 6 votes vote down vote up
private FileHandle convertToDex(FileHandle fileHandle) throws Exception {
  String inputHash = hashFile(fileHandle);
  
  FileHandle cacheDir = new FileHandle(androidCompatibility.androidLauncher.getCacheDir());
  FileHandle dexDir = cacheDir.child("converted_mod_dex");
  dexDir.mkdirs();
  FileHandle dexFile = dexDir.child(inputHash + ".dex");
  
  if (!dexFile.exists()) {
    Log.warning("Trying to convert jar to dex: " + fileHandle.file().getAbsolutePath());
    com.android.dx.command.dexer.Main.Arguments arguments = new com.android.dx.command.dexer.Main.Arguments();
    arguments.parse(new String[]{"--output=" + dexFile.file().getAbsolutePath(), fileHandle.file().getAbsolutePath()});
    int result = com.android.dx.command.dexer.Main.run(arguments);
    if (result != 0) throw new CubesException("Failed to convert jar to dex [" + result + "]: " + fileHandle.file().getAbsolutePath());
    Log.warning("Converted jar to dex: " + fileHandle.file().getAbsolutePath());
  }
  
  return dexFile;
}
 
Example 5
Source File: ClientSaveManager.java    From Cubes with MIT License 6 votes vote down vote up
public static Save createSave(String name, String generatorID, Gamemode gamemode, String seedString) {
  if (name != null) name = name.trim();
  if (name == null || name.isEmpty()) name = "world-" + Integer.toHexString(MathUtils.random.nextInt());
  FileHandle folder = getSavesFolder();
  FileHandle handle = folder.child(name);
  handle.mkdirs();
  Compatibility.get().nomedia(handle);
  Save s = new Save(name, handle);

  SaveOptions options = new SaveOptions();
  options.setWorldSeed(seedString);
  options.worldType = generatorID;
  options.worldGamemode = gamemode;
  s.setSaveOptions(options);

  return s;
}
 
Example 6
Source File: Screenshot.java    From Cubes with MIT License 6 votes vote down vote up
private static void writeScreenshot(final Pixmap pixmap) {
  FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
  dir.mkdirs();
  final FileHandle f = dir.child(System.currentTimeMillis() + ".png");
  Log.info("Writing screenshot '" + f.file().getAbsolutePath() + "'");
  Executor.executeNotSided(new Runnable() {
    @Override
    public void run() {
      long start = System.currentTimeMillis();
      try {
        PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
        try {
          writer.setFlipY(true);
          writer.write(f, pixmap);
        } finally {
          writer.dispose();
        }
      } catch (IOException ex) {
        throw new CubesException("Error writing PNG: " + f, ex);
      } finally {
        pixmap.dispose();
      }
      Log.debug("Finished writing screenshot '" + f.file().getAbsolutePath() + "' (took " + (System.currentTimeMillis() - start) + "ms)");
    }
  });
}
 
Example 7
Source File: WelcomeScreen.java    From gdx-skineditor with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param projectName
 */
public void createProject(String projectName) {

	FileHandle projectFolder = Gdx.files.local("projects").child(projectName);
	if (projectFolder.exists() == true) {
		game.showNotice("Error", "Project name already in use!", stage);
		return;
	}

	projectFolder.mkdirs();
	projectFolder.child("assets").mkdirs();
	projectFolder.child("backups").mkdirs();
	game.skin.save(projectFolder.child("uiskin.json"));

	// Copy assets
	FileHandle assetsFolder = Gdx.files.local("resources/raw");
	assetsFolder.copyTo(projectFolder.child("assets"));
	// Rebuild from raw resources
	TexturePacker.Settings settings = new TexturePacker.Settings();
	settings.combineSubdirectories = true;
	TexturePacker.process(settings, "projects/" + projectName +"/assets/", "projects/" + projectName, "uiskin");

	game.showNotice("Operation completed", "New project successfully created.", stage);
	
	refreshProjects();
}
 
Example 8
Source File: Registry.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public FileHandle createTempFolder() {
    String tempFolderPath = FilenameUtils.concat(TEMP_DIR, UUID.randomUUID().toString()) + "/";
    FileHandle tempFolder = Gdx.files.absolute(tempFolderPath);
    tempFolder.mkdirs();

    return tempFolder;
}
 
Example 9
Source File: SaveAreaIO.java    From Cubes with MIT License 5 votes vote down vote up
public static FileHandle file(Save save, int x, int z) {
  FileHandle folderArea = save.folderArea();
  FileHandle xMostSignificant = folderArea.child(Integer.toString(x & 0xFFFF0000));
  FileHandle xLeastSignificant = xMostSignificant.child(Integer.toString(x & 0xFFFF));
  FileHandle zMostSignificant = xLeastSignificant.child(Integer.toString(z & 0xFFFF0000));
  zMostSignificant.mkdirs();
  Compatibility.get().nomedia(zMostSignificant);
  
  return zMostSignificant.child(Integer.toString(z & 0xFFFF));
}
 
Example 10
Source File: Compatibility.java    From Cubes with MIT License 5 votes vote down vote up
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 11
Source File: Performance.java    From Cubes with MIT License 5 votes vote down vote up
public static synchronized void toggleTracking() {
  if (enabled.get()) {
    stopTracking();
    FileHandle dir = Compatibility.get().getBaseFolder().child("performance");
    Compatibility.get().nomedia(dir);
    dir.mkdirs();
    final long time = System.currentTimeMillis();
    final File saveFile = dir.child(time + ".cbpf").file();
    final ArrayList<ThreadPerformance> saveNodes;
    synchronized (nodes) {
      saveNodes = new ArrayList<ThreadPerformance>(nodes);
      nodes.clear();
    }

    Thread thread = new Thread("PerformanceWrite" + time) {
      @Override
      public void run() {
        try {
          save(saveFile, saveNodes);
          PerformanceAnalysis.run(saveFile);
          Log.info("Saved performance analysis information '" + saveFile.getAbsolutePath() + ".txt'");
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    };
    thread.setDaemon(false);
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();
  } else {
    clear();
    startTracking();
  }
}
 
Example 12
Source File: ModManager.java    From Cubes with MIT License 5 votes vote down vote up
private static List<FileHandle> getModFiles() {
  FileHandle base = Compatibility.get().getBaseFolder().child("mods");
  base.mkdirs();
  Compatibility.get().nomedia(base);
  ArrayList<FileHandle> fileHandles = new ArrayList<FileHandle>();
  fileHandles.addAll(extraMods);
  Collections.addAll(fileHandles, base.list(new FileFilter() {
    @Override
    public boolean accept(File pathname) {
      String s = pathname.getName().toLowerCase();
      return s.endsWith(".cm");
    }
  }));
  return fileHandles;
}
 
Example 13
Source File: SkinEditorGame.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
	
	opt = new OptionalChecker();
	
	fm = new SystemFonts();
	fm.refreshFonts();
	
	// Create projects folder if not already here
	FileHandle dirProjects = new FileHandle("projects");
	
	if (dirProjects.isDirectory() == false) {
		dirProjects.mkdirs();
	}
	
	// Rebuild from raw resources, kind of overkill, might disable it for production
	TexturePacker.Settings settings = new TexturePacker.Settings();
	settings.combineSubdirectories = true;
	TexturePacker.process(settings, "resources/raw/", ".", "resources/uiskin");

	batch = new SpriteBatch();
	skin = new Skin();
	atlas = new TextureAtlas(Gdx.files.internal("resources/uiskin.atlas"));
	
	
	skin.addRegions(new TextureAtlas(Gdx.files.local("resources/uiskin.atlas")));
	skin.load(Gdx.files.local("resources/uiskin.json"));
	
	screenMain = new MainScreen(this);
	screenWelcome = new WelcomeScreen(this);
	setScreen(screenWelcome);
	
}