use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
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) {
final ConfigFile configFile = compatibleConfigFileFormatFactory.open(new File(containerDirectory, "phoenicis.cfg"));
final File userRegistryFile = new File(containerDirectory, "user.reg");
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", "")).withGlslValue(winePrefixContainerDisplayConfiguration.getGLSL(userRegistryFile)).withDirectDrawRenderer(winePrefixContainerDisplayConfiguration.getDirectDrawRenderer(userRegistryFile)).withVideoMemorySize(winePrefixContainerDisplayConfiguration.getVideoMemorySize(userRegistryFile)).withOffscreenRenderingMode(winePrefixContainerDisplayConfiguration.getOffscreenRenderingMode(userRegistryFile)).withMultisampling(winePrefixContainerDisplayConfiguration.getMultisampling(userRegistryFile)).withAlwaysOffscreen(winePrefixContainerDisplayConfiguration.getAlwaysOffscreen(userRegistryFile)).withStrictDrawOrdering(winePrefixContainerDisplayConfiguration.getStrictDrawOrdering(userRegistryFile)).withRenderTargetModeLock(winePrefixContainerDisplayConfiguration.getRenderTargetModeLock(userRegistryFile)).withMouseWarpOverride(winePrefixContainerInputConfiguration.getMouseWarpOverride(userRegistryFile)).build());
}
}
containers.sort(ContainerDTO.nameComparator());
}
return containers;
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class GenericContainersManager method deleteContainer.
/**
* {@inheritDoc}
* @param container
* @param errorCallback
*/
@Override
public void deleteContainer(ContainerDTO container, Consumer<Exception> errorCallback) {
try {
this.fileUtilities.remove(new File(container.getPath()));
} catch (IOException e) {
LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
errorCallback.accept(e);
}
List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()).forEach(shortcutDTO -> {
final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
final String containerName = (String) shortcutReader.callMember("container");
if (containerName.equals(container.getName())) {
this.shortcutManager.deleteShortcut(shortcutDTO);
}
}, errorCallback), errorCallback);
});
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class LibraryManager method fetchShortcuts.
public List<ShortcutCategoryDTO> fetchShortcuts() {
final File shortcutDirectoryFile = new File(this.shortcutDirectory);
if (!shortcutDirectoryFile.exists()) {
shortcutDirectoryFile.mkdirs();
return Collections.emptyList();
}
final File[] directoryContent = shortcutDirectoryFile.listFiles();
if (directoryContent == null) {
return Collections.emptyList();
}
HashMap<String, List<ShortcutDTO>> categoryMap = new HashMap<>();
for (File file : directoryContent) {
if ("shortcut".equals(FilenameUtils.getExtension(file.getName()))) {
ShortcutDTO shortcut = fetchShortcutDTO(shortcutDirectoryFile, file);
String categoryId = shortcut.getInfo().getCategory();
if (!categoryMap.containsKey(categoryId)) {
categoryMap.put(categoryId, new ArrayList<>());
}
categoryMap.get(categoryId).add(shortcut);
}
}
List<ShortcutCategoryDTO> shortcuts = new ArrayList<>();
for (Map.Entry<String, List<ShortcutDTO>> entry : categoryMap.entrySet()) {
entry.getValue().sort(ShortcutDTO.nameComparator());
ShortcutCategoryDTO category = new ShortcutCategoryDTO.Builder().withId(entry.getKey()).withName(entry.getKey()).withShortcuts(entry.getValue()).build();
shortcuts.add(tr(category));
}
return shortcuts;
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class ShortcutManager method uninstallFromShortcut.
public void uninstallFromShortcut(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("uninstall");
}, errorCallback), errorCallback);
}
use of org.phoenicis.library.dto.ShortcutDTO in project phoenicis by PhoenicisOrg.
the class GenericContainersManager method deleteContainer.
/**
* {@inheritDoc}
* @param container
* @param errorCallback
*/
@Override
public void deleteContainer(ContainerDTO container, Consumer<Exception> errorCallback) {
try {
this.fileUtilities.remove(new File(container.getPath()));
} catch (IOException e) {
LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
errorCallback.accept(e);
}
List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()).forEach(shortcutDTO -> {
final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
final String containerName = (String) shortcutReader.callMember("container");
if (containerName.equals(container.getName())) {
this.shortcutManager.deleteShortcut(shortcutDTO);
}
}, errorCallback), errorCallback);
});
}
Aggregations