Workaround: auto Delete corrupted accounts

This commit is contained in:
Mathias-Boulay 2023-03-11 22:05:36 +01:00
parent 7c0a69fb6c
commit c8cf5df4e2
3 changed files with 15 additions and 4 deletions

View File

@ -159,7 +159,8 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
}
pickAccount(position);
performLogin(mSelectecAccount);
if(mSelectecAccount != null)
performLogin(mSelectecAccount);
}
@Override
@ -278,6 +279,16 @@ public class mcAccountSpinner extends AppCompatSpinner implements AdapterView.On
if(position != -1){
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;
}
setSelection(position);
}else {
// Get the current profile, or the first available profile if the wanted one is unavailable

View File

@ -25,7 +25,7 @@ public class PojavProfile {
return ctx.getSharedPreferences(PROFILE_PREF, Context.MODE_PRIVATE);
}
public static MinecraftAccount getCurrentProfileContent(@NonNull Context ctx, @Nullable String profileName) throws JsonSyntaxException {
public static MinecraftAccount getCurrentProfileContent(@NonNull Context ctx, @Nullable String profileName) {
return MinecraftAccount.load(profileName == null ? getCurrentProfileName(ctx) : profileName);
}

View File

@ -62,7 +62,7 @@ public class MinecraftAccount {
return Tools.GLOBAL_GSON.fromJson(content, MinecraftAccount.class);
}
public static MinecraftAccount load(String name) throws JsonSyntaxException {
public static MinecraftAccount load(String name) {
if(!accountExists(name)) return null;
try {
MinecraftAccount acc = parse(Tools.read(Tools.DIR_ACCOUNT_NEW + "/" + name + ".json"));
@ -88,7 +88,7 @@ public class MinecraftAccount {
// acc.updateSkinFace("MHF_Steve");
}
return acc;
} catch(IOException e) {
} catch(IOException | JsonSyntaxException e) {
Log.e(MinecraftAccount.class.getName(), "Caught an exception while loading the profile",e);
return null;
}