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.content.Intent;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
|
||||
|
@ -34,13 +35,16 @@ public class ProcessService extends Service {
|
|||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
String[] command = intent.getExtras().getStringArray("command");
|
||||
boolean first = intent.getExtras().getBoolean("first");
|
||||
String jre = first ? "jre8" : "jre17";
|
||||
FCLConfig config = new FCLConfig(
|
||||
getApplicationContext(),
|
||||
getApplicationContext().getExternalFilesDir("log").getAbsolutePath(),
|
||||
getApplicationContext().getDir("runtime", 0).getAbsolutePath() + "/java/jre8",
|
||||
Environment.getExternalStorageDirectory().getAbsolutePath() + "/FCL/log",
|
||||
getApplicationContext().getDir("runtime", 0).getAbsolutePath() + "/java/" + jre,
|
||||
getApplicationContext().getCacheDir() + "/fclauncher",
|
||||
null,
|
||||
command);
|
||||
command
|
||||
);
|
||||
startProcess(config);
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
|
|
@ -157,30 +157,7 @@ public class ForgeNewInstallTask extends Task<Version> {
|
|||
|
||||
command.addAll(args);
|
||||
|
||||
LOG.info("Executing external processor " + processor.getJar().toString() + ", command line: " + new CommandBuilder().addAll(command).toString());
|
||||
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.toArray(new String[0]));
|
||||
service.putExtras(bundle);
|
||||
FCLPath.CONTEXT.startService(service);
|
||||
server.start();
|
||||
latch.await();
|
||||
exitCode = Integer.parseInt((String) server.getResult());
|
||||
if (exitCode != 0)
|
||||
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
||||
runJVMProcess(processor, command, true);
|
||||
|
||||
for (Map.Entry<String, String> entry : outputs.entrySet()) {
|
||||
Path artifact = Paths.get(entry.getKey());
|
||||
|
@ -200,6 +177,38 @@ public class ForgeNewInstallTask extends Task<Version> {
|
|||
}
|
||||
}
|
||||
|
||||
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());
|
||||
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.toArray(new String[0]));
|
||||
service.putExtras(bundle);
|
||||
FCLPath.CONTEXT.startService(service);
|
||||
server.start();
|
||||
latch.await();
|
||||
exitCode = Integer.parseInt((String) server.getResult());
|
||||
if (exitCode != 0) {
|
||||
if (first) {
|
||||
runJVMProcess(processor, command, false);
|
||||
} else {
|
||||
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final DefaultDependencyManager dependencyManager;
|
||||
private final DefaultGameRepository gameRepository;
|
||||
private final Version version;
|
||||
|
|
|
@ -158,30 +158,7 @@ public class NeoForgeOldInstallTask extends Task<Version> {
|
|||
|
||||
command.addAll(args);
|
||||
|
||||
LOG.info("Executing external processor " + processor.getJar().toString() + ", command line: " + new CommandBuilder().addAll(command).toString());
|
||||
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.toArray(new String[0]));
|
||||
service.putExtras(bundle);
|
||||
FCLPath.CONTEXT.startService(service);
|
||||
server.start();
|
||||
latch.await();
|
||||
exitCode = Integer.parseInt((String) server.getResult());
|
||||
if (exitCode != 0)
|
||||
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
||||
runJVMProcess(processor, command, true);
|
||||
|
||||
for (Map.Entry<String, String> entry : outputs.entrySet()) {
|
||||
Path artifact = Paths.get(entry.getKey());
|
||||
|
@ -201,6 +178,39 @@ public class NeoForgeOldInstallTask extends Task<Version> {
|
|||
}
|
||||
}
|
||||
|
||||
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());
|
||||
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.toArray(new String[0]));
|
||||
bundle.putBoolean("first", first);
|
||||
service.putExtras(bundle);
|
||||
FCLPath.CONTEXT.startService(service);
|
||||
server.start();
|
||||
latch.await();
|
||||
exitCode = Integer.parseInt((String) server.getResult());
|
||||
if (exitCode != 0) {
|
||||
if (first) {
|
||||
runJVMProcess(processor, command, false);
|
||||
} else {
|
||||
throw new IOException("Game processor exited abnormally with code " + exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final DefaultDependencyManager dependencyManager;
|
||||
private final DefaultGameRepository gameRepository;
|
||||
private final Version version;
|
||||
|
|
|
@ -160,29 +160,7 @@ public final class OptiFineInstallTask extends Task<Version> {
|
|||
dest.toString(),
|
||||
gameRepository.getLibraryFile(version, optiFineLibrary).toString()
|
||||
};
|
||||
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)
|
||||
throw new IOException("OptiFine patcher failed, command: " + new CommandBuilder().addAll(Arrays.asList(command)));
|
||||
runJVMProcess(command, true);
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue