Fix compile errors
This commit is contained in:
1 parent
ea5c31f20f
commit
968a945b65
9 files changed
+110
-157
No files matched your search
@@ -0,0 +1,6 @@
|
||||
/** Automatically generated file. DO NOT MODIFY */
|
||||
package ;
|
||||
|
||||
public final class BuildConfig {
|
||||
public final static boolean DEBUG = true;
|
||||
}
|
||||
@@ -9,17 +9,7 @@ import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||
|
||||
public class PojavProfile
|
||||
{
|
||||
private static final File currAccFile;
|
||||
static {
|
||||
try {
|
||||
File currAccFile = new File(Tools.DIR_APP_DATA, "curr_account.txt");
|
||||
currAccFile.getParentFile().mkdir();
|
||||
// currAccFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public static MinecraftAccount getCurrentProfileContent() throws IOException, JsonSyntaxException {
|
||||
MinecraftAccount build = MinecraftAccount.load(getCurrentProfileName());
|
||||
if (build == null) {
|
||||
@@ -27,11 +17,11 @@ public class PojavProfile
|
||||
}
|
||||
return MinecraftAccount.load(getCurrentProfileName());
|
||||
}
|
||||
/*
|
||||
|
||||
public static MinecraftAccount getTempProfileContent(Context ctx) {
|
||||
return MinecraftAccount.parse(getPrefs(ctx).getString(PROFILE_PREF_TEMP_CONTENT, ""));
|
||||
}
|
||||
*/
|
||||
|
||||
public static String getCurrentProfileName() {
|
||||
String name = "";
|
||||
try {
|
||||
@@ -42,41 +32,35 @@ public class PojavProfile
|
||||
// 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, "").replace(".json", "");
|
||||
setCurrentProfile(ctx, name);
|
||||
setCurrentProfile(name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public static boolean setCurrentProfile(Object obj) {
|
||||
try {
|
||||
if (obj instanceof MinecraftAccount) {
|
||||
/*
|
||||
try {
|
||||
MinecraftAccount.saveTempAccount((MinecraftAccount) obj);
|
||||
} catch (IOException e) {
|
||||
Tools.showError(ctx, e);
|
||||
}
|
||||
*/
|
||||
throw new UnsupportedOperationException("Temp account is not supported yet");
|
||||
} else if (obj instanceof String) {
|
||||
String acc = (String) obj;
|
||||
Tools.write(currAccFile.getAbsolutePath(), acc);
|
||||
MinecraftAccount.clearTempAccount();
|
||||
} else if (obj == null) {
|
||||
pref.putString(PROFILE_PREF_FILE, "");
|
||||
// pref.putString(PROFILE_PREF_FILE, "");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Profile must be MinecraftAccount.class, String.class or null");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isFileType() {
|
||||
return new File(Tools.DIR_ACCOUNT_NEW + "/" + getCurrentProfileName() + ".json").exists();
|
||||
}
|
||||
|
||||
public static void updateTokens(final String name, RefreshListener listen) throws Exception {
|
||||
new RefreshTokenTask(listen).run(name);
|
||||
*/
|
||||
public static void updateTokens(final String name) throws Throwable {
|
||||
new RefreshTokenTask().run(name);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,41 @@
|
||||
package net.kdt.pojavlaunch;
|
||||
|
||||
import android.util.*;
|
||||
import com.google.gson.*;
|
||||
import com.oracle.dalvik.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import net.kdt.pojavlaunch.utils.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
import android.util.ArrayMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
import net.kdt.pojavlaunch.uikit.UIKit;
|
||||
import net.kdt.pojavlaunch.utils.DownloadUtils;
|
||||
import net.kdt.pojavlaunch.utils.JSONUtils;
|
||||
import net.kdt.pojavlaunch.value.DependentLibrary;
|
||||
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
/*
|
||||
import org.robovm.apple.foundation.*;
|
||||
import org.robovm.apple.uikit.*;
|
||||
|
||||
+5
-11
@@ -14,18 +14,12 @@ public class InvalidateTokenTask {
|
||||
private MinecraftAccount profilePath;
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public Throwable run(String name) {
|
||||
public void run(String name) throws Throwable {
|
||||
this.name = name;
|
||||
try {
|
||||
this.profilePath = MinecraftAccount.load(name);
|
||||
this.authenticator.invalidate(profilePath.accessToken,
|
||||
UUID.fromString(profilePath.isMicrosoft ? profilePath.profileId : profilePath.clientToken /* should be? */));
|
||||
new File(Tools.DIR_ACCOUNT_NEW, name + ".json").delete();
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
return e;
|
||||
}
|
||||
this.profilePath = MinecraftAccount.load(name);
|
||||
this.authenticator.invalidate(profilePath.accessToken,
|
||||
UUID.fromString(profilePath.isMicrosoft ? profilePath.profileId : profilePath.clientToken /* should be? */));
|
||||
new File(Tools.DIR_ACCOUNT_NEW, name + ".json").delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package net.kdt.pojavlaunch.authenticator.mojang;
|
||||
|
||||
public interface LoginListener
|
||||
{
|
||||
public void onBeforeLogin();
|
||||
public void onLoginDone(String[] result);
|
||||
}
|
||||
@@ -1,56 +1,36 @@
|
||||
package net.kdt.pojavlaunch.authenticator.mojang;
|
||||
|
||||
import android.os.*;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.yggdrasil.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.yggdrasil.AuthenticateResponse;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.yggdrasil.YggdrasilAuthenticator;
|
||||
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||
|
||||
public class LoginTask {
|
||||
private YggdrasilAuthenticator authenticator = new YggdrasilAuthenticator();
|
||||
//private String TAG = "MojangAuth-login";
|
||||
private LoginListener listener;
|
||||
|
||||
private UUID getRandomUUID() {
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
listener.onBeforeLogin();
|
||||
|
||||
super.onPreExecute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] run(String username, String password) {
|
||||
ArrayList<String> str = new ArrayList<String>();
|
||||
str.add("ERROR");
|
||||
try{
|
||||
try{
|
||||
AuthenticateResponse response = authenticator.authenticate(username, password, getRandomUUID());
|
||||
if (response.selectedProfile == null) {
|
||||
str.add("Can't login a demo account!\n");
|
||||
} else {
|
||||
if (new File(Tools.DIR_ACCOUNT_NEW + "/" + response.selectedProfile.name + ".json").exists()) {
|
||||
str.add("This account already exist!\n");
|
||||
} else {
|
||||
str.add(response.accessToken); // Access token
|
||||
str.add(response.clientToken.toString()); // Client token
|
||||
str.add(response.selectedProfile.id); // Profile ID
|
||||
str.add(response.selectedProfile.name); // Username
|
||||
str.set(0, "NORMAL");
|
||||
}
|
||||
}
|
||||
}
|
||||
//MainActivity.updateStatus(804);
|
||||
catch(Throwable e){
|
||||
str.add(e.getMessage());
|
||||
public MinecraftAccount run(String username, String password) throws Throwable {
|
||||
AuthenticateResponse response = authenticator.authenticate(username, password, getRandomUUID());
|
||||
if (response.selectedProfile == null) {
|
||||
throw new IllegalArgumentException("Can't login a demo account!\n");
|
||||
} else {
|
||||
if (new File(Tools.DIR_ACCOUNT_NEW + "/" + response.selectedProfile.name + ".json").exists()) {
|
||||
throw new IllegalArgumentException("This account already exist!\n");
|
||||
} else {
|
||||
MinecraftAccount acc = new MinecraftAccount();
|
||||
acc.accessToken = response.accessToken;
|
||||
acc.clientToken = response.clientToken.toString();
|
||||
acc.profileId = response.selectedProfile.id;
|
||||
acc.username = response.selectedProfile.name;
|
||||
acc.save();
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
str.add(e.getMessage());
|
||||
}
|
||||
return str.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package net.kdt.pojavlaunch.authenticator.mojang;
|
||||
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
|
||||
public interface RefreshListener
|
||||
{
|
||||
public void onFailed(Throwable e);
|
||||
public void onSuccess(MinecraftAccount profile);
|
||||
}
|
||||
+21
-26
@@ -5,38 +5,33 @@ import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.yggdrasil.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class RefreshTokenTask {
|
||||
private YggdrasilAuthenticator authenticator = new YggdrasilAuthenticator();
|
||||
private MinecraftAccount profilePath;
|
||||
|
||||
@Override
|
||||
public Throwable run(String name) {
|
||||
try {
|
||||
this.profilePath = MinecraftAccount.load(name);
|
||||
int responseCode = 400;
|
||||
responseCode = this.authenticator.validate(profilePath.accessToken).statusCode;
|
||||
if (responseCode >= 200 && responseCode < 300) {
|
||||
RefreshResponse response = this.authenticator.refresh(profilePath.accessToken, UUID.fromString(profilePath.clientToken));
|
||||
// if (response == null) {
|
||||
// throw new NullPointerException("Response is null?");
|
||||
// }
|
||||
if (response == null) {
|
||||
// Refresh when offline?
|
||||
return null;
|
||||
} else if (response.selectedProfile == null) {
|
||||
throw new IllegalArgumentException("Can't refresh a demo account!");
|
||||
}
|
||||
|
||||
profilePath.clientToken = response.clientToken.toString();
|
||||
profilePath.accessToken = response.accessToken;
|
||||
profilePath.username = response.selectedProfile.name;
|
||||
profilePath.profileId = response.selectedProfile.id;
|
||||
profilePath.save();
|
||||
public void run(String name) throws Throwable {
|
||||
this.profilePath = MinecraftAccount.load(name);
|
||||
int responseCode = 400;
|
||||
responseCode = this.authenticator.validate(profilePath.accessToken).statusCode;
|
||||
if (responseCode >= 200 && responseCode < 300) {
|
||||
RefreshResponse response = this.authenticator.refresh(profilePath.accessToken, UUID.fromString(profilePath.clientToken));
|
||||
// if (response == null) {
|
||||
// throw new NullPointerException("Response is null?");
|
||||
// }
|
||||
if (response == null) {
|
||||
// Refresh when offline?
|
||||
return;
|
||||
} else if (response.selectedProfile == null) {
|
||||
throw new IllegalArgumentException("Can't refresh a demo account!");
|
||||
}
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
return e;
|
||||
|
||||
profilePath.clientToken = response.clientToken.toString();
|
||||
profilePath.accessToken = response.accessToken;
|
||||
profilePath.username = response.selectedProfile.name;
|
||||
profilePath.profileId = response.selectedProfile.id;
|
||||
profilePath.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package net.kdt.pojavlaunch.uikit;
|
||||
|
||||
import net.kdt.pojavlaunch.PojavProfile;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.*;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.LoginTask;
|
||||
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||
|
||||
public class AccountJNI {
|
||||
@@ -15,45 +16,32 @@ public class AccountJNI {
|
||||
// Call back about account credentials for login
|
||||
public static boolean loginAccount(int type,
|
||||
String username, // Mojang or offline username
|
||||
String password, // Mojang password or Microsoft token
|
||||
String password // Mojang password or Microsoft token
|
||||
) {
|
||||
try {
|
||||
switch (type) {
|
||||
case TYPE_SELECTACC:
|
||||
PojavProfile.updateTokens(username);
|
||||
CURRENT_ACCOUNT = MinecraftAccount.load(username);
|
||||
return true;
|
||||
break;
|
||||
|
||||
case TYPE_MICROSOFT:
|
||||
// TODO
|
||||
break;
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
// break;
|
||||
|
||||
case TYPE_MOJANG:
|
||||
String[] retArr = new LoginTask().run(username, password);
|
||||
if (!retArr[0].equals("NORMAL")) {
|
||||
StringBuilder full = new StringBuilder();
|
||||
for (int i = 1; i < retArr.length; i++) {
|
||||
full.append(retArr[i] + "\n");
|
||||
}
|
||||
UIKit.showError("Error", full.toString());
|
||||
return false;
|
||||
} else {
|
||||
CURRENT_ACCOUNT = new MinecraftAccount();
|
||||
CURRENT_ACCOUNT.accessToken = retArr[1];
|
||||
CURRENT_ACCOUNT.clientToken = retArr[2];
|
||||
CURRENT_ACCOUNT.profileId = retArr[3];
|
||||
CURRENT_ACCOUNT.username = retArr[4];
|
||||
CURRENT_ACCOUNT.save();
|
||||
return true;
|
||||
}
|
||||
CURRENT_ACCOUNT = new LoginTask().run(username, password);
|
||||
break;
|
||||
|
||||
case TYPE_OFFLINE:
|
||||
CURRENT_ACCOUNT = new MinecraftAccount();
|
||||
CURRENT_ACCOUNT.username = username;
|
||||
CURRENT_ACCOUNT.save();
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(th);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user