FunctionalBridge

This commit is contained in:
Gravit 2018-10-21 17:22:29 +07:00
parent e4c1a8ce96
commit bc62dc3416
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 31 additions and 15 deletions

View file

@ -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

View file

@ -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;

View file

@ -133,6 +133,7 @@ public static void addLauncherClassBindings(Map<String, Object> 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);

View file

@ -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<HashedDir> 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<HashedDir> run() throws Exception;
}
}