two step api installation
This commit is contained in:
parent
5eae48377e
commit
97c0774786
|
@ -2,6 +2,7 @@ package com.tungsten.fclcore.download;
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
@ -34,13 +35,16 @@ public class ProcessService extends Service {
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
String[] command = intent.getExtras().getStringArray("command");
|
String[] command = intent.getExtras().getStringArray("command");
|
||||||
|
boolean first = intent.getExtras().getBoolean("first");
|
||||||
|
String jre = first ? "jre8" : "jre17";
|
||||||
FCLConfig config = new FCLConfig(
|
FCLConfig config = new FCLConfig(
|
||||||
getApplicationContext(),
|
getApplicationContext(),
|
||||||
getApplicationContext().getExternalFilesDir("log").getAbsolutePath(),
|
Environment.getExternalStorageDirectory().getAbsolutePath() + "/FCL/log",
|
||||||
getApplicationContext().getDir("runtime", 0).getAbsolutePath() + "/java/jre8",
|
getApplicationContext().getDir("runtime", 0).getAbsolutePath() + "/java/" + jre,
|
||||||
getApplicationContext().getCacheDir() + "/fclauncher",
|
getApplicationContext().getCacheDir() + "/fclauncher",
|
||||||
null,
|
null,
|
||||||
command);
|
command
|
||||||
|
);
|
||||||
startProcess(config);
|
startProcess(config);
|
||||||
return super.onStartCommand(intent, flags, startId);
|
return super.onStartCommand(intent, flags, startId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,27 @@ public class ForgeNewInstallTask extends Task<Version> {
|
||||||
|
|
||||||
command.addAll(args);
|
command.addAll(args);
|
||||||
|
|
||||||
|
runJVMProcess(processor, command, true);
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : outputs.entrySet()) {
|
||||||
|
Path artifact = Paths.get(entry.getKey());
|
||||||
|
if (!Files.isRegularFile(artifact))
|
||||||
|
throw new FileNotFoundException("File missing: " + artifact);
|
||||||
|
|
||||||
|
String code;
|
||||||
|
try (InputStream stream = Files.newInputStream(artifact)) {
|
||||||
|
code = DigestUtils.digestToString("SHA-1", stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Objects.equals(code, entry.getValue())) {
|
||||||
|
Files.delete(artifact);
|
||||||
|
throw new ChecksumMismatchException("SHA-1", entry.getValue(), code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runJVMProcess(ForgeNewInstallProfile.Processor processor, List<String> command, boolean first) throws Exception {
|
||||||
LOG.info("Executing external processor " + processor.getJar().toString() + ", command line: " + new CommandBuilder().addAll(command).toString());
|
LOG.info("Executing external processor " + processor.getJar().toString() + ", command line: " + new CommandBuilder().addAll(command).toString());
|
||||||
int exitCode;
|
int exitCode;
|
||||||
boolean listen = true;
|
boolean listen = true;
|
||||||
|
@ -179,23 +200,11 @@ public class ForgeNewInstallTask extends Task<Version> {
|
||||||
server.start();
|
server.start();
|
||||||
latch.await();
|
latch.await();
|
||||||
exitCode = Integer.parseInt((String) server.getResult());
|
exitCode = Integer.parseInt((String) server.getResult());
|
||||||
if (exitCode != 0)
|
if (exitCode != 0) {
|
||||||
|
if (first) {
|
||||||
|
runJVMProcess(processor, command, false);
|
||||||
|
} else {
|
||||||
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : outputs.entrySet()) {
|
|
||||||
Path artifact = Paths.get(entry.getKey());
|
|
||||||
if (!Files.isRegularFile(artifact))
|
|
||||||
throw new FileNotFoundException("File missing: " + artifact);
|
|
||||||
|
|
||||||
String code;
|
|
||||||
try (InputStream stream = Files.newInputStream(artifact)) {
|
|
||||||
code = DigestUtils.digestToString("SHA-1", stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Objects.equals(code, entry.getValue())) {
|
|
||||||
Files.delete(artifact);
|
|
||||||
throw new ChecksumMismatchException("SHA-1", entry.getValue(), code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,27 @@ public class NeoForgeOldInstallTask extends Task<Version> {
|
||||||
|
|
||||||
command.addAll(args);
|
command.addAll(args);
|
||||||
|
|
||||||
|
runJVMProcess(processor, command, true);
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : outputs.entrySet()) {
|
||||||
|
Path artifact = Paths.get(entry.getKey());
|
||||||
|
if (!Files.isRegularFile(artifact))
|
||||||
|
throw new FileNotFoundException("File missing: " + artifact);
|
||||||
|
|
||||||
|
String code;
|
||||||
|
try (InputStream stream = Files.newInputStream(artifact)) {
|
||||||
|
code = DigestUtils.digestToString("SHA-1", stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Objects.equals(code, entry.getValue())) {
|
||||||
|
Files.delete(artifact);
|
||||||
|
throw new ChecksumMismatchException("SHA-1", entry.getValue(), code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runJVMProcess(ForgeNewInstallProfile.Processor processor, List<String> command, boolean first) throws Exception {
|
||||||
LOG.info("Executing external processor " + processor.getJar().toString() + ", command line: " + new CommandBuilder().addAll(command).toString());
|
LOG.info("Executing external processor " + processor.getJar().toString() + ", command line: " + new CommandBuilder().addAll(command).toString());
|
||||||
int exitCode;
|
int exitCode;
|
||||||
boolean listen = true;
|
boolean listen = true;
|
||||||
|
@ -175,28 +196,17 @@ public class NeoForgeOldInstallTask extends Task<Version> {
|
||||||
Intent service = new Intent(FCLPath.CONTEXT, ProcessService.class);
|
Intent service = new Intent(FCLPath.CONTEXT, ProcessService.class);
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putStringArray("command", command.toArray(new String[0]));
|
bundle.putStringArray("command", command.toArray(new String[0]));
|
||||||
|
bundle.putBoolean("first", first);
|
||||||
service.putExtras(bundle);
|
service.putExtras(bundle);
|
||||||
FCLPath.CONTEXT.startService(service);
|
FCLPath.CONTEXT.startService(service);
|
||||||
server.start();
|
server.start();
|
||||||
latch.await();
|
latch.await();
|
||||||
exitCode = Integer.parseInt((String) server.getResult());
|
exitCode = Integer.parseInt((String) server.getResult());
|
||||||
if (exitCode != 0)
|
if (exitCode != 0) {
|
||||||
|
if (first) {
|
||||||
|
runJVMProcess(processor, command, false);
|
||||||
|
} else {
|
||||||
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : outputs.entrySet()) {
|
|
||||||
Path artifact = Paths.get(entry.getKey());
|
|
||||||
if (!Files.isRegularFile(artifact))
|
|
||||||
throw new FileNotFoundException("File missing: " + artifact);
|
|
||||||
|
|
||||||
String code;
|
|
||||||
try (InputStream stream = Files.newInputStream(artifact)) {
|
|
||||||
code = DigestUtils.digestToString("SHA-1", stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Objects.equals(code, entry.getValue())) {
|
|
||||||
Files.delete(artifact);
|
|
||||||
throw new ChecksumMismatchException("SHA-1", entry.getValue(), code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,29 +160,7 @@ public final class OptiFineInstallTask extends Task<Version> {
|
||||||
dest.toString(),
|
dest.toString(),
|
||||||
gameRepository.getLibraryFile(version, optiFineLibrary).toString()
|
gameRepository.getLibraryFile(version, optiFineLibrary).toString()
|
||||||
};
|
};
|
||||||
int exitCode;
|
runJVMProcess(command, true);
|
||||||
boolean listen = true;
|
|
||||||
while (listen) {
|
|
||||||
if (((ActivityManager) FCLPath.CONTEXT.getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses().size() == 1) {
|
|
||||||
listen = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
SocketServer server = new SocketServer("127.0.0.1", ProcessService.PROCESS_SERVICE_PORT, (server1, msg) -> {
|
|
||||||
server1.setResult(msg);
|
|
||||||
server1.stop();
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
Intent service = new Intent(FCLPath.CONTEXT, ProcessService.class);
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putStringArray("command", command);
|
|
||||||
service.putExtras(bundle);
|
|
||||||
FCLPath.CONTEXT.startService(service);
|
|
||||||
server.start();
|
|
||||||
latch.await();
|
|
||||||
exitCode = Integer.parseInt((String) server.getResult());
|
|
||||||
if (exitCode != 0)
|
|
||||||
throw new IOException("OptiFine patcher failed, command: " + new CommandBuilder().addAll(Arrays.asList(command)));
|
|
||||||
} else {
|
} else {
|
||||||
FileUtils.copyFile(dest, gameRepository.getLibraryFile(version, optiFineLibrary).toPath());
|
FileUtils.copyFile(dest, gameRepository.getLibraryFile(version, optiFineLibrary).toPath());
|
||||||
}
|
}
|
||||||
|
@ -244,6 +222,37 @@ public final class OptiFineInstallTask extends Task<Version> {
|
||||||
dependencies.add(dependencyManager.checkLibraryCompletionAsync(getResult(), true));
|
dependencies.add(dependencyManager.checkLibraryCompletionAsync(getResult(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runJVMProcess(String[] command, boolean first) throws Exception {
|
||||||
|
int exitCode;
|
||||||
|
boolean listen = true;
|
||||||
|
while (listen) {
|
||||||
|
if (((ActivityManager) FCLPath.CONTEXT.getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses().size() == 1) {
|
||||||
|
listen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
SocketServer server = new SocketServer("127.0.0.1", ProcessService.PROCESS_SERVICE_PORT, (server1, msg) -> {
|
||||||
|
server1.setResult(msg);
|
||||||
|
server1.stop();
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
|
Intent service = new Intent(FCLPath.CONTEXT, ProcessService.class);
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putStringArray("command", command);
|
||||||
|
service.putExtras(bundle);
|
||||||
|
FCLPath.CONTEXT.startService(service);
|
||||||
|
server.start();
|
||||||
|
latch.await();
|
||||||
|
exitCode = Integer.parseInt((String) server.getResult());
|
||||||
|
if (exitCode != 0) {
|
||||||
|
if (first) {
|
||||||
|
runJVMProcess(command, false);
|
||||||
|
} else {
|
||||||
|
throw new IOException("OptiFine patcher failed, command: " + new CommandBuilder().addAll(Arrays.asList(command)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install OptiFine library from existing local file.
|
* Install OptiFine library from existing local file.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue