Remove StringCRC64 since its now useless

Move all ExtraCore constants into a separate class
This commit is contained in:
artdeell 2022-03-20 13:07:27 +03:00
parent 19037b8db1
commit 05cf75e8fa
6 changed files with 21 additions and 73 deletions

View File

@ -20,6 +20,7 @@ import net.kdt.pojavlaunch.fragments.*;
import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.profiles.ProfileConstants;
import net.kdt.pojavlaunch.tasks.*;
import androidx.appcompat.app.AlertDialog;
@ -133,7 +134,7 @@ public abstract class BaseLauncherActivity extends BaseActivity {
}
public static String getVersionId(String input) {
Map<String,String> lReleaseMaps = (Map<String,String>)ExtraCore.getValue("release_table");
Map<String,String> lReleaseMaps = (Map<String,String>)ExtraCore.getValue(ProfileConstants.RELEASE_TABLE);
if(lReleaseMaps == null || lReleaseMaps.isEmpty()) return input;
switch(input) {
case "latest-release":

View File

@ -39,6 +39,7 @@ import net.kdt.pojavlaunch.fragments.LauncherFragment;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment;
import net.kdt.pojavlaunch.profiles.ProfileAdapter;
import net.kdt.pojavlaunch.profiles.ProfileConstants;
import net.kdt.pojavlaunch.profiles.ProfileEditor;
import net.kdt.pojavlaunch.profiles.ProfileIconCache;
import net.kdt.pojavlaunch.value.MinecraftAccount;
@ -273,7 +274,7 @@ public class PojavLauncherActivity extends BaseLauncherActivity
} finally {
basicVersionList = versions.toArray(new String[0]);
ExtraCore.setValue("lac_version_list",versions);
ExtraCore.setValue(ProfileConstants.VERSION_LIST,versions);
}
}
private void pickAccount() {

View File

@ -0,0 +1,9 @@
package net.kdt.pojavlaunch.profiles;
public class ProfileConstants {
/* ExtraCore constant: a HashMap for converting values such as latest-snapshot or latest-release to actual game version names */
public static final String RELEASE_TABLE = "release_table";
/* ExtraCore constant: an ArrayList of Strings, where each String is a Minecraft version name */
public static final String VERSION_LIST= "lac_version_list";
}

View File

@ -114,7 +114,7 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
}
javaRuntimeSpinner.setSelection(jvmIndex);
rendererSpinner.setSelection(rendererIndex);
ExtraCore.addExtraListener("lac_version_list",this);
ExtraCore.addExtraListener(ProfileConstants.VERSION_LIST,this);
profileNameView.setText(minecraftProfile.name);
Bitmap profileIcon = ProfileIconCache.getCachedIcon(profile);
if(profileIcon == null) {
@ -124,7 +124,7 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
if(minecraftProfile.lastVersionId != null && !"latest-release".equals(minecraftProfile.lastVersionId) && !"latest-snapshot".equals(minecraftProfile.lastVersionId))
selectedVersionId = minecraftProfile.lastVersionId;
else if(minecraftProfile.lastVersionId != null) {
Map<String,String> releaseTable = (Map<String,String>)ExtraCore.getValue("release_table");
Map<String,String> releaseTable = (Map<String,String>)ExtraCore.getValue(ProfileConstants.RELEASE_TABLE);
if(releaseTable != null) {
switch (minecraftProfile.lastVersionId) {
case "latest-release":
@ -141,7 +141,7 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
selectedVersionId = PojavLauncherActivity.basicVersionList[0];
}
}
ArrayList<String> versions = (ArrayList<String>) ExtraCore.getValue("lac_version_list");
ArrayList<String> versions = (ArrayList<String>) ExtraCore.getValue(ProfileConstants.VERSION_LIST);
BaseLauncherActivity.updateVersionSpinner(context,versions,versionSpinner, selectedVersionId);
dialog.show();
return true;
@ -180,7 +180,7 @@ public class ProfileEditor implements ExtraListener<ArrayList<String>> {
destroy(dialog);
}
public void destroy(@NonNull DialogInterface dialog) {
ExtraCore.removeExtraListenerFromValue("lac_version_list",this);
ExtraCore.removeExtraListenerFromValue(ProfileConstants.VERSION_LIST,this);
editingProfile = null;
selectedVersionId = null;
}

View File

@ -1,64 +0,0 @@
package net.kdt.pojavlaunch.profiles;
import java.nio.charset.StandardCharsets;
public class StringCRC64 {
private final static long POLY = 0xc96c5795d7870f42L; // ECMA-182
private final static long[][] table;
static
{
table = new long[8][256];
for (int n = 0; n < 256; n++)
{
long crc = n;
for (int k = 0; k < 8; k++)
{
if ((crc & 1) == 1)
{
crc = (crc >>> 1) ^ POLY;
}
else
{
crc = (crc >>> 1);
}
}
table[0][n] = crc;
}
for (int n = 0; n < 256; n++)
{
long crc = table[0][n];
for (int k = 1; k < 8; k++)
{
crc = table[0][(int) (crc & 0xff)] ^ (crc >>> 8);
table[k][n] = crc;
}
}
}
public static long strhash(String str) {
byte[] b = str.getBytes(StandardCharsets.US_ASCII);
long value = 0;
int idx = 0;
int len = b.length;
while (len >= 8)
{
value = table[7][(int) (value & 0xff ^ (b[idx] & 0xff))]
^ table[6][(int) ((value >>> 8) & 0xff ^ (b[idx + 1] & 0xff))]
^ table[5][(int) ((value >>> 16) & 0xff ^ (b[idx + 2] & 0xff))]
^ table[4][(int) ((value >>> 24) & 0xff ^ (b[idx + 3] & 0xff))]
^ table[3][(int) ((value >>> 32) & 0xff ^ (b[idx + 4] & 0xff))]
^ table[2][(int) ((value >>> 40) & 0xff ^ (b[idx + 5] & 0xff))]
^ table[1][(int) ((value >>> 48) & 0xff ^ (b[idx + 6] & 0xff))]
^ table[0][(int) ((value >>> 56) ^ b[idx + 7] & 0xff)];
idx += 8;
len -= 8;
}
while (len > 0)
{
value = table[0][(int) ((value ^ b[idx]) & 0xff)] ^ (value >>> 8);
idx++;
len--;
}
return ~value;
}
}

View File

@ -18,6 +18,7 @@ import net.kdt.pojavlaunch.extra.ExtraListener;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.multirt.RTSpinnerAdapter;
import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.profiles.ProfileConstants;
import net.kdt.pojavlaunch.utils.*;
import net.kdt.pojavlaunch.value.PerVersionConfig;
@ -43,8 +44,8 @@ public class RefreshVersionListTask extends AsyncTask<Void, Void, ArrayList<Stri
Log.i("ExtVL", "Syncing to external: " + url);
list = Tools.GLOBAL_GSON.fromJson(DownloadUtils.downloadString(url), JMinecraftVersionList.class);
Log.i("ExtVL","Downloaded the version list, len="+list.versions.length);
if(list.latest != null && ExtraCore.getValue("release_table") == null)
ExtraCore.setValue("release_table",list.latest);
if(list.latest != null && ExtraCore.getValue(ProfileConstants.RELEASE_TABLE) == null)
ExtraCore.setValue(ProfileConstants.RELEASE_TABLE,list.latest);
Collections.addAll(versions,list.versions);
}
mActivity.mVersionList = new JMinecraftVersionList();
@ -64,7 +65,7 @@ public class RefreshVersionListTask extends AsyncTask<Void, Void, ArrayList<Stri
protected void onPostExecute(ArrayList<String> result)
{
super.onPostExecute(result);
ExtraCore.setValue("lac_version_list",result);
ExtraCore.setValue(ProfileConstants.VERSION_LIST,result);
}
private ArrayList<String> filter(JMinecraftVersionList.Version[] list1, File[] list2) {