From 631f84ab17f4cbe6a260817b79c58cabd73e99ff Mon Sep 17 00:00:00 2001 From: Boulay Mathias Date: Thu, 3 Nov 2022 22:27:59 +0100 Subject: [PATCH] Workaround: Remove the temp account system Note: The newer system won't need it. It still displays an error on first login. --- .../pojavlaunch/PojavLauncherActivity.java | 26 ++++++------------- .../kdt/pojavlaunch/PojavLoginActivity.java | 2 +- .../net/kdt/pojavlaunch/PojavProfile.java | 20 +++++--------- .../pojavlaunch/value/MinecraftAccount.java | 11 -------- 4 files changed, 15 insertions(+), 44 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java index aa4078840..a6a1b0e10 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java @@ -145,10 +145,7 @@ public class PojavLauncherActivity extends BaseLauncherActivity // Try to load the temporary account final List accountList = new ArrayList<>(); - final MinecraftAccount tempProfile = PojavProfile.getTempProfileContent(); - if (tempProfile != null) { - accountList.add(tempProfile.username); - } + for (String s : new File(Tools.DIR_ACCOUNT_NEW).list()) { accountList.add(s.substring(0, s.length() - 5)); } @@ -159,26 +156,19 @@ public class PojavLauncherActivity extends BaseLauncherActivity adapterAcc.setDropDownViewResource(android.R.layout.simple_list_item_single_choice); accountSelector.setAdapter(adapterAcc); - if (tempProfile != null) { - accountSelector.setSelection(0); - } else { - for (int i = 0; i < accountList.size(); i++) { - String account = accountList.get(i); - if (account.equals(mProfile.username)) { - accountSelector.setSelection(i); - } + for (int i = 0; i < accountList.size(); i++) { + String account = accountList.get(i); + if (account.equals(mProfile.username)) { + accountSelector.setSelection(i); } } + accountSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){ @Override public void onItemSelected(AdapterView p1, View p2, int position, long p4) { - if (tempProfile != null && position == 0) { - PojavProfile.setCurrentProfile(PojavLauncherActivity.this, tempProfile); - } else { - PojavProfile.setCurrentProfile(PojavLauncherActivity.this, - accountList.get(position + (tempProfile != null ? 1 : 0))); - } + PojavProfile.setCurrentProfile(PojavLauncherActivity.this, accountList.get(position)); + pickAccount(); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java index 4f975f667..02286fadb 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java @@ -696,7 +696,7 @@ public class PojavLoginActivity extends BaseActivity { profileName = mProfile.save(); } - PojavProfile.launch(PojavLoginActivity.this, profileName == null ? mProfile : profileName); + PojavProfile.launch(PojavLoginActivity.this, profileName); } catch (IOException e) { Tools.showError(this, e); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java index 2561b69ba..b2c93c691 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java @@ -11,7 +11,6 @@ import androidx.annotation.Nullable; import com.google.gson.JsonSyntaxException; import java.io.File; import java.io.IOException; -import java.util.UUID; import net.kdt.pojavlaunch.authenticator.mojang.RefreshListener; import net.kdt.pojavlaunch.authenticator.mojang.RefreshTokenTask; @@ -70,24 +69,17 @@ public class PojavProfile { return name; } - public static boolean setCurrentProfile(Context ctx, Object obj) { + public static boolean setCurrentProfile(@NonNull Context ctx, @Nullable Object obj) { SharedPreferences.Editor pref = getPrefs(ctx).edit(); - try { - if (obj instanceof MinecraftAccount) { - try { - MinecraftAccount.saveTempAccount((MinecraftAccount) obj); - } catch (IOException e) { - Tools.showError(ctx, e); - } - } else if (obj instanceof String) { + try { if (obj instanceof String) { String acc = (String) obj; pref.putString(PROFILE_PREF_FILE, acc); - MinecraftAccount.clearTempAccount(); + //MinecraftAccount.clearTempAccount(); } else if (obj == null) { pref.putString(PROFILE_PREF_FILE, ""); } else { - throw new IllegalArgumentException("Profile must be MinecraftAccount.class, String.class or null"); + throw new IllegalArgumentException("Profile must be String.class or null"); } } finally { return pref.commit(); @@ -99,8 +91,8 @@ public class PojavProfile { } - public static void launch(Activity ctx, Object o) { - PojavProfile.setCurrentProfile(ctx, o); + public static void launch(Activity ctx, String accountName) { + PojavProfile.setCurrentProfile(ctx, accountName); LauncherProfiles.update(); if(!LauncherProfiles.mainProfileJson.profilesWereMigrated && LauncherProfiles.mainProfileJson.profiles != null) { MinecraftProfile defaultProfile = LauncherProfiles.mainProfileJson.profiles.get("(Default)"); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/MinecraftAccount.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/MinecraftAccount.java index f3a66d86b..9f0c3b12c 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/MinecraftAccount.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/MinecraftAccount.java @@ -100,15 +100,4 @@ public class MinecraftAccount { private static boolean accountExists(String username){ return new File(Tools.DIR_ACCOUNT_NEW + "/" + username + ".json").exists(); } - - public static void clearTempAccount() { - File tempAccFile = new File(Tools.DIR_DATA, "cache/tempacc.json"); - tempAccFile.delete(); - } - - public static void saveTempAccount(MinecraftAccount acc) throws IOException { - File tempAccFile = new File(Tools.DIR_DATA, "cache/tempacc.json"); - tempAccFile.delete(); - acc.save(tempAccFile.getAbsolutePath()); - } }