Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiles 2: Electric Boogaloo #2535

Merged
merged 29 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4bea845
Start implementing new, cleaner Profiles
artdeell Nov 30, 2021
0fc0623
ExtraCore can now deal all kinds of values (#2315)
artdeell Dec 1, 2021
4961acf
New shit
artdeell Dec 2, 2021
213c6a7
Changes
artdeell Dec 5, 2021
9608545
Changes
artdeell Dec 5, 2021
14a460a
Fix merging
artdeell Dec 7, 2021
095b62a
Changes
artdeell Dec 7, 2021
870d86d
check for null value insert (#2350)
artdeell Dec 7, 2021
2478758
Update from mainline
artdeell Dec 11, 2021
ad8d115
▼▼▼
artdeell Dec 13, 2021
9fc4d5d
Upstreamify profiles (#2390)
artdeell Dec 13, 2021
8588933
Upstreamify profiles (#2472)
artdeell Dec 28, 2021
ac40da2
TMP_COMMIT
artdeell Jan 5, 2022
015e27d
Make the profile settings from the previous commit user-editable
artdeell Jan 10, 2022
15030ac
Merge remote-tracking branch 'origin/profiles-2-electric-boogaloo' in…
artdeell Jan 10, 2022
b85dd16
Fix merge conflicts
artdeell Jan 10, 2022
d7556c3
Upstreamify
artdeell Feb 4, 2022
0b4d775
Upstreamify profiles (#2765)
artdeell Feb 20, 2022
cf72668
Merge branch 'profiles-2-electric-boogaloo' into merge-profiles
artdeell Mar 17, 2022
a4eabb6
Merge pull request #2917 from PojavLauncherTeam/merge-profiles
artdeell Mar 17, 2022
965cad4
A lot of changes
artdeell Mar 17, 2022
19037b8
Implement PVC migrator, remove PVC dialog, add a couple of helper met…
artdeell Mar 17, 2022
05cf75e
Remove StringCRC64 since its now useless
artdeell Mar 20, 2022
8685b49
Rename ProfileConstants to ExtraConstants and move it to extra package
artdeell Mar 20, 2022
68b10bc
Fixations
artdeell Mar 20, 2022
89d42b9
Make 'em private
artdeell Mar 20, 2022
e8697c6
Update ProfileAdapter.java
artdeell Mar 20, 2022
3aa5615
Update ProfileAdapter.java
artdeell Mar 20, 2022
5f94f25
Redesign control flows a bit
artdeell Mar 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@
import androidx.annotation.Nullable;

import java.io.*;

import java.util.ArrayList;
import java.util.Map;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.tasks.*;

import androidx.appcompat.app.AlertDialog;

import net.kdt.pojavlaunch.value.*;
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;

import org.apache.commons.io.IOUtils;

Expand All @@ -33,7 +39,7 @@ public abstract class BaseLauncherActivity extends BaseActivity {
public JMinecraftVersionList mVersionList;
public MinecraftDownloaderTask mTask;
public MinecraftAccount mProfile;
public String[] mAvailableVersions;
//public String[] mAvailableVersions;

public boolean mIsAssetsProcessing = false;
protected boolean canBack = false;
Expand Down Expand Up @@ -99,26 +105,38 @@ public void launchGame(View v) {
} else if (canBack) {
v.setEnabled(false);
mTask = new MinecraftDownloaderTask(this);
// TODO: better check!!!
if (mProfile.accessToken.equals("0")) {
File verJsonFile = new File(Tools.DIR_HOME_VERSION,
mProfile.selectedVersion + "/" + mProfile.selectedVersion + ".json");
if (verJsonFile.exists()) {
mTask.onPostExecute(null);
} else {
new AlertDialog.Builder(this)
.setTitle(R.string.global_error)
.setMessage(R.string.mcl_launch_error_localmode)
.setPositiveButton(android.R.string.ok, null)
.show();
LauncherProfiles.update();
if (LauncherProfiles.mainProfileJson != null && LauncherProfiles.mainProfileJson.profiles != null && LauncherProfiles.mainProfileJson.profiles.containsKey(mProfile.selectedProfile + "")) {
MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile + "");
if (prof != null && prof.lastVersionId != null) {
if (mProfile.accessToken.equals("0")) {
String versionId = getVersionId(prof.lastVersionId);
File verJsonFile = new File(Tools.DIR_HOME_VERSION,
versionId + "/" + versionId + ".json");
if (verJsonFile.exists()) {
mTask.onPostExecute(null);
return;
}
Tools.dialogOnUiThread(this,
getString(R.string.global_error),
getString(R.string.mcl_launch_error_localmode)
);
}else {
mTask.execute(getVersionId(prof.lastVersionId));
}
}
}
} else {
mTask.execute(mProfile.selectedVersion);
}

}
}


public static String getVersionId(String input) {
Map<String,String> releaseTable = (Map<String,String>)ExtraCore.getValue(ExtraConstants.RELEASE_TABLE);
if(releaseTable == null || releaseTable.isEmpty()) return input;
if("latest-release".equals(input)) return releaseTable.get("release");
if("latest-snapshot".equals(input)) return releaseTable.get("snapshot");
return input;
}

@Override
public void onBackPressed() {
if (canBack) {
Expand All @@ -133,10 +151,35 @@ protected void onPostResume() {
Tools.updateWindowSize(this);
System.out.println("call to onPostResume; E");
}


public static void updateVersionSpinner(Context ctx, ArrayList<String> value, Spinner mVersionSelector, String defaultSelection) {
if(value != null && value.size() > 0) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx, android.R.layout.simple_spinner_item, value);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
mVersionSelector.setAdapter(adapter);
mVersionSelector.setSelection(RefreshVersionListTask.selectAt(value, defaultSelection));
return;
}
mVersionSelector.setSelection(RefreshVersionListTask.selectAt(PojavLauncherActivity.basicVersionList, defaultSelection));
}
@Override
protected void onResume(){
super.onResume();
new RefreshVersionListTask(this).execute();
if(listRefreshListener != null) {
LauncherPreferences.DEFAULT_PREF.unregisterOnSharedPreferenceChangeListener(listRefreshListener);
}
listRefreshListener = (sharedPreferences, key) -> {
if(key.startsWith("vertype_")) {
System.out.println("Verlist update needed!");
LauncherPreferences.PREF_VERTYPE_RELEASE = sharedPreferences.getBoolean("vertype_release",true);
LauncherPreferences.PREF_VERTYPE_SNAPSHOT = sharedPreferences.getBoolean("vertype_snapshot",false);
LauncherPreferences.PREF_VERTYPE_OLDALPHA = sharedPreferences.getBoolean("vertype_oldalpha",false);
LauncherPreferences.PREF_VERTYPE_OLDBETA = sharedPreferences.getBoolean("vertype_oldbeta",false);
new RefreshVersionListTask(this).execute();
}
};
LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener(listRefreshListener);
System.out.println("call to onResume");
final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
final View decorView = getWindow().getDecorView();
Expand All @@ -145,20 +188,10 @@ protected void onResume(){
}

SharedPreferences.OnSharedPreferenceChangeListener listRefreshListener = null;
SharedPreferences.OnSharedPreferenceChangeListener profileEnableListener = null;
@Override
protected void onResumeFragments() {
super.onResumeFragments();
if(listRefreshListener == null) {
final BaseLauncherActivity thiz = this;
listRefreshListener = (sharedPreferences, key) -> {
if(key.startsWith("vertype_")) {
System.out.println("Verlist update needed!");
new RefreshVersionListTask(thiz).execute();
}
};
}
LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener(listRefreshListener);
new RefreshVersionListTask(this).execute();
System.out.println("call to onResumeFragments");
mRuntimeConfigDialog = new MultiRTConfigDialog();
mRuntimeConfigDialog.prepare(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.utils.*;
import net.kdt.pojavlaunch.value.*;
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;

import org.lwjgl.glfw.*;

public class BaseMainActivity extends BaseActivity {
Expand All @@ -45,7 +48,8 @@ public class BaseMainActivity extends BaseActivity {
private static Touchpad touchpad;
private LoggerView loggerView;

private MinecraftAccount mProfile;
MinecraftAccount mProfile;
MinecraftProfile minecraftProfile;

private DrawerLayout drawerLayout;
private NavigationView navDrawer;
Expand All @@ -55,11 +59,10 @@ public class BaseMainActivity extends BaseActivity {

protected volatile JMinecraftVersionList.Version mVersionInfo;

private PerVersionConfig.VersionConfig config;
//private PerVersionConfig.VersionConfig config;

protected void initLayout(int resId) {
setContentView(resId);

try {
Logger.getInstance().reset();
// FIXME: is it safe fot multi thread?
Expand All @@ -68,22 +71,30 @@ protected void initLayout(int resId) {
loggerView = findViewById(R.id.mainLoggerView);

mProfile = PojavProfile.getCurrentProfileContent(this);
mVersionInfo = Tools.getVersionInfo(null,mProfile.selectedVersion);

setTitle("Minecraft " + mProfile.selectedVersion);
PerVersionConfig.update();
config = PerVersionConfig.configMap.get(mProfile.selectedVersion);
minecraftProfile = LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile);
if(minecraftProfile == null) {
Toast.makeText(this,"Attempted to launch nonexistent profile",Toast.LENGTH_SHORT).show();
finish();
return;
}
String runtime = LauncherPreferences.PREF_DEFAULT_RUNTIME;
if(config != null) {
if(config.selectedRuntime != null) {
if(MultiRTUtils.forceReread(config.selectedRuntime).versionString != null) {
runtime = config.selectedRuntime;
LauncherProfiles.update();

mVersionInfo = Tools.getVersionInfo(null, BaseLauncherActivity.getVersionId(
minecraftProfile.lastVersionId));
if(minecraftProfile.javaDir != null && minecraftProfile.javaDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) {
String runtimeName = minecraftProfile.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length());
if(MultiRTUtils.forceReread(runtimeName).versionString != null) {
runtime = runtimeName;
}
}
if(config.renderer != null) {
Tools.LOCAL_RENDERER = config.renderer;
if(minecraftProfile.pojavRendererName != null) {
Log.i("RdrDebug","__P_renderer="+minecraftProfile.pojavRendererName);
Tools.LOCAL_RENDERER = minecraftProfile.pojavRendererName;
}
}

setTitle("Minecraft " + minecraftProfile.lastVersionId);

MultiRTUtils.setRuntimeNamed(this,runtime);
// Minecraft 1.13+
isInputStackCall = mVersionInfo.arguments != null;
Expand Down Expand Up @@ -204,8 +215,11 @@ private void runCraft() throws Throwable {
((mVersionInfo.inheritsFrom == null || mVersionInfo.inheritsFrom.equals(mVersionInfo.id)) ?
"" : " (" + mVersionInfo.inheritsFrom + ")"));


JREUtils.redirectAndPrintJRELog();
Tools.launchMinecraft(this, mProfile, mProfile.selectedVersion);
LauncherProfiles.update();
Tools.launchMinecraft(this, mProfile, BaseLauncherActivity.getVersionId(
minecraftProfile.lastVersionId));
}

private void checkJavaArgsIsLaunchable(String jreVersion) throws Throwable {
Expand Down
Loading