use of org.phoenicis.containers.dto.ContainerDTO 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;
}
use of org.phoenicis.containers.dto.ContainerDTO 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);
}
use of org.phoenicis.containers.dto.ContainerDTO in project POL-POM-5 by PlayOnLinux.
the class ContainersFeaturePanel method deleteContainer.
/**
* Deletes a given container
*
* @param container The container
*/
public void deleteContainer(final ContainerDTO container) {
final SimpleConfirmDialog confirmMessage = SimpleConfirmDialog.builder().withTitle(tr("Delete {0} container", container.getName())).withMessage(tr("Are you sure you want to delete the {0} container?", container.getName())).withOwner(getScene().getWindow()).withYesCallback(() -> {
getContainersManager().deleteContainer(container, unused -> Platform.runLater(() -> setSelectedContainer(null)), e -> Platform.runLater(() -> {
final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error")).withException(e).withOwner(getScene().getWindow()).build();
errorDialog.showAndWait();
}));
getContainersManager().fetchContainers(containerCategories -> Platform.runLater(() -> categories.setAll(containerCategories)), e -> Platform.runLater(() -> {
final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Loading containers failed.")).withException(e).withOwner(getScene().getWindow()).build();
errorDialog.showAndWait();
}));
}).build();
confirmMessage.showAndCallback();
}
use of org.phoenicis.containers.dto.ContainerDTO in project POL-POM-5 by PlayOnLinux.
the class ContainerEngineSettingsPanelSkin method updateEngineSettingsGrid.
/**
* Updates the engine settings in the given {@link GridPane engineSettingsGrid}
*
* @param engineSettingsGrid The GridPane containing the shown engine settings
*/
private void updateEngineSettingsGrid(final GridPane engineSettingsGrid) {
engineSettingsGrid.getChildren().clear();
final ContainerDTO container = getControl().getContainer();
for (EngineSetting engineSetting : getControl().getEngineSettings()) {
final int row = engineSettingsGrid.getRowCount();
final Text engineSettingDescription = new Text(engineSetting.getText());
engineSettingDescription.getStyleClass().add("captionTitle");
final ObservableList<String> items = FXCollections.observableArrayList(engineSetting.getOptions());
final ComboBox<String> engineSettingComboBox = new ComboBox<>(items);
engineSettingComboBox.getStyleClass().add("engine-setting-combo-box");
engineSettingComboBox.disableProperty().bind(getControl().lockEngineSettingsProperty());
// if the container is not specified set no default values
if (container != null) {
try {
engineSettingComboBox.setValue(engineSetting.getCurrentOption(container.getName()));
} catch (Exception e) {
engineSettingComboBox.getSelectionModel().select(0);
LOGGER.warn(String.format("Could not fetch current option for engine setting \"%s\", will use default.", engineSetting.getText()));
LOGGER.debug("Caused by: ", e);
}
engineSettingComboBox.valueProperty().addListener((Observable invalidation) -> Platform.runLater(() -> {
getControl().setLockEngineSettings(true);
engineSetting.setOption(container.getName(), items.indexOf(engineSettingComboBox.getValue()));
getControl().setLockEngineSettings(false);
}));
}
engineSettingsGrid.addRow(row, engineSettingDescription, engineSettingComboBox);
}
}
use of org.phoenicis.containers.dto.ContainerDTO in project POL-POM-5 by PlayOnLinux.
the class ContainersFeaturePanelSkin method updateVerbs.
/**
* Applies the verbs belonging to the currently selected container to the given {@link ContainerInformationPanel}
*
* @param containerInformationPanel The information panel showing the details for the currently selected container
*/
private void updateVerbs(final ContainerInformationPanel containerInformationPanel) {
final ObservableMap<String, ApplicationDTO> verbs = getControl().getVerbs();
final ContainerDTO container = containerInformationPanel.getContainer();
if (container != null && verbs.containsKey(container.getEngine().toLowerCase())) {
containerInformationPanel.setVerbs(verbs.get(container.getEngine().toLowerCase()));
} else {
containerInformationPanel.setVerbs(null);
}
}
Aggregations