mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-12 22:26:56 -04:00
Fix[code]: fixes for stuff that i missed/additional validations
This commit is contained in:
parent
ae286fb57a
commit
e6af83b2e2
@ -125,7 +125,8 @@ public class LauncherActivity extends BaseActivity {
|
||||
}
|
||||
String normalizedVersionId = AsyncMinecraftDownloader.normalizeVersionId(prof.lastVersionId);
|
||||
JMinecraftVersionList.Version mcVersion = AsyncMinecraftDownloader.getListedVersion(normalizedVersionId);
|
||||
new AsyncMinecraftDownloader(this,
|
||||
new AsyncMinecraftDownloader().start(
|
||||
this,
|
||||
mcVersion,
|
||||
normalizedVersionId,
|
||||
new ContextAwareDoneListener(this, normalizedVersionId)
|
||||
@ -133,10 +134,10 @@ public class LauncherActivity extends BaseActivity {
|
||||
return false;
|
||||
};
|
||||
|
||||
private final TaskCountListener mDoubleLaunchPreventionListener = (tc)->{
|
||||
private final TaskCountListener mDoubleLaunchPreventionListener = taskCount -> {
|
||||
// Hide the notification that starts the game if there are tasks executing.
|
||||
// Prevents the user from trying to launch the game with tasks ongoing.
|
||||
if(tc > 0) {
|
||||
if(taskCount > 0) {
|
||||
Tools.runOnUiThread(() ->
|
||||
mNotificationManager.cancel(NotificationUtils.NOTIFICATION_ID_GAME_START)
|
||||
);
|
||||
|
@ -559,6 +559,7 @@ public final class Tools {
|
||||
private static void showError(final Context ctx, final int titleId, final String rolledMessage, final Throwable e, final boolean exitIfOk, final boolean showMore) {
|
||||
if(e instanceof ContextExecutorTask) {
|
||||
ContextExecutor.execute((ContextExecutorTask) e);
|
||||
return;
|
||||
}
|
||||
e.printStackTrace();
|
||||
|
||||
|
@ -14,6 +14,13 @@ import androidx.annotation.Nullable;
|
||||
// you to specify practically anything. So i made this instead.
|
||||
public class OpenDocumentWithExtension extends ActivityResultContract<Object, Uri> {
|
||||
private final String mimeType;
|
||||
|
||||
/**
|
||||
* Create a new OpenDocumentWithExtension contract.
|
||||
* If the extension provided to the constructor is not available in the device's MIME
|
||||
* type database, the filter will default to "all types"
|
||||
* @param extension the extension to filter by
|
||||
*/
|
||||
public OpenDocumentWithExtension(String extension) {
|
||||
String extensionMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||
if(extensionMimeType == null) extensionMimeType = "*/*";
|
||||
|
@ -53,6 +53,10 @@ public class DownloadMirror {
|
||||
DownloadUtils.downloadFileMonitored(urlInput, outputFile, buffer, monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current download source is a mirror and not an official source.
|
||||
* @return true if the source is a mirror, false otherwise
|
||||
*/
|
||||
public static boolean isMirrored() {
|
||||
return !LauncherPreferences.PREF_DOWNLOAD_SOURCE.equals("default");
|
||||
}
|
||||
@ -88,8 +92,14 @@ public class DownloadMirror {
|
||||
|
||||
private static int getBaseUrlTail(String wholeUrl) throws MalformedURLException{
|
||||
int protocolNameEnd = wholeUrl.indexOf("://");
|
||||
if(protocolNameEnd == -1) throw new MalformedURLException("No protocol");
|
||||
if(protocolNameEnd == -1)
|
||||
throw new MalformedURLException("No protocol, or non path-based URL");
|
||||
protocolNameEnd += 3;
|
||||
return wholeUrl.indexOf('/', protocolNameEnd);
|
||||
int hostnameEnd = wholeUrl.indexOf('/', protocolNameEnd);
|
||||
if(protocolNameEnd >= wholeUrl.length() || hostnameEnd == protocolNameEnd)
|
||||
throw new MalformedURLException("No hostname");
|
||||
if(hostnameEnd == -1) hostnameEnd = wholeUrl.length();
|
||||
System.out.println(protocolNameEnd +" "+ hostnameEnd);
|
||||
return hostnameEnd;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,12 @@ public class MirrorTamperedException extends Exception implements ContextExecuto
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(R.string.dl_tampered_manifest_title);
|
||||
builder.setMessage(Html.fromHtml(activity.getString(R.string.dl_tampered_manifest)));
|
||||
addButtons(builder);
|
||||
ShowErrorActivity.installRemoteDialogHandling(activity, builder);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void addButtons(AlertDialog.Builder builder) {
|
||||
builder.setPositiveButton(R.string.dl_switch_to_official_site,(d,w)->{
|
||||
LauncherPreferences.DEFAULT_PREF.edit().putString("downloadSource", "default").apply();
|
||||
LauncherPreferences.PREF_DOWNLOAD_SOURCE = "default";
|
||||
@ -28,8 +34,6 @@ public class MirrorTamperedException extends Exception implements ContextExecuto
|
||||
LauncherPreferences.PREF_VERIFY_MANIFEST = false;
|
||||
});
|
||||
builder.setNeutralButton(android.R.string.cancel, (d,w)->{});
|
||||
ShowErrorActivity.installRemoteDialogHandling(activity, builder);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,7 +88,7 @@ public class OptiFineDownloadTask implements Runnable, Tools.DownloaderFeedback,
|
||||
if(minecraftJsonVersion == null) return false;
|
||||
try {
|
||||
synchronized (mMinecraftDownloadLock) {
|
||||
new AsyncMinecraftDownloader(null, minecraftJsonVersion, minecraftVersion, this);
|
||||
new AsyncMinecraftDownloader().start(null, minecraftJsonVersion, minecraftVersion, this);
|
||||
mMinecraftDownloadLock.wait();
|
||||
}
|
||||
}catch (InterruptedException e) {
|
||||
|
@ -26,29 +26,37 @@ public class NotificationDownloadListener implements ModloaderDownloadListener {
|
||||
if(mModLoader.requiresGuiInstallation()) {
|
||||
ModloaderInstallTracker.saveModLoader(mContext, mModLoader, downloadedFile);
|
||||
Intent mainActivityIntent = new Intent(mContext, LauncherActivity.class);
|
||||
Tools.runOnUiThread(() -> NotificationUtils.sendBasicNotification(mContext,
|
||||
R.string.modpack_install_notification_title,
|
||||
R.string.modpack_install_notification_success,
|
||||
mainActivityIntent,
|
||||
NotificationUtils.PENDINGINTENT_CODE_DOWNLOAD_SERVICE,
|
||||
NotificationUtils.NOTIFICATION_ID_DOWNLOAD_LISTENER
|
||||
));
|
||||
sendIntentNotification(mainActivityIntent, R.string.modpack_install_notification_success);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataNotAvailable() {
|
||||
Tools.runOnUiThread(()->NotificationUtils.sendBasicNotification(mContext,
|
||||
R.string.modpack_install_notification_title,
|
||||
R.string.modpack_install_notification_success,
|
||||
null,
|
||||
NotificationUtils.PENDINGINTENT_CODE_DOWNLOAD_SERVICE,
|
||||
NotificationUtils.NOTIFICATION_ID_DOWNLOAD_LISTENER
|
||||
));
|
||||
sendEmptyNotification(R.string.modpack_install_notification_data_not_available);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadError(Exception e) {
|
||||
Tools.showErrorRemote(mContext, R.string.modpack_install_modloader_download_failed, e);
|
||||
}
|
||||
|
||||
private void sendIntentNotification(Intent intent, int localeString) {
|
||||
Tools.runOnUiThread(() -> NotificationUtils.sendBasicNotification(mContext,
|
||||
R.string.modpack_install_notification_title,
|
||||
localeString,
|
||||
intent,
|
||||
NotificationUtils.PENDINGINTENT_CODE_DOWNLOAD_SERVICE,
|
||||
NotificationUtils.NOTIFICATION_ID_DOWNLOAD_LISTENER
|
||||
));
|
||||
}
|
||||
|
||||
private void sendEmptyNotification(int localeString) {
|
||||
Tools.runOnUiThread(()->NotificationUtils.sendBasicNotification(mContext,
|
||||
R.string.modpack_install_notification_title,
|
||||
localeString,
|
||||
null,
|
||||
NotificationUtils.PENDINGINTENT_CODE_DOWNLOAD_SERVICE,
|
||||
NotificationUtils.NOTIFICATION_ID_DOWNLOAD_LISTENER
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,9 @@ public class AsyncMinecraftDownloader {
|
||||
/* Allows each downloading thread to have its own RECYCLED buffer */
|
||||
private final ConcurrentHashMap<Thread, byte[]> mThreadBuffers = new ConcurrentHashMap<>(5);
|
||||
|
||||
public AsyncMinecraftDownloader(Activity activity, JMinecraftVersionList.Version version, String realVersion,
|
||||
@NonNull DoneListener listener){ // this was there for a reason
|
||||
public void start(Activity activity, JMinecraftVersionList.Version version,
|
||||
String realVersion, // this was there for a reason
|
||||
@NonNull DoneListener listener) {
|
||||
sExecutorService.execute(() -> {
|
||||
try {
|
||||
downloadGame(activity, version, realVersion);
|
||||
@ -399,10 +400,10 @@ public class AsyncMinecraftDownloader {
|
||||
}
|
||||
|
||||
private boolean verifyManifest(File verJsonDir, JMinecraftVersionList.Version verInfo) {
|
||||
return /*verJsonDir.exists()
|
||||
return verJsonDir.exists()
|
||||
&& (!LauncherPreferences.PREF_CHECK_LIBRARY_SHA
|
||||
|| verInfo.sha1 == null
|
||||
|| Tools.compareSHA1(verJsonDir, verInfo.sha1));*/false;
|
||||
|| Tools.compareSHA1(verJsonDir, verInfo.sha1));
|
||||
}
|
||||
|
||||
public static String normalizeVersionId(String versionString) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user