use of org.phoenicis.library.ShortcutReader in project POL-POM-5 by PlayOnLinux.
the class GenericContainersManager method deleteContainer.
/**
* {@inheritDoc}
*/
@Override
public void deleteContainer(ContainerDTO container, Consumer<ContainerDTO> onSuccess, Consumer<Exception> onError) {
try {
final File containerFile = new File(container.getPath());
FileUtils.deleteDirectory(containerFile);
} catch (IOException e) {
LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
onError.accept(e);
}
// TODO: better way to get engine ID
final String engineId = container.getEngine().toLowerCase();
final List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
// remove the shortcuts leading to the container
categories.stream().flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).forEach(shortcut -> {
final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include(\"engines." + engineId + ".shortcuts.reader\");", result -> {
final org.graalvm.polyglot.Value shortcutReaderClass = (org.graalvm.polyglot.Value) result;
final ShortcutReader shortcutReader = shortcutReaderClass.newInstance().as(ShortcutReader.class);
shortcutReader.of(shortcut);
final String containerName = shortcutReader.getContainer();
if (containerName.equals(container.getName())) {
this.shortcutManager.deleteShortcut(shortcut);
}
}, onError);
});
onSuccess.accept(container);
}
Aggregations