Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Implement PVC migrator, remove PVC dialog, add a couple of helper met…
Browse files Browse the repository at this point in the history
…hods and sanitize the code according to serpent's recommendations
  • Loading branch information
artdeell committed Mar 17, 2022
1 parent 965cad4 commit 19037b8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,41 +159,6 @@ protected void onPostResume() {
Tools.updateWindowSize(this);
System.out.println("call to onPostResume; E");
}
public void setupVersionSelector() {
final androidx.appcompat.widget.PopupMenu popup = new PopupMenu(this, mVersionSelector);
popup.getMenuInflater().inflate(R.menu.menu_versionopt, popup.getMenu());
PerVersionConfigDialog dialog = new PerVersionConfigDialog(this);
this.mVersionSelector.setOnLongClickListener((v)->dialog.openConfig(this.mProfile.selectedVersion));
this.mVersionSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> p1, View p2, int p3, long p4)
{
mProfile.selectedVersion = p1.getItemAtPosition(p3).toString();

PojavProfile.setCurrentProfile(BaseLauncherActivity.this, mProfile);
if (PojavProfile.isFileType(BaseLauncherActivity.this)) {
try {
PojavProfile.setCurrentProfile(BaseLauncherActivity.this, mProfile.save());
} catch (IOException e) {
Tools.showError(BaseLauncherActivity.this, e);
}
}

}

@Override
public void onNothingSelected(AdapterView<?> p1)
{
// TODO: Implement this method
}
});
popup.setOnMenuItemClickListener(item -> true);
}
ExtraListener<ArrayList<String>> versionListener;
@Override
protected void onPause() {
super.onPause();
}

public static void updateVersionSpinner(Context ctx, ArrayList<String> value, Spinner mVersionSelector, String defaultSelection) {
if(value != null && value.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.kdt.pojavlaunch.fragments.CrashFragment;
import net.kdt.pojavlaunch.fragments.LauncherFragment;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.prefs.PerVersionConfigDialog;
import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment;
import net.kdt.pojavlaunch.profiles.ProfileAdapter;
import net.kdt.pojavlaunch.profiles.ProfileEditor;
Expand Down Expand Up @@ -193,7 +192,7 @@ public void onNothingSelected(AdapterView<?> p1) {

//mAvailableVersions;
ProfileAdapter profileAdapter = new ProfileAdapter(this);
ProfileEditor editor = new ProfileEditor(this,(name, isNew, deleting)->{
ProfileEditor profileEditor = new ProfileEditor(this,(name, isNew, deleting)->{
LauncherProfiles.update();
if(isNew) {
mVersionSelector.setSelection(profileAdapter.resolveProfileIndex(name));
Expand All @@ -203,7 +202,7 @@ public void onNothingSelected(AdapterView<?> p1) {
}
profileAdapter.notifyDataSetChanged();
});
mVersionSelector.setOnLongClickListener((v)->editor.show(mProfile.selectedProfile));
mVersionSelector.setOnLongClickListener((v)->profileEditor.show(mProfile.selectedProfile));
mVersionSelector.setAdapter(profileAdapter);
mVersionSelector.setSelection(profileAdapter.resolveProfileIndex(mProfile.selectedProfile));
mVersionSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
Expand All @@ -212,7 +211,7 @@ public void onItemSelected(AdapterView<?> p1, View p2, int p3, long p4)
{
String profileName = p1.getItemAtPosition(p3).toString();
if(profileName.equals(ProfileAdapter.CREATE_PROFILE_MAGIC)) {
editor.show(profileName);
profileEditor.show(profileName);
mVersionSelector.setSelection(0);
}else {
mProfile.selectedProfile = p1.getItemAtPosition(p3).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.utils.LocaleUtils;
import net.kdt.pojavlaunch.value.MinecraftAccount;
import net.kdt.pojavlaunch.value.PerVersionConfig;
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;

import org.apache.commons.io.FileUtils;

Expand Down Expand Up @@ -336,6 +339,7 @@ private void initMain() throws Throwable {
mLockSelectJRE.wait();
}
}
migrateToProfiles();
if(Build.VERSION.SDK_INT > 28) runOnUiThread(this::showStorageDialog);
LauncherPreferences.loadPreferences(getApplicationContext());
}
Expand Down Expand Up @@ -388,6 +392,33 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
}
}
}
private void migrateToProfiles() {
try {
if(!PerVersionConfig.exists()) return;
LauncherProfiles.update();
PerVersionConfig.update();
if(PerVersionConfig.erase()) {
for (String version : PerVersionConfig.configMap.keySet()) {
PerVersionConfig.VersionConfig config = PerVersionConfig.configMap.get(version);
if (config != null) {
MinecraftProfile profile = new MinecraftProfile();
profile.lastVersionId = version;
profile.name = getString(R.string.migrated_profile_str, version);
profile.pojavRendererName = config.renderer;
profile.gameDir = config.gamePath;
profile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + config.selectedRuntime;
profile.javaArgs = config.jvmArgs;
LauncherProfiles.mainProfileJson.profiles.put("pvc-migrated-" + version, profile);
}
}
LauncherProfiles.update();
}else{
Log.e("ProfileMigrator"," Unable to remove Per Version Config files.");
}
}catch (IOException e) {
Log.e("ProfileMigrator","Failed to migrate!",e);
}
}
private boolean installRuntimeAutomatically(AssetManager am, boolean otherRuntimesAvailable) {
/* Check if JRE is included */
String rt_version = null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public static void update() throws IOException {
Tools.write(pvcFile.getAbsolutePath(),Tools.GLOBAL_GSON.toJson(configMap));
}
}
public static boolean erase() {
return new File(Tools.DIR_GAME_HOME,"per-version-config.json").delete();
}
public static boolean exists() {
return new File(Tools.DIR_GAME_HOME,"per-version-config.json").exists();
}
public static class VersionConfig {
public String jvmArgs;
public String gamePath;
Expand Down
1 change: 1 addition & 0 deletions app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,5 @@
<string name="gles_version_hack_description">Help with compatibility on some old versions</string>
<string name="arc_capes_title">Arc Capes</string>
<string name="arc_capes_desc">Enables capes from Arc. For more information please visit https://arccapes.com. Requires OptiFine.</string>
<string name="migrated_profile_str">%s version configuration</string>
</resources>

0 comments on commit 19037b8

Please sign in to comment.