Skip to content

Commit

Permalink
Fix auto update, add delay to auto accept and change chart library fo…
Browse files Browse the repository at this point in the history
…r performance monitor
  • Loading branch information
stirante committed Apr 2, 2020
1 parent d3a402d commit 78151b2
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 243 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/stirante/runechanger/RuneChanger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/stirante/runechanger/client/Matchmaking.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/com/stirante/runechanger/util/AutoUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -238,4 +240,29 @@ public static void checkUpdate() {
log.error("Exception occurred while checking for update", ex);
}
}

public static void deleteOldLibs() {
try {
ArrayList<String> 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();
}

}
}
Loading

0 comments on commit 78151b2

Please sign in to comment.