use of com.pixbits.lib.io.archive.handles.HandleLink in project rom-manager by Jakz.
the class Organizer method renameRom.
public void renameRom(Game game) {
/* special case: all roms of the game are inside same archive, just rename the archive */
Set<Path> filesForGame = game.stream().map(Rom::handle).map(Handle::path).collect(Collectors.toSet());
if (filesForGame.size() == 1 && !game.stream().map(Rom::handle).anyMatch(h -> h instanceof HandleLink)) {
Path path = filesForGame.iterator().next();
String correctName = game.getCorrectName() + '.' + FileUtils.pathExtension(path);
Path correctPath = path.getParent().resolve(correctName);
if (!path.equals(correctPath)) {
// TODO: forward exception to caller
try {
Files.move(path, correctPath);
game.stream().map(Rom::handle).forEach(handle -> handle.relocate(correctPath));
} catch (IOException exception) {
exception.printStackTrace();
}
}
}
// throw new UnsupportedOperationException("relocate name is not compatible with new handles");
/* TODO
Handle romPath = rom.getHandle();
Path renameTo = romPath.path().getParent();
//TODO: should fix extensions if wrong and crc is verified but now just keeps them
renameTo = renameTo.resolve(rom.getCorrectName()+"."+romPath.getExtension());
try
{
rom.move(renameTo);
}
catch (FileAlreadyExistsException e)
{
logger.e(LogTarget.game(rom), "Can't rename file, already exists: "+e.getFile());
}
catch (Exception e)
{
e.printStackTrace();
// TODO: handle and write on log
}*/
}
Aggregations