[FIX] Исправление рантайма для UpdateResponse

This commit is contained in:
Gravit 2019-02-20 17:11:42 +07:00
parent bcedb95eec
commit 57fc3b1c04
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 22 additions and 17 deletions

View file

@ -237,7 +237,7 @@ var digest = profile.isUpdateFastCheck();
makeSetProfileRequest(profile, function() {
ClientLauncher.setProfile(profile);
makeUpdateRequest(assetDirName, assetDir, assetMatcher, digest, function(assetHDir) {
settings.lastHDirs.put(assetDirName, assetHDir);
settings.lastHDirs.put(assetDirName, assetHDir.hdir);
// Update client dir
update.resetOverlay("Обновление файлов клиента");
@ -245,7 +245,7 @@ var digest = profile.isUpdateFastCheck();
var clientDir = settings.updatesDir.resolve(clientDirName);
var clientMatcher = profile.getClientUpdateMatcher();
makeUpdateRequest(clientDirName, clientDir, clientMatcher, digest, function(clientHDir) {
settings.lastHDirs.put(clientDirName, clientHDir);
settings.lastHDirs.put(clientDirName, clientHDir.hdir);
doLaunchClient(assetDir, assetHDir, clientDir, clientHDir, profile, pp, accessToken);
});
});

View file

@ -46,7 +46,7 @@ public class LauncherSettings {
@LauncherAPI
public List<ClientProfile> lastProfiles = new LinkedList<>();
@LauncherAPI
public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16);
public Map<String, HashedDir> lastHDirs = new HashMap<>(16);
@LauncherAPI
public void load() throws SignatureException {
@ -103,7 +103,6 @@ public void read(HInput input) throws IOException, SignatureException {
setRAM(input.readLength(JVMHelper.RAM));
// Offline cache
RSAPublicKey publicKey = Launcher.getConfig().publicKey;
lastDigest = input.readBoolean() ? input.readByteArray(0) : null;
lastProfiles.clear();
int lastProfilesCount = input.readLength(0);
@ -114,8 +113,6 @@ public void read(HInput input) throws IOException, SignatureException {
int lastHDirsCount = input.readLength(0);
for (int i = 0; i < lastHDirsCount; i++) {
String name = IOHelper.verifyFileName(input.readString(255));
VerifyHelper.putIfAbsent(lastHDirs, name, new SignedObjectHolder<>(input, publicKey, HashedDir::new),
java.lang.String.format("Duplicate offline hashed dir: '%s'", name));
}
}
@ -153,7 +150,7 @@ public void write(HOutput output) throws IOException {
output.writeString(Launcher.gson.toJson(profile), 0);
}
output.writeLength(lastHDirs.size(), 0);
for (Map.Entry<String, SignedObjectHolder<HashedDir>> entry : lastHDirs.entrySet()) {
for (Map.Entry<String, HashedDir> entry : lastHDirs.entrySet()) {
output.writeString(entry.getKey(), 0);
entry.getValue().write(output);
}

View file

@ -3,6 +3,7 @@
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.UpdateRequestEvent;
import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.hasher.HashedEntry;
@ -11,6 +12,8 @@
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.UpdateAction;
import ru.gravit.launcher.request.update.UpdateRequest.State.Callback;
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -35,7 +38,12 @@
import java.util.Queue;
import java.util.zip.InflaterInputStream;
public final class UpdateRequest extends Request<SignedObjectHolder<HashedDir>> {
public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
@Override
public String getType() {
return "update";
}
public static final class State {
@FunctionalInterface
@ -189,6 +197,11 @@ private static void fillActionsQueue(Queue<UpdateAction> queue, HashedDir mismat
}
}
}
@Override
public UpdateRequestEvent requestWebSockets() throws Exception
{
return (UpdateRequestEvent) LegacyRequestBridge.sendRequest(this);
}
// Instance
private final String dirName;
@ -290,16 +303,9 @@ public Integer getLegacyType() {
}
@Override
public SignedObjectHolder<HashedDir> request() throws Exception {
protected UpdateRequestEvent requestDo(HInput input, HOutput output) throws IOException, SignatureException {
Files.createDirectories(dir);
localDir = new HashedDir(dir, matcher, false, digest);
// Start request
return super.request();
}
@Override
protected SignedObjectHolder<HashedDir> requestDo(HInput input, HOutput output) throws IOException, SignatureException {
// Write update dir name
output.writeString(dirName, 255);
output.flush();
@ -365,7 +371,7 @@ protected SignedObjectHolder<HashedDir> requestDo(HInput input, HOutput output)
// Write update completed packet
deleteExtraDir(dir, diff.extra, diff.extra.flag);
return remoteHDirHolder;
return new UpdateRequestEvent(remoteHDirHolder.object);
}
@LauncherAPI

View file

@ -1,9 +1,11 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.LauncherNetworkAPI;
import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.request.ResultInterface;
public class UpdateRequestEvent implements ResultInterface {
@LauncherNetworkAPI
public HashedDir hdir;
@Override
public String getType() {