From 0020c4deb280f75441f087952ab40a773044790d Mon Sep 17 00:00:00 2001 From: artdeell Date: Sun, 4 Jul 2021 14:59:44 +0300 Subject: [PATCH] Remove the Thread.sleep in BaseMainActivity, make MCOptionUtils use ArrayMap instead of List --- .../net/kdt/pojavlaunch/BaseMainActivity.java | 1 - .../kdt/pojavlaunch/utils/MCOptionUtils.java | 43 +++++++------------ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java index 285d1be75..6265794ed 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java @@ -1230,7 +1230,6 @@ public class BaseMainActivity extends LoggableActivity { public void getMcScale() { //Get the scale stored in game files, used auto scale if found or if the stored scaled is bigger than the authorized size. MCOptionUtils.load(); - try { Thread.sleep(200); } catch (Throwable th) {} String str = MCOptionUtils.get("guiScale"); this.guiScale = (str == null ? 0 :Integer.parseInt(str)); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java index f0ecdd792..cd3d4ccb4 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java @@ -1,22 +1,25 @@ package net.kdt.pojavlaunch.utils; - -import java.util.*; import java.io.*; import android.util.*; import net.kdt.pojavlaunch.*; public class MCOptionUtils { - private static final List mLineList = Collections.synchronizedList(new ArrayList<>()); + private static final ArrayMap parameterMap = new ArrayMap<>(); public static void load() { - mLineList.clear(); - + parameterMap.clear(); + try { BufferedReader reader = new BufferedReader(new FileReader(Tools.DIR_GAME_NEW + "/options.txt")); String line; while ((line = reader.readLine()) != null) { - mLineList.add(line); + int firstColonIndex = line.indexOf(':'); + if(firstColonIndex < 0) { + Log.w(Tools.APP_NAME, "No colon on line \""+line+"\", skipping"); + continue; + } + parameterMap.put(line.substring(0,firstColonIndex), line.substring(firstColonIndex+1)); } reader.close(); } catch (IOException e) { @@ -25,34 +28,20 @@ public class MCOptionUtils } public static void set(String key, String value) { - for (int i = 0; i < mLineList.size(); i++) { - String line = mLineList.get(i); - if (line.startsWith(key + ":")) { - mLineList.set(i, key + ":" + value); - return; - } - } - - mLineList.add(key + ":" + value); + parameterMap.put(key,value); } public static String get(String key){ - if(mLineList.isEmpty()) load(); - String searchedLine=null; - for(String line : mLineList){ - if(line.startsWith(key + ":")) { - searchedLine = line; - break; - } - } - if(searchedLine != null) return searchedLine.substring(searchedLine.indexOf(':') + 1); - else return null; + return parameterMap.get(key); } public static void save() { StringBuilder result = new StringBuilder(); - for(String line : mLineList) - result.append(line).append('\n'); + for(String key : parameterMap.keySet()) + result.append(key) + .append(':') + .append(parameterMap.get(key)) + .append('\n'); try { Tools.write(Tools.DIR_GAME_NEW + "/options.txt", result.toString());