diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java index 7938c8821..5fee7c840 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java @@ -7,6 +7,13 @@ import android.view.*; import java.io.*; import net.kdt.pojavlaunch.authenticator.mojang.*; +/** + * This account data format is deprecated. + * The current account data format is JSON on net.kdt.pojavlaunch.value.MinecraftAccount. + * This class remain for account data migrator only. + * Methods for saving/exporting on this format are no longer available. + */ +@Deprecated public class MCProfile { private static String[] emptyBuilder = new String[]{ @@ -17,30 +24,6 @@ public class MCProfile "Steve" }; - public static void launch(Activity ctx, Object o) { - PojavProfile.setCurrentProfile(ctx, o); - - Intent intent = new Intent(ctx, PojavV2ActivityManager.getLauncherRemakeVer(ctx)); //MCLauncherActivity.class); - ctx.startActivity(intent); - } - - public static void updateTokens(final Activity ctx, final String name, RefreshListener listen) throws Exception { - new RefreshTokenTask(ctx, listen).execute(Tools.DIR_ACCOUNT_NEW + "/" + name + ".json"); - } - - public static String build(MCProfile.Builder builder) { - //System.out.println("build THE VER = " + builder.getVersion()); - - try { - byte[] bFull = toString(builder).getBytes("UTF-8"); - Tools.write(Tools.DIR_ACCOUNT_OLD + "/" + builder.getUsername(), bFull); - } catch (IOException e) { - e.printStackTrace(); - } - - return Tools.DIR_ACCOUNT_OLD + "/" + builder.getUsername(); - } - public static MCProfile.Builder load(String pofFilePath) { try { //String th = new String(new byte[]{-128}); @@ -90,20 +73,6 @@ public class MCProfile } } - public static String toString(String pofFilePath) { - return toString(load(pofFilePath)); - } - - public static String toString(MCProfile.Builder builder) { - return - builder.getClientID() + ":" + - builder.getProfileID() + ":" + - builder.getAccessToken() + ":" + - builder.getUsername() + ":" + - builder.getVersion() + ":" + - Boolean.toString(builder.isMojangAccount()); - } - public static class Builder implements Serializable { private String[] fullArgs = new String[6]; 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 55baefb5e..0ab08b74f 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java @@ -717,10 +717,10 @@ public class PojavLoginActivity extends BaseActivity new MicrosoftAuthTask(PojavLoginActivity.this, authListener) .execute("true", acc.msaRefreshToken); } else if (acc.accessToken.length() >= 5) { - MCProfile.updateTokens(PojavLoginActivity.this, selectedAccName, authListener); + PojavProfile.updateTokens(PojavLoginActivity.this, selectedAccName, authListener); } else { di.dismiss(); - MCProfile.launch(PojavLoginActivity.this, selectedAccName); + PojavProfile.launch(PojavLoginActivity.this, selectedAccName); } } catch (Exception e) { Tools.showError(PojavLoginActivity.this, e); @@ -826,7 +826,7 @@ public class PojavLoginActivity extends BaseActivity profileName = mProfile.save(); } - MCProfile.launch(PojavLoginActivity.this, profileName == null ? mProfile : profileName); + PojavProfile.launch(PojavLoginActivity.this, profileName == null ? mProfile : 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 e46822857..126ee1fe2 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavProfile.java @@ -1,8 +1,14 @@ package net.kdt.pojavlaunch; -import java.io.*; -import android.content.*; -import net.kdt.pojavlaunch.value.*; -import com.google.gson.*; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import com.google.gson.JsonSyntaxException; +import java.io.File; +import java.io.IOException; +import net.kdt.pojavlaunch.authenticator.mojang.RefreshListener; +import net.kdt.pojavlaunch.authenticator.mojang.RefreshTokenTask; +import net.kdt.pojavlaunch.value.MinecraftAccount; public class PojavProfile { @@ -26,9 +32,15 @@ public class PojavProfile return MinecraftAccount.parse(getPrefs(ctx).getString(PROFILE_PREF_TEMP_CONTENT, "")); } - public static String getCurrentProfileName(Context ctx) { - return getPrefs(ctx).getString(PROFILE_PREF_FILE, ""); - } + public static String getCurrentProfileName(Context ctx) { + String name = getPrefs(ctx).getString(PROFILE_PREF_FILE, ""); + // A dirty fix + if (!name.isEmpty() && name.startsWith(Tools.DIR_ACCOUNT_NEW) && name.endsWith(".json")) { + name = name.substring(0, name.length() - 5).replace(Tools.DIR_ACCOUNT_NEW, ""); + setCurrentProfile(ctx, name); + } + return name; + } public static boolean setCurrentProfile(Context ctx, Object obj) { SharedPreferences.Editor pref = getPrefs(ctx).edit(); @@ -57,4 +69,16 @@ public class PojavProfile public static boolean isFileType(Context ctx) { return new File(Tools.DIR_ACCOUNT_NEW + "/" + PojavProfile.getCurrentProfileName(ctx) + ".json").exists(); } + + + public static void launch(Activity ctx, Object o) { + PojavProfile.setCurrentProfile(ctx, o); + + Intent intent = new Intent(ctx, PojavV2ActivityManager.getLauncherRemakeVer(ctx)); //MCLauncherActivity.class); + ctx.startActivity(intent); + } + + public static void updateTokens(final Activity ctx, final String name, RefreshListener listen) throws Exception { + new RefreshTokenTask(ctx, listen).execute(Tools.DIR_ACCOUNT_NEW + "/" + name + ".json"); + } }