Skip to content

Commit

Permalink
Feat[bta_profile]: add the ability to install nightlies
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Feb 4, 2025
1 parent 2401262 commit 61c8e57
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import java.util.ListIterator;

public class BTAUtils {
private static final String BTA_CLIENT_URL = "https://downloads.betterthanadventure.net/bta-client/release/%s/client.jar";
private static final String BTA_ICON_URL = "https://downloads.betterthanadventure.net/bta-client/release/%s/auto/%s.png";
private static final String BTA_CLIENT_URL = "https://downloads.betterthanadventure.net/bta-client/%s/%s/client.jar";
private static final String BTA_ICON_URL = "https://downloads.betterthanadventure.net/bta-client/%s/%s/auto/%s.png";
private static final List<String> BTA_TESTED_VERSIONS = new ArrayList<>();
static {
BTA_TESTED_VERSIONS.add("v7.3");
Expand All @@ -27,26 +27,33 @@ public class BTAUtils {
BTA_TESTED_VERSIONS.add("v7.1");
}

private static String getIconUrl(String version) {
String versionUnderscore = version.replace('.','_');
return String.format(BTA_ICON_URL, version, versionUnderscore);
private static String getIconUrl(String version, String buildType) {
String iconName = version.replace('.','_');
if(buildType.equals("nightly")) iconName = "v"+iconName;
return String.format(BTA_ICON_URL, buildType, version, iconName);
}

private static List<BTAVersion> createVersionList(List<String> versionStrings) {
private static List<BTAVersion> createVersionList(List<String> versionStrings, String buildType) {
ListIterator<String> iterator = versionStrings.listIterator(versionStrings.size());
ArrayList<BTAVersion> btaVersions = new ArrayList<>(versionStrings.size());
while(iterator.hasPrevious()) {
String version = iterator.previous();
if(version == null) continue;
btaVersions.add(new BTAVersion(
version,
String.format(BTA_CLIENT_URL, version),
getIconUrl(version)
String.format(BTA_CLIENT_URL, buildType, version),
getIconUrl(version, buildType)
));
}
btaVersions.trimToSize();
return btaVersions;
}

private static List<BTAVersion> processNightliesJson(String nightliesInfo) throws JsonParseException {
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(nightliesInfo, BTAVersionsManifest.class);
return createVersionList(manifest.versions, "nightly");
}

private static BTAVersionList processReleasesJson(String releasesInfo) throws JsonParseException {
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(releasesInfo, BTAVersionsManifest.class);
List<String> stringVersions = manifest.versions;
Expand All @@ -62,16 +69,21 @@ private static BTAVersionList processReleasesJson(String releasesInfo) throws Js
}

return new BTAVersionList(
createVersionList(testedVersions),
createVersionList(untestedVersions)
createVersionList(testedVersions, "release"),
createVersionList(untestedVersions, "release"),
null
);
}

public static BTAVersionList downloadVersionList() throws IOException {
try {
return DownloadUtils.downloadStringCached(
BTAVersionList releases = DownloadUtils.downloadStringCached(
"https://downloads.betterthanadventure.net/bta-client/release/versions.json",
"bta_releases", BTAUtils::processReleasesJson);
List<BTAVersion> nightlies = DownloadUtils.downloadStringCached(
"https://downloads.betterthanadventure.net/bta-client/nightly/versions.json",
"bta_nightlies", BTAUtils::processNightliesJson);
return new BTAVersionList(releases.testedVersions, releases.untestedVersions, nightlies);
}catch (DownloadUtils.ParseException e) {
Log.e("BTAUtils", "Failed to process json", e);
return null;
Expand Down Expand Up @@ -100,10 +112,12 @@ public BTAVersion(String versionName, String downloadUrl, String iconUrl) {
public static class BTAVersionList {
public final List<BTAVersion> testedVersions;
public final List<BTAVersion> untestedVersions;
public final List<BTAVersion> nightlyVersions;

public BTAVersionList(List<BTAVersion> mTestedVersions, List<BTAVersion> mUntestedVersions) {
public BTAVersionList(List<BTAVersion> mTestedVersions, List<BTAVersion> mUntestedVersions, List<BTAVersion> nightlyVersions) {
this.testedVersions = mTestedVersions;
this.untestedVersions = mUntestedVersions;
this.nightlyVersions = nightlyVersions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public BTAVersionListAdapter(BTAUtils.BTAVersionList versionList, LayoutInflater
mGroupNames.add(context.getString(R.string.bta_installer_untested_versions));
mGroups.add(versionList.untestedVersions);
}
if(!versionList.nightlyVersions.isEmpty()) {
mGroupNames.add(context.getString(R.string.bta_installer_nightly_versions));
mGroups.add(versionList.nightlyVersions);
}
mGroupNames.trimToSize();
mGroups.trimToSize();
}
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 @@ -428,4 +428,5 @@
<string name="select_bta_version">Select \"Better than Adventure!\" version</string>
<string name="bta_installer_available_versions">Supported BTA versions</string>
<string name="bta_installer_untested_versions">Untested BTA versions</string>
<string name="bta_installer_nightly_versions">Nightly BTA versions</string>
</resources>

0 comments on commit 61c8e57

Please sign in to comment.