use of org.phoenicis.library.dto.ShortcutDTO in project phoenicis by PhoenicisOrg.
the class ShortcutManager method updateShortcut.
public void updateShortcut(ShortcutDTO shortcutDTO) {
final String baseName = shortcutDTO.getId();
final File shortcutDirectory = new File(this.shortcutDirectory);
// backup icon if it didn't change (deleteShortcut will delete it -> icon lost after shortcut update)
final File iconFile = new File(shortcutDirectory, baseName + ".icon");
final File iconBackup = new File(shortcutDirectory, baseName + ".icon_backup");
final URI shortcutIcon = shortcutDTO.getIcon();
if (shortcutIcon != null && shortcutIcon.getPath() != null) {
final boolean keepIcon = shortcutIcon.getPath().equals(iconFile.getPath());
if (keepIcon) {
try {
Files.move(iconFile.toPath(), iconBackup.toPath());
shortcutDTO = new ShortcutDTO.Builder(shortcutDTO).withIcon(iconBackup.toURI()).build();
} catch (IOException e) {
LOGGER.error("Could not backup icon.", e);
}
}
}
// backup miniature if it didn't change (deleteShortcut will delete it -> miniature lost after shortcut update)
final File miniatureFile = new File(shortcutDirectory, baseName + ".miniature");
final File miniatureBackup = new File(shortcutDirectory, baseName + ".miniature_backup");
final URI shortcutMiniature = shortcutDTO.getMiniature();
if (shortcutMiniature != null && shortcutMiniature.getPath() != null) {
final boolean keepMiniature = shortcutMiniature.getPath().equals(miniatureFile.getPath());
if (keepMiniature) {
try {
Files.move(miniatureFile.toPath(), miniatureBackup.toPath());
shortcutDTO = new ShortcutDTO.Builder(shortcutDTO).withMiniature(miniatureBackup.toURI()).build();
} catch (IOException e) {
LOGGER.error("Could not backup miniature.", e);
}
}
}
deleteShortcut(shortcutDTO);
createShortcut(shortcutDTO);
// delete backups
if (iconBackup.exists()) {
iconBackup.delete();
}
if (miniatureBackup.exists()) {
miniatureBackup.delete();
}
}
use of org.phoenicis.library.dto.ShortcutDTO in project phoenicis by PhoenicisOrg.
the class ShortcutRunner method run.
public void run(ShortcutDTO shortcutDTO, List<String> arguments, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"Wine\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
shortcutReader.callMember("run", arguments);
}, errorCallback), errorCallback);
}
use of org.phoenicis.library.dto.ShortcutDTO in project phoenicis by PhoenicisOrg.
the class ShortcutRunner method stop.
public void stop(ShortcutDTO shortcutDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"Wine\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
shortcutReader.callMember("stop");
}, errorCallback), errorCallback);
}
use of org.phoenicis.library.dto.ShortcutDTO in project phoenicis by PhoenicisOrg.
the class ListWidgetEntry method create.
public static ListWidgetEntry<ContainerDTO> create(ContainerDTO container) {
final List<BufferedImage> miniatures = new ArrayList<>();
// do not use too many segments (cannot recognize the miniature if the segment is too small)
final int maxSegments = 4;
int currentSegment = 0;
for (ShortcutDTO shortcutDTO : container.getInstalledShortcuts()) {
if (currentSegment >= maxSegments) {
break;
}
try {
miniatures.add(ImageIO.read(shortcutDTO.getMiniature().toURL()));
currentSegment++;
} catch (IOException e) {
LOGGER.warn(String.format("Could not read miniature for shortcut \"%s\"", shortcutDTO.getInfo().getName()), e);
}
}
final BufferedImage segmentedMiniature = createSegmentedMiniature(miniatures);
final Optional<URI> shortcutMiniature = saveBufferedImage(segmentedMiniature, container.getName());
return new ListWidgetEntry<>(container, shortcutMiniature, CONTAINER_MINIATURE, container.getName(), Optional.empty(), Optional.empty());
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PlayOnLinux.
the class GenericContainersManager method fetchContainers.
/**
* fetches all containers in a given directory
*
* @param directory
* @return found containers
*/
private List<ContainerDTO> fetchContainers(File directory) {
final List<ContainerDTO> containers = new ArrayList<>();
final File[] containerDirectories = directory.listFiles();
if (containerDirectories != null) {
for (File containerDirectory : containerDirectories) {
if (!containerDirectory.isHidden()) {
final ConfigFile configFile = compatibleConfigFileFormatFactory.open(new File(containerDirectory, "phoenicis.cfg"));
final String containerPath = containerDirectory.getAbsolutePath();
final String containerName = containerPath.substring(containerPath.lastIndexOf('/') + 1);
// find shortcuts which use this container
List<ShortcutDTO> shortcutDTOS = libraryManager.fetchShortcuts().stream().flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).filter(shortcut -> {
boolean toAdd = false;
try {
final Map<String, Object> shortcutProperties = objectMapper.readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() {
});
toAdd = shortcutProperties.get("winePrefix").equals(containerName);
} catch (IOException e) {
LOGGER.warn("Could not parse shortcut script JSON", e);
}
return toAdd;
}).collect(Collectors.toList());
if (directory.getName().equals("wineprefix")) {
containers.add(new WinePrefixContainerDTO.Builder().withName(containerDirectory.getName()).withPath(containerPath).withInstalledShortcuts(shortcutDTOS).withArchitecture(configFile.readValue("wineArchitecture", "")).withDistribution(configFile.readValue("wineDistribution", "")).withVersion(configFile.readValue("wineVersion", "")).build());
}
}
}
containers.sort(ContainerDTO.nameComparator());
}
return containers;
}
Aggregations