Fix the temporary account

This commit is contained in:
artdeell 2020-12-30 22:26:39 +03:00
parent be621f7732
commit 472c288721
3 changed files with 58 additions and 21 deletions

View File

@ -809,12 +809,10 @@ public class PojavLoginActivity extends BaseActivity
builder.profileId = result[3]; builder.profileId = result[3];
builder.username = result[4]; builder.username = result[4];
builder.selectedVersion = "1.12.2"; builder.selectedVersion = "1.12.2";
mProfile = builder; mProfile = builder;
} }
v.setEnabled(true); v.setEnabled(true);
prb.setVisibility(View.GONE); prb.setVisibility(View.GONE);
playProfile(false); playProfile(false);
} }
}).execute(edit2.getText().toString(), edit3.getText().toString()); }).execute(edit2.getText().toString(), edit3.getText().toString());

View File

@ -3,6 +3,8 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Log;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -14,22 +16,47 @@ public class PojavProfile
{ {
private static String PROFILE_PREF = "pojav_profile"; private static String PROFILE_PREF = "pojav_profile";
private static String PROFILE_PREF_FILE = "file"; 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); 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)); MinecraftAccount build = MinecraftAccount.load(getCurrentProfileName(ctx));
if (build == null) { if (build == null) {
System.out.println("isTempProfile null? " + (getTempProfileContent(ctx) == null));
return getTempProfileContent(ctx); return getTempProfileContent(ctx);
} }
return build; return build;
} }
public static MinecraftAccount getTempProfileContent(Context ctx) { 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) { public static String getCurrentProfileName(Context ctx) {

View File

@ -1,4 +1,6 @@
package net.kdt.pojavlaunch.value; package net.kdt.pojavlaunch.value;
import android.util.Log;
import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.*;
import java.io.*; import java.io.*;
import com.google.gson.*; import com.google.gson.*;
@ -26,22 +28,32 @@ public class MinecraftAccount
return Tools.GLOBAL_GSON.fromJson(content, MinecraftAccount.class); return Tools.GLOBAL_GSON.fromJson(content, MinecraftAccount.class);
} }
public static MinecraftAccount load(String name) throws IOException, JsonSyntaxException { public static MinecraftAccount load(String name) throws JsonSyntaxException {
MinecraftAccount acc = parse(Tools.read(Tools.DIR_ACCOUNT_NEW + "/" + name + ".json")); try {
if (acc.accessToken == null) { MinecraftAccount acc = parse(Tools.read(Tools.DIR_ACCOUNT_NEW + "/" + name + ".json"));
acc.accessToken = "0"; if (acc.accessToken == null) {
} if (acc.clientToken == null) { acc.accessToken = "0";
acc.clientToken = "0"; }
} if (acc.profileId == null) { if (acc.clientToken == null) {
acc.profileId = "0"; acc.clientToken = "0";
} if (acc.username == null) { }
acc.username = "0"; if (acc.profileId == null) {
} if (acc.selectedVersion == null) { acc.profileId = "0";
acc.selectedVersion = "1.7.10"; }
} if (acc.msaRefreshToken == null) { if (acc.username == null) {
acc.msaRefreshToken = "0"; 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() { public static void clearTempAccount() {