From bc62dc3416353d041fc1308fc7144c5786c726af Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 21 Oct 2018 17:22:29 +0700 Subject: [PATCH] FunctionalBridge --- .../runtime/dialog/overlay/update/update.js | 16 +---------- Launcher/runtime/engine/api.js | 1 + .../ru/gravit/launcher/LauncherEngine.java | 1 + .../launcher/client/FunctionalBridge.java | 28 +++++++++++++++++++ 4 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java diff --git a/Launcher/runtime/dialog/overlay/update/update.js b/Launcher/runtime/dialog/overlay/update/update.js index d4e366ca..04d9fc86 100644 --- a/Launcher/runtime/dialog/overlay/update/update.js +++ b/Launcher/runtime/dialog/overlay/update/update.js @@ -71,25 +71,11 @@ var update = { } }; -function offlineUpdateRequest(dirName, dir, matcher, digest) { - return function() { - var hdir = settings.lastHDirs.get(dirName); - if (hdir === null) { - Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); - return; - } - - // Verify dir with matcher using ClientLauncher's API - ClientLauncher.verifyHDir(dir, hdir.object, matcher, digest); - return hdir; - }; -} - /* Export functions */ function makeUpdateRequest(dirName, dir, matcher, digest, callback) { var request = settings.offline ? { setStateCallback: function(stateCallback) { /* Ignored */ } } : new UpdateRequest(dirName, dir, matcher, digest); - var task = settings.offline ? newTask(offlineUpdateRequest(dirName, dir, matcher, digest)) : + var task = settings.offline ? newTask(FunctionalBridge.offlineUpdateRequest(dirName, dir, matcher, digest)) : newRequestTask(request); // Set task properties and start diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js index effeb498..0cdbf766 100644 --- a/Launcher/runtime/engine/api.js +++ b/Launcher/runtime/engine/api.js @@ -2,6 +2,7 @@ var Launcher = LauncherClass.static; var LauncherConfig = LauncherConfigClass.static; var HTTPRequest = HTTPRequestClass.static; var DirBridge = DirBridgeClass.static; +var FunctionalBridge = FunctionalBridgeClass.class; // Hasher class API imports var PlayerProfile = PlayerProfileClass.static; diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index f5e49818..82cf25be 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -133,6 +133,7 @@ public static void addLauncherClassBindings(Map bindings) { bindings.put("DigestAlgorithmClass", SecurityHelper.DigestAlgorithm.class); bindings.put("VerifyHelperClass", VerifyHelper.class); bindings.put("DirBridgeClass", DirBridge.class); + bindings.put("FunctionalBridgeClass",FunctionalBridge.class); // Load JS API if available bindings.put("RingProgressIndicatorClass", RingProgressIndicator.class); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java new file mode 100644 index 00000000..f234d528 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -0,0 +1,28 @@ +package ru.gravit.launcher.client; + +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.hasher.FileNameMatcher; +import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.serialize.signed.SignedObjectHolder; + +import java.nio.file.Path; + +public class FunctionalBridge { + @LauncherAPI + public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) throws Exception + { + return () -> { + if(hdir == null) + { + Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); + } + ClientLauncher.verifyHDir(dir, hdir.object, matcher, digest); + return hdir; + }; + } + @FunctionalInterface + public interface HashedDirRunnable { + SignedObjectHolder run() throws Exception; + } +}