mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
FunctionalBridge
This commit is contained in:
parent
e4c1a8ce96
commit
bc62dc3416
4 changed files with 31 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue