mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 15:17:02 -04:00
Fix weird edgecase crash for MinecraftAccount.load() returning null (#25)
This commit is contained in:
commit
5f24b138c9
@ -48,6 +48,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import fr.spse.extended_view.ExtendedTextView;
|
import fr.spse.extended_view.ExtendedTextView;
|
||||||
|
|
||||||
@ -301,14 +302,23 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
|||||||
PojavProfile.setCurrentProfile(getContext(), mAccountList.get(position));
|
PojavProfile.setCurrentProfile(getContext(), mAccountList.get(position));
|
||||||
selectedAccount = PojavProfile.getCurrentProfileContent(getContext(), mAccountList.get(position));
|
selectedAccount = PojavProfile.getCurrentProfileContent(getContext(), mAccountList.get(position));
|
||||||
|
|
||||||
|
|
||||||
// WORKAROUND
|
// WORKAROUND
|
||||||
// Account file corrupted due to previous versions having improper encoding
|
// Account file corrupted due to previous versions having improper encoding
|
||||||
if (selectedAccount == null){
|
if (selectedAccount == null){
|
||||||
|
Context ctx = Objects.requireNonNull(getContext());
|
||||||
|
|
||||||
|
new AlertDialog.Builder(ctx)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setTitle(R.string.account_corrupted)
|
||||||
|
.setMessage(R.string.login_again)
|
||||||
|
.setPositiveButton(R.string.delete_account_and_login, (dialog, which) -> {
|
||||||
removeCurrentAccount();
|
removeCurrentAccount();
|
||||||
pickAccount(-1);
|
pickAccount(-1);
|
||||||
setSelection(0);
|
setSelection(0);
|
||||||
return;
|
})
|
||||||
|
.show();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
setSelection(position);
|
setSelection(position);
|
||||||
}else {
|
}else {
|
||||||
|
@ -40,8 +40,10 @@ public class PojavProfile {
|
|||||||
public static List<MinecraftAccount> getAllProfiles(){
|
public static List<MinecraftAccount> getAllProfiles(){
|
||||||
List<MinecraftAccount> mcAccountList = new ArrayList<>();;
|
List<MinecraftAccount> mcAccountList = new ArrayList<>();;
|
||||||
for (String accountName : getAllProfilesList()){
|
for (String accountName : getAllProfilesList()){
|
||||||
|
if (MinecraftAccount.load(accountName) != null) {
|
||||||
mcAccountList.add(MinecraftAccount.load(accountName));
|
mcAccountList.add(MinecraftAccount.load(accountName));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return mcAccountList;
|
return mcAccountList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import android.graphics.Bitmap;
|
|||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
import androidx.annotation.Keep;
|
import androidx.annotation.Keep;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ public class MinecraftAccount {
|
|||||||
public static MinecraftAccount parse(String content) throws JsonSyntaxException {
|
public static MinecraftAccount parse(String content) throws JsonSyntaxException {
|
||||||
return Tools.GLOBAL_GSON.fromJson(content, MinecraftAccount.class);
|
return Tools.GLOBAL_GSON.fromJson(content, MinecraftAccount.class);
|
||||||
}
|
}
|
||||||
|
@Nullable
|
||||||
public static MinecraftAccount load(String name) {
|
public static MinecraftAccount load(String name) {
|
||||||
if(!accountExists(name)) return null;
|
if(!accountExists(name)) return null;
|
||||||
try {
|
try {
|
||||||
@ -92,7 +93,7 @@ public class MinecraftAccount {
|
|||||||
acc.msaRefreshToken = "0";
|
acc.msaRefreshToken = "0";
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
} catch(IOException | JsonSyntaxException e) {
|
} catch(NullPointerException | IOException | JsonSyntaxException e) {
|
||||||
Log.e(MinecraftAccount.class.getName(), "Caught an exception while loading the profile",e);
|
Log.e(MinecraftAccount.class.getName(), "Caught an exception while loading the profile",e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -450,6 +450,9 @@
|
|||||||
<string name="change_account">Please change accounts to use this function</string>
|
<string name="change_account">Please change accounts to use this function</string>
|
||||||
<string name="no_minecraft_account_found">No Minecraft Account Found</string>
|
<string name="no_minecraft_account_found">No Minecraft Account Found</string>
|
||||||
<string name="feature_requires_java_account">This feature requires a Microsoft account that owns Minecraft Java Edition.</string>
|
<string name="feature_requires_java_account">This feature requires a Microsoft account that owns Minecraft Java Edition.</string>
|
||||||
|
<string name="delete_account_and_login">Delete account and log in</string>
|
||||||
|
<string name="login_again">Please log in again</string>
|
||||||
|
<string name="account_corrupted">Selected account is corrupted</string>
|
||||||
<string name="modloader_dl_install_neoforge">Create Neoforge profile</string>
|
<string name="modloader_dl_install_neoforge">Create Neoforge profile</string>
|
||||||
<string name="neoforge_dl_select_version">Select NeoForge version</string>
|
<string name="neoforge_dl_select_version">Select NeoForge version</string>
|
||||||
<string name="neoforge_dl_no_installer">Sorry, but this version of NeoForge does not have an installer, which is not yet supported.</string>
|
<string name="neoforge_dl_no_installer">Sorry, but this version of NeoForge does not have an installer, which is not yet supported.</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user