mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-21 09:01:56 -07:00
[Account loader] A dirty fix, might resolves #534
This commit is contained in:
parent
9f7f2fb62d
commit
3231ddce64
3 changed files with 41 additions and 48 deletions
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -27,7 +33,13 @@ public class PojavProfile
|
|||
}
|
||||
|
||||
public static String getCurrentProfileName(Context ctx) {
|
||||
return getPrefs(ctx).getString(PROFILE_PREF_FILE, "");
|
||||
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) {
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue