mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 16:47:14 -04:00
Feat[profiles]: Avoid named profiles to be erased by installers
This commit is contained in:
parent
6c65334406
commit
57521c1960
@ -1,8 +1,12 @@
|
|||||||
package net.kdt.pojavlaunch.value.launcherprofiles;
|
package net.kdt.pojavlaunch.value.launcherprofiles;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import net.kdt.pojavlaunch.*;
|
import net.kdt.pojavlaunch.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class LauncherProfiles {
|
public class LauncherProfiles {
|
||||||
public static MinecraftLauncherProfiles mainProfileJson;
|
public static MinecraftLauncherProfiles mainProfileJson;
|
||||||
@ -13,6 +17,9 @@ public class LauncherProfiles {
|
|||||||
if (launcherProfilesFile.exists()) {
|
if (launcherProfilesFile.exists()) {
|
||||||
mainProfileJson = Tools.GLOBAL_GSON.fromJson(Tools.read(launcherProfilesFile.getAbsolutePath()), MinecraftLauncherProfiles.class);
|
mainProfileJson = Tools.GLOBAL_GSON.fromJson(Tools.read(launcherProfilesFile.getAbsolutePath()), MinecraftLauncherProfiles.class);
|
||||||
if(mainProfileJson.profiles == null) mainProfileJson.profiles = new HashMap<>();
|
if(mainProfileJson.profiles == null) mainProfileJson.profiles = new HashMap<>();
|
||||||
|
else if(LauncherProfiles.normalizeProfileIds(mainProfileJson)){
|
||||||
|
LauncherProfiles.update();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mainProfileJson = new MinecraftLauncherProfiles();
|
mainProfileJson = new MinecraftLauncherProfiles();
|
||||||
mainProfileJson.profiles = new HashMap<>();
|
mainProfileJson.profiles = new HashMap<>();
|
||||||
@ -27,6 +34,40 @@ public class LauncherProfiles {
|
|||||||
throw new RuntimeException(th);
|
throw new RuntimeException(th);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For all keys to be UUIDs, effectively isolating profile created by installers
|
||||||
|
* This avoids certain profiles to be erased by the installer
|
||||||
|
* @return Whether some profiles have been normalized
|
||||||
|
*/
|
||||||
|
private static boolean normalizeProfileIds(MinecraftLauncherProfiles launcherProfiles){
|
||||||
|
boolean hasNormalized = false;
|
||||||
|
ArrayList<String> keys = new ArrayList<>();
|
||||||
|
|
||||||
|
// Detect denormalized keys
|
||||||
|
for(String profileKey : launcherProfiles.profiles.keySet()){
|
||||||
|
try{
|
||||||
|
UUID.fromString(profileKey);
|
||||||
|
}catch (IllegalArgumentException exception){
|
||||||
|
keys.add(profileKey);
|
||||||
|
Log.w(LauncherProfiles.class.toString(), "Illegal profile uuid: " + profileKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap the new keys
|
||||||
|
for(String profileKey: keys){
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
while(launcherProfiles.profiles.containsKey(uuid)) {
|
||||||
|
uuid = UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
launcherProfiles.profiles.put(uuid, launcherProfiles.profiles.get(profileKey));
|
||||||
|
launcherProfiles.profiles.remove(profileKey);
|
||||||
|
hasNormalized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasNormalized;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
public static String insert;
|
public static String insert;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user