Search in sources :

Example 6 with ContainerDTO

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;
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) ShortcutReader(org.phoenicis.library.ShortcutReader) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) Map(java.util.Map) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) Consumer(java.util.function.Consumer) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ConfigFile(org.phoenicis.tools.config.ConfigFile) Safe(org.phoenicis.configuration.security.Safe) CompatibleConfigFileFormatFactory(org.phoenicis.tools.config.CompatibleConfigFileFormatFactory) CollectionUtils(org.springframework.util.CollectionUtils) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) ConfigFile(org.phoenicis.tools.config.ConfigFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile) Map(java.util.Map)

Example 7 with ContainerDTO

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);
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) ShortcutReader(org.phoenicis.library.ShortcutReader) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) Map(java.util.Map) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) Consumer(java.util.function.Consumer) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ConfigFile(org.phoenicis.tools.config.ConfigFile) Safe(org.phoenicis.configuration.security.Safe) CompatibleConfigFileFormatFactory(org.phoenicis.tools.config.CompatibleConfigFileFormatFactory) CollectionUtils(org.springframework.util.CollectionUtils) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) IOException(java.io.IOException) ShortcutReader(org.phoenicis.library.ShortcutReader) Value(org.springframework.beans.factory.annotation.Value) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Example 8 with ContainerDTO

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();
}
Also used : FeaturePanel(org.phoenicis.javafx.components.common.control.FeaturePanel) EngineToolsManager(org.phoenicis.engines.EngineToolsManager) EnginesManager(org.phoenicis.engines.EnginesManager) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) FXCollections(javafx.collections.FXCollections) ContainersFeaturePanelSkin(org.phoenicis.javafx.components.container.skin.ContainersFeaturePanelSkin) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) None(org.phoenicis.javafx.components.common.panelstates.None) EngineSetting(org.phoenicis.engines.EngineSetting) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) ContainersManager(org.phoenicis.containers.ContainersManager) VerbsManager(org.phoenicis.engines.VerbsManager) ObjectProperty(javafx.beans.property.ObjectProperty) ContainersFilter(org.phoenicis.javafx.views.mainwindow.containers.ContainersFilter) IOException(java.io.IOException) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) ObservableMap(javafx.collections.ObservableMap) File(java.io.File) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) Platform(javafx.application.Platform) java.awt(java.awt) List(java.util.List) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) SimpleConfirmDialog(org.phoenicis.javafx.dialogs.SimpleConfirmDialog) OpenDetailsPanel(org.phoenicis.javafx.components.common.panelstates.OpenDetailsPanel) ObservableList(javafx.collections.ObservableList) SimpleConfirmDialog(org.phoenicis.javafx.dialogs.SimpleConfirmDialog) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog)

Example 9 with ContainerDTO

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);
    }
}
Also used : EngineSetting(org.phoenicis.engines.EngineSetting) ComboBox(javafx.scene.control.ComboBox) Text(javafx.scene.text.Text) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Observable(javafx.beans.Observable)

Example 10 with ContainerDTO

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);
    }
}
Also used : ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO)

Aggregations

ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)21 File (java.io.File)12 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)12 ContainerCategoryDTO (org.phoenicis.containers.dto.ContainerCategoryDTO)11 ArrayList (java.util.ArrayList)10 ConfigFile (org.phoenicis.tools.config.ConfigFile)10 List (java.util.List)9 Consumer (java.util.function.Consumer)8 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 IOException (java.io.IOException)7 Collectors (java.util.stream.Collectors)7 TypeReference (com.fasterxml.jackson.core.type.TypeReference)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Collections (java.util.Collections)6 Map (java.util.Map)6 ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)6 Safe (org.phoenicis.configuration.security.Safe)6 LibraryManager (org.phoenicis.library.LibraryManager)6