mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 23:00:45 -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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import fr.spse.extended_view.ExtendedTextView;
|
||||
|
||||
@ -301,14 +302,23 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
|
||||
PojavProfile.setCurrentProfile(getContext(), mAccountList.get(position));
|
||||
selectedAccount = PojavProfile.getCurrentProfileContent(getContext(), mAccountList.get(position));
|
||||
|
||||
|
||||
// WORKAROUND
|
||||
// Account file corrupted due to previous versions having improper encoding
|
||||
if (selectedAccount == null){
|
||||
removeCurrentAccount();
|
||||
pickAccount(-1);
|
||||
setSelection(0);
|
||||
return;
|
||||
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();
|
||||
pickAccount(-1);
|
||||
setSelection(0);
|
||||
})
|
||||
.show();
|
||||
|
||||
|
||||
}
|
||||
setSelection(position);
|
||||
}else {
|
||||
|
@ -40,7 +40,9 @@ public class PojavProfile {
|
||||
public static List<MinecraftAccount> getAllProfiles(){
|
||||
List<MinecraftAccount> mcAccountList = new ArrayList<>();;
|
||||
for (String accountName : getAllProfilesList()){
|
||||
mcAccountList.add(MinecraftAccount.load(accountName));
|
||||
if (MinecraftAccount.load(accountName) != null) {
|
||||
mcAccountList.add(MinecraftAccount.load(accountName));
|
||||
}
|
||||
}
|
||||
return mcAccountList;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import android.graphics.Bitmap;
|
||||
import android.util.Base64;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
@ -68,7 +69,7 @@ public class MinecraftAccount {
|
||||
public static MinecraftAccount parse(String content) throws JsonSyntaxException {
|
||||
return Tools.GLOBAL_GSON.fromJson(content, MinecraftAccount.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MinecraftAccount load(String name) {
|
||||
if(!accountExists(name)) return null;
|
||||
try {
|
||||
@ -92,7 +93,7 @@ public class MinecraftAccount {
|
||||
acc.msaRefreshToken = "0";
|
||||
}
|
||||
return acc;
|
||||
} catch(IOException | JsonSyntaxException e) {
|
||||
} catch(NullPointerException | IOException | JsonSyntaxException e) {
|
||||
Log.e(MinecraftAccount.class.getName(), "Caught an exception while loading the profile",e);
|
||||
return null;
|
||||
}
|
||||
|
@ -450,6 +450,9 @@
|
||||
<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="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="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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user