Search in sources :

Example 1 with ConfigFile

use of org.phoenicis.tools.config.ConfigFile in project phoenicis 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;
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) WinePrefixContainerInputConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerInputConfiguration) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) 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) WinePrefixContainerDisplayConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerDisplayConfiguration) Logger(org.slf4j.Logger) FileUtilities(org.phoenicis.tools.files.FileUtilities) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) 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) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) 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 2 with ConfigFile

use of org.phoenicis.tools.config.ConfigFile 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 3 with ConfigFile

use of org.phoenicis.tools.config.ConfigFile 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) {
            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 4 with ConfigFile

use of org.phoenicis.tools.config.ConfigFile in project POL-POM-5 by PlayOnLinux.

the class WinePrefixContainersManager method fetchContainers.

@Override
public void fetchContainers(Consumer<List<ContainerCategoryDTO>> callback, Consumer<Exception> errorCallback) {
    final File winePrefixesFile = new File(winePrefixPath);
    winePrefixesFile.mkdirs();
    final File[] winePrefixes = winePrefixesFile.listFiles();
    if (winePrefixes == null) {
        callback.accept(Collections.emptyList());
    } else {
        final List<ContainerCategoryDTO> containerCategories = new ArrayList<>();
        final List<ContainerDTO> containers = new ArrayList<>();
        for (File winePrefix : winePrefixes) {
            final ConfigFile configFile = compatibleConfigFileFormatFactory.open(new File(winePrefix, "phoenicis.cfg"));
            final File userRegistryFile = new File(winePrefix, "user.reg");
            containers.add(new WinePrefixContainerDTO.Builder().withName(winePrefix.getName()).withPath(winePrefix.getAbsolutePath()).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());
        containerCategories.add(new ContainerCategoryDTO.Builder().withName("Wine").withContainers(containers).build());
        callback.accept(containerCategories);
    }
}
Also used : ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) ConfigFile(org.phoenicis.tools.config.ConfigFile) ArrayList(java.util.ArrayList) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Aggregations

File (java.io.File)4 ArrayList (java.util.ArrayList)4 ContainerCategoryDTO (org.phoenicis.containers.dto.ContainerCategoryDTO)4 ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)4 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)4 ConfigFile (org.phoenicis.tools.config.ConfigFile)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IOException (java.io.IOException)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 Safe (org.phoenicis.configuration.security.Safe)3 LibraryManager (org.phoenicis.library.LibraryManager)3 ShortcutManager (org.phoenicis.library.ShortcutManager)3 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)3 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)3 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)3