mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Портирован UpdateListRequest
This commit is contained in:
parent
b5d2f47cf8
commit
ec7e64fdf4
4 changed files with 33 additions and 13 deletions
|
@ -4,13 +4,17 @@
|
|||
import ru.gravit.launcher.events.request.ErrorRequestEvent;
|
||||
import ru.gravit.launcher.events.request.UpdateListRequestEvent;
|
||||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class UpdateListResponse implements JsonResponseInterface {
|
||||
public String dir;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
|
@ -23,8 +27,10 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||
return;
|
||||
}
|
||||
HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object;
|
||||
service.sendObject(ctx, new UpdateListRequestEvent(hdir));
|
||||
HashSet<String> set = new HashSet<>();
|
||||
for(Map.Entry<String, SignedObjectHolder<HashedDir>> entry : LaunchServer.server.updatesDirMap.entrySet())
|
||||
set.add(entry.getKey());
|
||||
service.sendObject(ctx, new UpdateListRequestEvent(set));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
import ru.gravit.launcher.LauncherConfig;
|
||||
import ru.gravit.launcher.events.request.UpdateListRequestEvent;
|
||||
import ru.gravit.launcher.request.Request;
|
||||
import ru.gravit.launcher.request.RequestType;
|
||||
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.utils.helper.IOHelper;
|
||||
|
@ -13,7 +16,7 @@
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class UpdateListRequest extends Request<Set<String>> {
|
||||
public final class UpdateListRequest extends Request<UpdateListRequestEvent> implements RequestInterface {
|
||||
@LauncherAPI
|
||||
public UpdateListRequest() {
|
||||
this(null);
|
||||
|
@ -24,21 +27,32 @@ public UpdateListRequest(LauncherConfig config) {
|
|||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateListRequestEvent requestWebSockets() throws Exception
|
||||
{
|
||||
return (UpdateListRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getLegacyType() {
|
||||
return RequestType.UPDATE_LIST.getNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> requestDo(HInput input, HOutput output) throws IOException {
|
||||
protected UpdateListRequestEvent requestDo(HInput input, HOutput output) throws IOException {
|
||||
int count = input.readLength(0);
|
||||
|
||||
// Read all update dirs names
|
||||
Set<String> result = new HashSet<>(count);
|
||||
HashSet<String> result = new HashSet<>(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
result.add(IOHelper.verifyFileName(input.readString(255)));
|
||||
|
||||
// We're done. Make it unmodifiable and return
|
||||
return Collections.unmodifiableSet(result);
|
||||
return new UpdateListRequestEvent(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "updateList";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ public void registerResults() {
|
|||
registerResult("profileByUUID", ProfileByUUIDRequestEvent.class);
|
||||
registerResult("batchProfileByUsername", BatchProfileByUsernameRequestEvent.class);
|
||||
registerResult("profiles", ProfilesRequestEvent.class);
|
||||
registerResult("setProfile", SetProfileRequestEvent.class);
|
||||
registerResult("updateList", UpdateListRequestEvent.class);
|
||||
registerResult("error", ErrorRequestEvent.class);
|
||||
}
|
||||
|
|
|
@ -5,18 +5,17 @@
|
|||
import ru.gravit.launcher.request.ResultInterface;
|
||||
import ru.gravit.utils.event.EventInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UpdateListRequestEvent implements EventInterface, ResultInterface {
|
||||
private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b");
|
||||
@LauncherNetworkAPI
|
||||
public final String type;
|
||||
@LauncherNetworkAPI
|
||||
public final HashedDir dir;
|
||||
public final HashSet<String> dirs;
|
||||
|
||||
public UpdateListRequestEvent(HashedDir dir) {
|
||||
this.dir = dir;
|
||||
type = "success";
|
||||
public UpdateListRequestEvent(HashSet<String> dirs) {
|
||||
this.dirs = dirs;
|
||||
}
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
|
|
Loading…
Reference in a new issue