Search in sources :

Example 1 with Handle

use of com.pixbits.lib.io.archive.handles.Handle in project rom-manager by Jakz.

the class GameConsolidator method accept.

public void accept(GameEntry handle) {
    Game game = handle.getGame();
    // TODO: broken with new management
    game.stream().forEach(rom -> {
        try {
            Path finalPath = handle.getFinalPath(destination);
            if (!overwrite && Files.exists(finalPath))
                return;
            Files.createDirectories(finalPath.getParent());
            if (handle.hasBeenModified()) {
                Files.move(handle.getPath(), finalPath, StandardCopyOption.REPLACE_EXISTING);
            } else {
                Handle path = rom.handle();
                if (!path.isArchive())
                    Files.copy(path.path(), finalPath, StandardCopyOption.REPLACE_EXISTING);
                else
                    Files.copy(path.getInputStream(), finalPath, StandardCopyOption.REPLACE_EXISTING);
            }
        // if (handle.getBuffer() == null)
        // handle.prepareBuffer();
        // Files.deleteIfExists(handle.getPath());
        } catch (Exception e) {
            System.out.println("Error on " + rom.handle().toString());
            if (e.getCause() != e)
                e.getCause().printStackTrace();
            else
                e.printStackTrace();
        }
    });
}
Also used : Path(java.nio.file.Path) Game(com.github.jakz.romlib.data.game.Game) Handle(com.pixbits.lib.io.archive.handles.Handle)

Example 2 with Handle

use of com.pixbits.lib.io.archive.handles.Handle in project rom-manager by Jakz.

the class GameEntry method prepareBuffer.

public void prepareBuffer() throws IOException {
    Handle source = getGame().rom().handle();
    this.path = Files.createTempFile(null, null);
    Files.copy(source.getInputStream(), path, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
}
Also used : Handle(com.pixbits.lib.io.archive.handles.Handle)

Example 3 with Handle

use of com.pixbits.lib.io.archive.handles.Handle in project rom-manager by Jakz.

the class Organizer method moveRom.

public void moveRom(Game game) {
    if (game.getStatus().isComplete()) {
        try {
            Path finalPath = settings().romsPath.resolve(game.getCorrectFolder());
            if (!Files.exists(finalPath) || !Files.isDirectory(finalPath)) {
                Files.createDirectories(finalPath);
                logger.i(LogTarget.none(), "Creating folder " + finalPath);
            }
            Handle romPath = game.rom().handle();
            Path newFile = finalPath.resolve(romPath.path().getFileName());
            if (!newFile.equals(romPath.path()) && Files.exists(newFile)) {
                logger.e(LogTarget.game(game), "Cannot rename to " + newFile.toString() + ", file exists");
            } else if (!newFile.equals(romPath.path())) {
                game.move(newFile);
                logger.e(LogTarget.game(game), "Moved rom to " + finalPath);
            }
        } catch (Exception e) {
            // TODO: handle and log
            e.printStackTrace();
        }
    }
}
Also used : Path(java.nio.file.Path) Handle(com.pixbits.lib.io.archive.handles.Handle)

Example 4 with Handle

use of com.pixbits.lib.io.archive.handles.Handle in project rom-manager by Jakz.

the class TextAttributeField method setValue.

void setValue(Game game) {
    deleteButton.setVisible(this.infoPanel.mode == Mode.EDIT && game.hasCustomAttribute(attrib));
    if (attrib == GameAttribute.PATH) {
        Handle handle = game.rom().handle();
        String handleValue = handle == null ? "" : handle.toString();
        value.setText(handleValue);
    } else if (attrib instanceof RomAttribute) {
        Rom rom = game.rom();
        value.setText(attrib.prettyValue(rom.getAttribute((RomAttribute) attrib)));
    } else
        value.setText(attrib.prettyValue(game.getAttribute(attrib)));
}
Also used : Rom(com.github.jakz.romlib.data.game.Rom) RomAttribute(com.github.jakz.romlib.data.game.attributes.RomAttribute) Handle(com.pixbits.lib.io.archive.handles.Handle)

Aggregations

Handle (com.pixbits.lib.io.archive.handles.Handle)4 Path (java.nio.file.Path)2 Game (com.github.jakz.romlib.data.game.Game)1 Rom (com.github.jakz.romlib.data.game.Rom)1 RomAttribute (com.github.jakz.romlib.data.game.attributes.RomAttribute)1