Search in sources :

Example 41 with Consumer

use of java.util.function.Consumer in project POL-POM-5 by PlayOnLinux.

the class WinePrefixContainerController method changeSetting.

public void changeSetting(WinePrefixContainerDTO winePrefix, RegistryParameter setting, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    final String registryPatch = registryWriter.generateRegFileContent(setting.toRegistryPatch());
    LOGGER.info("Updating registry for prefix: " + winePrefix.getPath());
    LOGGER.info(registryPatch);
    interactiveScriptSession.eval("include([\"Functions\", \"Engines\", \"Wine\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("prefix", winePrefix.getName());
        final ScriptObjectMirror regedit = (ScriptObjectMirror) wine.callMember("regedit");
        regedit.callMember("patch", registryPatch);
        wine.callMember("wait");
        doneCallback.run();
    }, errorCallback), errorCallback);
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) RegistryWriter(org.phoenicis.win32.registry.RegistryWriter) Logger(org.slf4j.Logger) FileUtilities(org.phoenicis.tools.files.FileUtilities) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) HashMap(java.util.HashMap) File(java.io.File) Consumer(java.util.function.Consumer) TerminalOpener(org.phoenicis.tools.system.terminal.TerminalOpener) List(java.util.List) RegistryParameter(org.phoenicis.containers.wine.parameters.RegistryParameter) ShortcutManager(org.phoenicis.library.ShortcutManager) Map(java.util.Map) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) OperatingSystemFetcher(org.phoenicis.tools.system.OperatingSystemFetcher) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 42 with Consumer

use of java.util.function.Consumer in project POL-POM-5 by PlayOnLinux.

the class WinePrefixContainerController method createShortcut.

/**
     * creates a shortcut for a given executable in a Wine prefix
     * @param winePrefix the Wine prefix
     * @param name name which is shown in the library
     * @param executable filename of the executable (WineShortcut will search for this file in the given prefix)
     * @param doneCallback callback executed after the shortcut has been created
     * @param errorCallback callback executed if there is an error
     */
public void createShortcut(WinePrefixContainerDTO winePrefix, String name, String executable, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Functions\", \"Shortcuts\", \"Wine\"]);", ignored -> interactiveScriptSession.eval("new WineShortcut()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("name", name);
        wine.callMember("search", executable);
        wine.callMember("prefix", winePrefix.getName());
        wine.callMember("create");
        doneCallback.run();
    }, errorCallback), errorCallback);
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) RegistryWriter(org.phoenicis.win32.registry.RegistryWriter) Logger(org.slf4j.Logger) FileUtilities(org.phoenicis.tools.files.FileUtilities) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) HashMap(java.util.HashMap) File(java.io.File) Consumer(java.util.function.Consumer) TerminalOpener(org.phoenicis.tools.system.terminal.TerminalOpener) List(java.util.List) RegistryParameter(org.phoenicis.containers.wine.parameters.RegistryParameter) ShortcutManager(org.phoenicis.library.ShortcutManager) Map(java.util.Map) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) OperatingSystemFetcher(org.phoenicis.tools.system.OperatingSystemFetcher) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 43 with Consumer

use of java.util.function.Consumer in project POL-POM-5 by PlayOnLinux.

the class EnginesController method installEngine.

private void installEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Functions\", \"Engines\", \"" + engineDTO.getCategory() + "\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("install", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
    }, errorCallback), errorCallback);
}
Also used : Files(java.nio.file.Files) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) AppsController(org.phoenicis.javafx.controller.apps.AppsController) File(java.io.File) Platform(javafx.application.Platform) Consumer(java.util.function.Consumer) List(java.util.List) EngineDTO(org.phoenicis.engines.dto.EngineDTO) EnginesSource(org.phoenicis.engines.EnginesSource) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) ViewEngines(org.phoenicis.javafx.views.mainwindow.engines.ViewEngines) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ConfirmMessage(org.phoenicis.javafx.views.common.ConfirmMessage) URI(java.net.URI) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) Path(java.nio.file.Path) ThemeManager(org.phoenicis.javafx.views.common.ThemeManager) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 44 with Consumer

use of java.util.function.Consumer in project Skree by Skelril.

the class JarResourceLoader method loadFromResources.

public void loadFromResources(Consumer<Function<String, Path>> execute) {
    try {
        URI uri = getClass().getResource(baseResourcePathName).toURI();
        if (uri.getScheme().equals("jar")) {
            try (FileSystem fileSystem = getFileSystem(uri)) {
                Function<String, Path> providerFunction = (resourceName) -> {
                    return fileSystem.getPath(baseResourcePathName + resourceName);
                };
                execute.accept(providerFunction);
            }
        } else {
            execute.accept(Paths::get);
        }
    } catch (Exception e) {
        System.err.println("Error loading: " + baseResourcePathName);
        e.printStackTrace();
    }
}
Also used : Consumer(java.util.function.Consumer) IOException(java.io.IOException) URI(java.net.URI) Collections(java.util.Collections) Function(java.util.function.Function) java.nio.file(java.nio.file) URI(java.net.URI) IOException(java.io.IOException)

Example 45 with Consumer

use of java.util.function.Consumer in project POL-POM-5 by PlayOnLinux.

the class ShortcutManager method uninstallFromShortcut.

public void uninstallFromShortcut(ShortcutDTO shortcutDTO, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Functions\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
        final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
        shortcutReader.callMember("of", shortcutDTO);
        shortcutReader.callMember("uninstall");
    }, errorCallback), errorCallback);
}
Also used : Consumer(java.util.function.Consumer) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) File(java.io.File) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Aggregations

Consumer (java.util.function.Consumer)193 List (java.util.List)81 Test (org.junit.Test)55 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)52 Map (java.util.Map)49 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)46 LoggerFactory (org.slf4j.LoggerFactory)41 Logger (org.slf4j.Logger)40 HashMap (java.util.HashMap)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)32 File (java.io.File)31 Collections (java.util.Collections)27 Set (java.util.Set)25 Collectors (java.util.stream.Collectors)25 TimeUnit (java.util.concurrent.TimeUnit)24 AtomicReference (java.util.concurrent.atomic.AtomicReference)24 CountDownLatch (java.util.concurrent.CountDownLatch)23 Arrays (java.util.Arrays)21 Supplier (java.util.function.Supplier)21