From 472c2887211c96464cdadcdc61a9040ef9d324bd Mon Sep 17 00:00:00 2001 From: artdeell Date: Wed, 30 Dec 2020 22:26:39 +0300 Subject: [PATCH] Fix the temporary account --- .../kdt/pojavlaunch/PojavLoginActivity.java | 2 - .../net/kdt/pojavlaunch/PojavProfile.java | 35 ++++++++++++++-- .../pojavlaunch/value/MinecraftAccount.java | 42 ++++++++++++------- 3 files changed, 58 insertions(+), 21 deletions(-) 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 e6ad0b23a..3b66ee546 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java @@ -809,12 +809,10 @@ public class PojavLoginActivity extends BaseActivity builder.profileId = result[3]; builder.username = result[4]; builder.selectedVersion = "1.12.2"; - mProfile = builder; } v.setEnabled(true); prb.setVisibility(View.GONE); - playProfile(false); } }).execute(edit2.getText().toString(), edit3.getText().toString()); 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 20fc4ea0e..8b5fc9468 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java @@ -3,6 +3,8 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.util.Log; + import com.google.gson.JsonSyntaxException; import java.io.File; import java.io.IOException; @@ -14,22 +16,47 @@ public class PojavProfile { private static String PROFILE_PREF = "pojav_profile"; private static String PROFILE_PREF_FILE = "file"; - private static String PROFILE_PREF_TEMP_CONTENT = "tempContent"; + public static String PROFILE_PREF_TEMP_CONTENT = "tempContent"; - private static SharedPreferences getPrefs(Context ctx) { + public static SharedPreferences getPrefs(Context ctx) { return ctx.getSharedPreferences(PROFILE_PREF, Context.MODE_PRIVATE); } - public static MinecraftAccount getCurrentProfileContent(Context ctx) throws IOException, JsonSyntaxException { + public static MinecraftAccount getCurrentProfileContent(Context ctx) throws JsonSyntaxException { MinecraftAccount build = MinecraftAccount.load(getCurrentProfileName(ctx)); if (build == null) { + System.out.println("isTempProfile null? " + (getTempProfileContent(ctx) == null)); return getTempProfileContent(ctx); } return build; } public static MinecraftAccount getTempProfileContent(Context ctx) { - return MinecraftAccount.parse(getPrefs(ctx).getString(PROFILE_PREF_TEMP_CONTENT, "")); + try { + MinecraftAccount acc = MinecraftAccount.parse(Tools.read(Tools.DIR_DATA+"/cache/tempacc.json")); + if (acc.accessToken == null) { + acc.accessToken = "0"; + } + if (acc.clientToken == null) { + acc.clientToken = "0"; + } + if (acc.profileId == null) { + acc.profileId = "0"; + } + if (acc.username == null) { + acc.username = "0"; + } + if (acc.selectedVersion == null) { + acc.selectedVersion = "1.7.10"; + } + if (acc.msaRefreshToken == null) { + acc.msaRefreshToken = "0"; + } + return acc; + }catch (IOException e) { + Log.e(MinecraftAccount.class.getName(), "Caught an exception while loading the temporary profile",e); + return null; + } } public static String getCurrentProfileName(Context ctx) { 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 8c4f3e6b2..cfa7c741b 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 @@ -1,4 +1,6 @@ package net.kdt.pojavlaunch.value; +import android.util.Log; + import net.kdt.pojavlaunch.*; import java.io.*; import com.google.gson.*; @@ -26,22 +28,32 @@ public class MinecraftAccount return Tools.GLOBAL_GSON.fromJson(content, MinecraftAccount.class); } - public static MinecraftAccount load(String name) throws IOException, JsonSyntaxException { - MinecraftAccount acc = parse(Tools.read(Tools.DIR_ACCOUNT_NEW + "/" + name + ".json")); - if (acc.accessToken == null) { - acc.accessToken = "0"; - } if (acc.clientToken == null) { - acc.clientToken = "0"; - } if (acc.profileId == null) { - acc.profileId = "0"; - } if (acc.username == null) { - acc.username = "0"; - } if (acc.selectedVersion == null) { - acc.selectedVersion = "1.7.10"; - } if (acc.msaRefreshToken == null) { - acc.msaRefreshToken = "0"; + public static MinecraftAccount load(String name) throws JsonSyntaxException { + try { + MinecraftAccount acc = parse(Tools.read(Tools.DIR_ACCOUNT_NEW + "/" + name + ".json")); + if (acc.accessToken == null) { + acc.accessToken = "0"; + } + if (acc.clientToken == null) { + acc.clientToken = "0"; + } + if (acc.profileId == null) { + acc.profileId = "0"; + } + if (acc.username == null) { + acc.username = "0"; + } + if (acc.selectedVersion == null) { + acc.selectedVersion = "1.7.10"; + } + if (acc.msaRefreshToken == null) { + acc.msaRefreshToken = "0"; + } + return acc; + }catch(IOException e) { + Log.e(MinecraftAccount.class.getName(), "Caught an exception while loading the profile",e); + return null; } - return acc; } public static void clearTempAccount() {