Add the ability to change the Minecraft folder for a profile

This commit is contained in:
artdeell 2022-04-12 22:00:05 +03:00
parent 45751ed37d
commit 6060e8bdcd
4 changed files with 37 additions and 4 deletions

View File

@ -124,8 +124,8 @@ public final class Tools {
LauncherProfiles.update();
MinecraftProfile minecraftProfile = ((BaseMainActivity)activity).minecraftProfile;
if(minecraftProfile == null) throw new Exception("Launching empty Profile");
if(minecraftProfile.gameDir != null && !minecraftProfile.gameDir.isEmpty())
gamedirPath = minecraftProfile.gameDir;
if(minecraftProfile.gameDir != null && minecraftProfile.gameDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX))
gamedirPath = minecraftProfile.gameDir.replace(Tools.LAUNCHERPROFILES_RTPREFIX,Tools.DIR_GAME_HOME+"/");
if(minecraftProfile.javaArgs != null && !minecraftProfile.javaArgs.isEmpty())
LauncherPreferences.PREF_CUSTOM_JAVA_ARGS = minecraftProfile.javaArgs;
}

View File

@ -9,6 +9,7 @@ import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
@ -43,6 +44,7 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
private final Spinner versionSpinner;
private final Spinner javaRuntimeSpinner;
private final Spinner rendererSpinner;
private final EditText pathSelectionEditor;
private final List<String> renderNames;
private final AlertDialog dialog;
private String selectedVersionId;
@ -75,6 +77,8 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
rendererSpinner.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item,renderList));
}
profileIconView = mainView.findViewById(R.id.vprof_editor_icon);
((TextView)mainView.findViewById(R.id.vprof_editor_beginPathView)).setText(Tools.DIR_GAME_HOME+"/");
pathSelectionEditor = mainView.findViewById(R.id.vprof_editor_path);
builder.setPositiveButton(R.string.global_save,this::save);
builder.setNegativeButton(android.R.string.cancel,(dialog,which)->destroy(dialog));
builder.setNeutralButton(R.string.global_delete,(dialogInterface, i) -> {
@ -143,6 +147,9 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
}
ArrayList<String> versions = (ArrayList<String>) ExtraCore.getValue(ExtraConstants.VERSION_LIST);
BaseLauncherActivity.updateVersionSpinner(context,versions,versionSpinner, selectedVersionId);
if(minecraftProfile.gameDir != null && minecraftProfile.gameDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) {
pathSelectionEditor.setText(minecraftProfile.gameDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()));
}
dialog.show();
return true;
}
@ -175,6 +182,10 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
}
if(rendererSpinner.getSelectedItemPosition() == renderNames.size()) profile.pojavRendererName = null;
else profile.pojavRendererName = renderNames.get(rendererSpinner.getSelectedItemPosition());
String selectedPath = pathSelectionEditor.getText().toString();
if(!selectedPath.isEmpty()) {
profile.gameDir = Tools.LAUNCHERPROFILES_RTPREFIX+selectedPath;
}
LauncherProfiles.mainProfileJson.profiles.put(editingProfile,profile);
editSaveCallback.onSave(editingProfile,isNew, false);
destroy(dialog);

View File

@ -116,7 +116,7 @@ public class V117CompatUtil {
MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(((BaseLauncherActivity)ctx).mProfile.selectedProfile);
if(prof == null) throw new MinecraftDownloaderTask.SilentException();
renderer = prof.pojavRendererName != null?prof.pojavRendererName :LauncherPreferences.PREF_RENDERER;
gamePath = prof.gameDir != null?prof.gameDir:Tools.DIR_GAME_NEW;
gamePath = prof.gameDir != null && prof.gameDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)?prof.gameDir.replace(Tools.LAUNCHERPROFILES_RTPREFIX,Tools.DIR_GAME_HOME+"/"):Tools.DIR_GAME_NEW;
//String
if(renderer.equals("vulkan_zink") || renderer.equals("opengles3_virgl")) return; //don't install for zink/virgl users;

View File

@ -62,8 +62,9 @@
android:layout_marginEnd="16dp"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vprof_editior_profile_name" />
app:layout_constraintTop_toBottomOf="@+id/vprof_editor_path" />
<TextView
android:id="@+id/textView4"
@ -109,5 +110,26 @@
app:layout_constraintBottom_toTopOf="@+id/vprof_editor_profile_renderer"
app:layout_constraintStart_toStartOf="@+id/vprof_editor_profile_renderer" />
<EditText
android:id="@+id/vprof_editor_path"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:hint=".minecraft"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vprof_editior_profile_name" />
<TextView
android:id="@+id/vprof_editor_beginPathView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/vprof_editor_path"
app:layout_constraintStart_toStartOf="@+id/vprof_editor_path" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>