diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java index 8c40570c46..447c376feb 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseLauncherActivity.java @@ -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> versionListener; - @Override - protected void onPause() { - super.onPause(); - } public static void updateVersionSpinner(Context ctx, ArrayList value, Spinner mVersionSelector, String defaultSelection) { if(value != null && value.size() > 0) { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java index f046f79f13..d23d68a23d 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java @@ -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; @@ -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)); @@ -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(){ @@ -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(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java index dd91ed26a9..6b015f8896 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java @@ -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; @@ -336,6 +339,7 @@ private void initMain() throws Throwable { mLockSelectJRE.wait(); } } + migrateToProfiles(); if(Build.VERSION.SDK_INT > 28) runOnUiThread(this::showStorageDialog); LauncherPreferences.loadPreferences(getApplicationContext()); } @@ -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; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/PerVersionConfigDialog.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/PerVersionConfigDialog.java deleted file mode 100644 index 2b5f000e91..0000000000 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/PerVersionConfigDialog.java +++ /dev/null @@ -1,124 +0,0 @@ -package net.kdt.pojavlaunch.prefs; - -import android.content.Context; -import android.content.DialogInterface; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.Spinner; - -import androidx.appcompat.app.AlertDialog; - -import net.kdt.pojavlaunch.R; -import net.kdt.pojavlaunch.multirt.MultiRTUtils; -import net.kdt.pojavlaunch.multirt.RTSpinnerAdapter; -import net.kdt.pojavlaunch.multirt.Runtime; -import net.kdt.pojavlaunch.value.PerVersionConfig; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class PerVersionConfigDialog{ - final Context mContext; - final AlertDialog mDialog; - final View mRootView; - List mRuntimes; - final Spinner mJvmSpinner; - final Spinner mRendererSpinner; - final EditText mCustomDirEditText; - final EditText mJvmArgsEditText; - final List mRendererNames; - String mSelectedGameVersion = null; - - public PerVersionConfigDialog(Context ctx) { - mContext = ctx; - mRootView = LayoutInflater.from(mContext).inflate(R.layout.dialog_per_version_control,null); - mJvmSpinner = mRootView.findViewById(R.id.pvc_javaVm); - mRendererSpinner = mRootView.findViewById(R.id.pvc_renderer); - - ArrayList renderList = new ArrayList<>(5); - Collections.addAll(renderList, mContext.getResources().getStringArray(R.array.renderer)); - renderList.add("Default"); - mRendererNames = Arrays.asList(mContext.getResources().getStringArray(R.array.renderer_values)); - mRendererSpinner.setAdapter(new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_dropdown_item, renderList)); - - mCustomDirEditText = mRootView.findViewById(R.id.pvc_customDir); - mJvmArgsEditText = mRootView.findViewById(R.id.pvc_jvmArgs); - AlertDialog.Builder builder = new AlertDialog.Builder(mContext); - builder.setView(mRootView); - builder.setTitle(R.string.pvc_title); - builder.setNegativeButton(android.R.string.cancel, null); - builder.setPositiveButton(android.R.string.ok, this::save); - mDialog = builder.create(); - } - - public void refreshRuntimes() { - if(mRuntimes !=null) mRuntimes.clear(); - mRuntimes = MultiRTUtils.getRuntimes(); - //runtimes.add(new Runtime("")); - } - - private void save(DialogInterface dialogInterface, int which) { - if(mSelectedGameVersion == null) { - dialogInterface.dismiss(); - return; - } - - PerVersionConfig.VersionConfig versionConfig = PerVersionConfig.configMap.get(mSelectedGameVersion); - if(versionConfig == null){ - versionConfig = new PerVersionConfig.VersionConfig(); - } - versionConfig.jvmArgs= mJvmArgsEditText.getText().toString(); - versionConfig.gamePath= mCustomDirEditText.getText().toString(); - - if(mRendererSpinner.getSelectedItemPosition() == mRendererNames.size()) versionConfig.renderer = null; - else versionConfig.renderer = mRendererNames.get(mRendererSpinner.getSelectedItemPosition()); - - String runtime=((Runtime) mJvmSpinner.getSelectedItem()).name;; - if(!runtime.equals(""))versionConfig.selectedRuntime=runtime; - else versionConfig.selectedRuntime = null; - - PerVersionConfig.configMap.put(mSelectedGameVersion, versionConfig); - try{ - PerVersionConfig.update(); - }catch(IOException e){ - e.printStackTrace(); - } - } - - public boolean openConfig(String selectedVersion) { - mSelectedGameVersion = selectedVersion; - try{ - PerVersionConfig.update(); - }catch(IOException e){ - e.printStackTrace(); - } - PerVersionConfig.VersionConfig versionConfig = PerVersionConfig.configMap.get(mSelectedGameVersion); - refreshRuntimes(); - mJvmSpinner.setAdapter(new RTSpinnerAdapter(mContext, mRuntimes)); - - int jvmIndex = mRuntimes.indexOf(new Runtime("")); - int rendererIndex = mRendererSpinner.getAdapter().getCount()-1; - if (versionConfig != null) { - mCustomDirEditText.setText(versionConfig.gamePath); - mJvmArgsEditText.setText(versionConfig.jvmArgs); - if (versionConfig.selectedRuntime != null) { - int nIndex = mRuntimes.indexOf(new Runtime(versionConfig.selectedRuntime)); - if (nIndex != -1) jvmIndex = nIndex; - } - if(versionConfig.renderer != null) { - int nIndex = mRendererNames.indexOf(versionConfig.renderer); - if (nIndex != -1) rendererIndex = nIndex; - } - } - mJvmSpinner.setSelection(jvmIndex); - mRendererSpinner.setSelection(rendererIndex); - - mDialog.show(); - return true; - } -} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/PerVersionConfig.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/PerVersionConfig.java index 30903c86e0..d657de5524 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/PerVersionConfig.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/PerVersionConfig.java @@ -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; diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index c8dfbe9111..bf4276659e 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -300,4 +300,5 @@ Help with compatibility on some old versions Arc Capes Enables capes from Arc. For more information please visit https://arccapes.com. Requires OptiFine. + %s version configuration