From 78151b2b3ec84efc20e633677f0a173a639dcf24 Mon Sep 17 00:00:00 2001 From: Piotr Brzozowski Date: Thu, 2 Apr 2020 15:54:23 +0200 Subject: [PATCH] Fix auto update, add delay to auto accept and change chart library for performance monitor --- .../com/stirante/runechanger/RuneChanger.java | 1 + .../runechanger/client/Matchmaking.java | 24 +- .../runechanger/util/AutoUpdater.java | 29 +- src/main/resources/perfmon.html | 338 ++++++------------ 4 files changed, 149 insertions(+), 243 deletions(-) diff --git a/src/main/java/com/stirante/runechanger/RuneChanger.java b/src/main/java/com/stirante/runechanger/RuneChanger.java index 8bae03c..1f52915 100644 --- a/src/main/java/com/stirante/runechanger/RuneChanger.java +++ b/src/main/java/com/stirante/runechanger/RuneChanger.java @@ -409,6 +409,7 @@ public Matchmaking getMatchmakingModule() { @Override public void run(LaunchContext context) { try { + AutoUpdater.deleteOldLibs(); Runtime.getRuntime().exec("wscript silent.vbs open.bat"); System.exit(0); } catch (IOException e) { diff --git a/src/main/java/com/stirante/runechanger/client/Matchmaking.java b/src/main/java/com/stirante/runechanger/client/Matchmaking.java index 1f1c74f..fe0de5a 100644 --- a/src/main/java/com/stirante/runechanger/client/Matchmaking.java +++ b/src/main/java/com/stirante/runechanger/client/Matchmaking.java @@ -1,14 +1,12 @@ package com.stirante.runechanger.client; +import com.stirante.eventbus.AsyncEventExecutor; import com.stirante.eventbus.EventBus; import com.stirante.eventbus.Subscribe; import com.stirante.lolclient.ClientApi; import com.stirante.runechanger.RuneChanger; import com.stirante.runechanger.util.SimplePreferences; -import generated.LolLobbyLobby; -import generated.LolLobbyLobbyMatchmakingSearchState; -import generated.LolMatchmakingMatchmakingDodgeState; -import generated.LolMatchmakingMatchmakingSearchResource; +import generated.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,12 +52,26 @@ public void onMatchmakingSearch(ClientEventListener.MatchmakingSearchEvent event } } - @Subscribe(ClientEventListener.MatchmakingSearchStateEvent.NAME) + @Subscribe(value = ClientEventListener.MatchmakingSearchStateEvent.NAME, eventExecutor = AsyncEventExecutor.class) public void onMatchmakingSearchState(ClientEventListener.MatchmakingSearchStateEvent event) { if (SimplePreferences.getBooleanValue(SimplePreferences.SettingsKeys.AUTO_ACCEPT, false)) { if (event.getData().searchState == LolLobbyLobbyMatchmakingSearchState.FOUND) { + log.info("Found match, waiting 3 seconds and accepting"); try { - getApi().executePost("/lol-matchmaking/v1/ready-check/accept"); + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + LolMatchmakingMatchmakingReadyCheckResource state = + getApi().executeGet("/lol-matchmaking/v1/ready-check", LolMatchmakingMatchmakingReadyCheckResource.class); + if (state.state == LolMatchmakingMatchmakingReadyCheckState.INPROGRESS) { + log.info("Accepting queue"); + getApi().executePost("/lol-matchmaking/v1/ready-check/accept"); + } + else { + log.info("Not accepting queue, because it's already accepted"); + } } catch (IOException e) { log.error("Exception occurred while autoaccepting", e); } diff --git a/src/main/java/com/stirante/runechanger/util/AutoUpdater.java b/src/main/java/com/stirante/runechanger/util/AutoUpdater.java index 125eb4c..fee1146 100644 --- a/src/main/java/com/stirante/runechanger/util/AutoUpdater.java +++ b/src/main/java/com/stirante/runechanger/util/AutoUpdater.java @@ -13,6 +13,7 @@ import java.net.URL; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -21,6 +22,7 @@ public class AutoUpdater { private static final String DEV_UPDATE_CONFIG = "https://runechanger.stirante.com/dev/dev.xml"; private static final String STABLE_UPDATE_CONFIG = "https://runechanger.stirante.com/stable/stable.xml"; private static final int BUFFER_SIZE = 4096; + public static final String LOCAL_UPDATE_CONFIG = "update.xml"; private static Configuration configuration = null; public static void resetCache() { @@ -73,7 +75,7 @@ public static String humanReadableByteCountSI(long bytes) { public static void performUpdate() { try { copyDir(new File("image").toPath(), new File("updateImage").toPath()); - FileWriter writer = new FileWriter("update.xml"); + FileWriter writer = new FileWriter(LOCAL_UPDATE_CONFIG); getConfiguration().write(writer); writer.flush(); writer.close(); @@ -238,4 +240,29 @@ public static void checkUpdate() { log.error("Exception occurred while checking for update", ex); } } + + public static void deleteOldLibs() { + try { + ArrayList acceptableLibs = new ArrayList<>(); + Reader reader = new InputStreamReader(new FileInputStream(LOCAL_UPDATE_CONFIG)); + Configuration configuration = Configuration.read(reader); + reader.close(); + for (FileMetadata file : configuration.getFiles()) { + if (file.getPath().startsWith("lib")) { + acceptableLibs.add(file.getPath().getFileName().toString()); + } + } + File[] libs = new File("lib").listFiles(); + if (libs != null) { + for (File lib : libs) { + if (!acceptableLibs.contains(lib.getName())) { + lib.deleteOnExit(); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + } } \ No newline at end of file diff --git a/src/main/resources/perfmon.html b/src/main/resources/perfmon.html index c25b190..3481723 100644 --- a/src/main/resources/perfmon.html +++ b/src/main/resources/perfmon.html @@ -11388,7 +11388,8 @@

Performance data

CPU
-
Intel® Core™ i7-7700 CPU @ 3.60GHz +
Intel® Core™ i7-7700 CPU + @ 3.60GHz
@@ -11421,7 +11422,9 @@

Performance data

GPU
-
NVIDIA GeForce GTX 1050 Ti
+
NVIDIA GeForce GTX 1050 + Ti +
@@ -11438,8 +11441,7 @@

Performance data

CPU usage
-
- +
@@ -11452,8 +11454,7 @@
CPU usage
Memory usage
-
- +
@@ -11461,9 +11462,8 @@
Memory usage
- - - + + @@ -11478,10 +11478,7 @@
Memory usage