Skip to content

Commit

Permalink
💥 clean and finish Lagrange support
Browse files Browse the repository at this point in the history
  • Loading branch information
Szzrain committed Apr 1, 2024
1 parent 927a1fd commit b9e6eb2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 68 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
minSdk 26
//noinspection ExpiredTargetSdkVersion
targetSdk 28
versionCode 39
versionName "v0.6.1-dev"
versionCode 40
versionName "v0.6.1-rc1"
buildConfigField "String", "DOCUMENTS_AUTHORITY", "\"com.sealdice.dice.authorities\""
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
externalNativeBuild {
Expand Down Expand Up @@ -71,7 +71,6 @@ dependencies {
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.lifecycle:lifecycle-service:2.6.1'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'
implementation 'org.apache.commons:commons-compress:1.20'
api 'com.tencent.tbs:tbssdk:44286'
implementation 'androidx.core:core-ktx:1.10.0'
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/sealdice/dice/DebugActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.MenuItem
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -63,8 +64,6 @@ class DebugActivity : AppCompatActivity() {
val command = findViewById<EditText>(R.id.DEBUG_edittext_command).text.toString()
if (!isInit) {
processBuilder.directory(File(this.filesDir.absolutePath))
processBuilder.environment()["LD_LIBRARY_PATH"] = this.filesDir.absolutePath + "/sealdice/lagrange/openssl-1.1"
processBuilder.environment()["CLR_OPENSSL_VERSION_OVERRIDE"] = "1.1"

GlobalScope.launch(context = Dispatchers.IO) {
isRunning = true
Expand Down Expand Up @@ -186,6 +185,8 @@ class DebugActivity : AppCompatActivity() {
alertDialogBuilder.create().show()
}
findViewById<ImageView>(R.id.DEBUG_app_icon).setOnClickListener {
Toast.makeText(this, "海豹 + 1", Toast.LENGTH_SHORT).show()

it.animate().scaleX(1.2f).scaleY(1.2f).setDuration(100).withEndAction {
it.animate().scaleX(1f).scaleY(1f).setDuration(100).start()
}.start()
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/com/sealdice/dice/FirstFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class FirstFragment : Fragment() {
} else {
if (sharedPreferences?.getBoolean("extract_on_start", true) == true) {
ExtractAssets(context).extractResources("sealdice")
ExtractAssets(context).extractResources("runner")
DecompressUtil.decompressTar(FileWrite.getPrivateFileDir(requireContext())+"runner/app-runner-arm64.tar", FileWrite.getPrivateFileDir(requireContext())+"runner/")
ExtractAssets(context).extractResource("app-runner-arm64.tar")
DecompressUtil.decompressTarSys(FileWrite.getPrivateFileDir(requireContext())+"app-runner-arm64.tar", FileWrite.getPrivateFileDir(requireContext())+"runner/")
}
binding.buttonTut.visibility = View.GONE
binding.buttonInput.visibility = View.GONE
Expand All @@ -174,10 +174,18 @@ class FirstFragment : Fragment() {
this.activity?.let { it1 -> ActivityCompat.requestPermissions(it1, arrayOf(Manifest.permission.FOREGROUND_SERVICE), 1) }
}
}
launchAliveService(context)

GlobalScope.launch(context = Dispatchers.IO) {
for (i in 0..10) {
for (i in 0..5) {
withContext(Dispatchers.Main) {
binding.textviewFirst.text = "正在启动...\n请等待${10 - i}s..."
}
Thread.sleep(1000)
}
withContext(Dispatchers.Main){
launchAliveService(context)
}
for (i in 5..10) {
withContext(Dispatchers.Main) {
binding.textviewFirst.text = "正在启动...\n请等待${10 - i}s..."
}
Expand All @@ -186,6 +194,7 @@ class FirstFragment : Fragment() {
withContext(Dispatchers.Main){
binding.textviewFirst.text = "启动完成(或者失败)"
}

if (sharedPreferences?.getBoolean("auto_launch_ui", true) == true) {
val address = sharedPreferences.getString("ui_address", "http://127.0.0.1:3211")
if (sharedPreferences.getBoolean("use_internal_webview", true)) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/sealdice/dice/JNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
final class JNI {

static {
System.loadLibrary("sealjni");
System.loadLibrary("seal");
}

/**
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/sealdice/dice/ProcessService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,7 @@ class ProcessService : LifecycleService(){
processBuilder.environment()["PATH"] = "${this.filesDir.absolutePath}/sealdice"
}
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
processBuilder.environment()["LD_LIBRARY_PATH"] = this.filesDir.absolutePath + sharedPreferences.getString("ld_library_path", "/sealdice/lagrange/openssl-1.1")
processBuilder.environment()["CLR_OPENSSL_VERSION_OVERRIDE"] = "1.1"
processBuilder.environment()["RUNNER_PATH"] = this.filesDir.absolutePath + "/runner"
// var env = arrayOf("LD_LIBRARY_PATH=${this.filesDir.absolutePath + sharedPreferences.getString("ld_library_path", "/sealdice/lagrange/openssl-1.1")}", "CLR_OPENSSL_VERSION_OVERRIDE=1.1")
process = processBuilder.start()
val args = sharedPreferences.getString("launch_args", "")
val cmd = "cd sealdice&&./sealdice-core $args"
Expand Down
68 changes: 19 additions & 49 deletions app/src/main/java/com/sealdice/dice/utils/DecompressUtil.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,30 @@
package com.sealdice.dice.utils;

import android.util.Log;

import java.io.*;
import java.nio.file.*;
import java.util.zip.GZIPInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;

public class DecompressUtil {


public static void decompressTar(String tarFilePath, String outputDir) throws IOException {
try (FileInputStream fis = new FileInputStream(tarFilePath);
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(fis)) {
org.apache.commons.compress.archivers.tar.TarArchiveEntry entry;

while ((entry = (org.apache.commons.compress.archivers.tar.TarArchiveEntry) tarArchiveInputStream.getNextEntry()) != null) {
final String individualFile = outputDir + File.separator + entry.getName();
final File file = new File(individualFile);

if (entry.isDirectory()) {
if (!file.exists()) {
file.mkdirs();
}
} else {
int count;
byte[] data = new byte[1024];
FileOutputStream fos = new FileOutputStream(individualFile, false);
try (BufferedOutputStream dest = new BufferedOutputStream(fos, 1024)) {
while ((count = tarArchiveInputStream.read(data, 0, 1024)) != -1) {
dest.write(data, 0, count);
}
}
}
}
}
}

public static void decompressTarGz(String tarGzFilePath, String outputDir) throws IOException {
try (GZIPInputStream gis = new GZIPInputStream(Files.newInputStream(Paths.get(tarGzFilePath)));
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gis)) {
org.apache.commons.compress.archivers.tar.TarArchiveEntry entry;

while ((entry = (org.apache.commons.compress.archivers.tar.TarArchiveEntry) tarArchiveInputStream.getNextEntry()) != null) {
final Path outputPath = Paths.get(outputDir, entry.getName());

if (entry.isDirectory()) {
Files.createDirectories(outputPath);
} else if (entry.isSymbolicLink()) {
// 对符号链接的处理
Path target = Paths.get(entry.getLinkName());
Files.createSymbolicLink(outputPath, target);
} else {
// 处理常规文件
Files.createDirectories(outputPath.getParent());
Files.copy(tarArchiveInputStream, outputPath, StandardCopyOption.REPLACE_EXISTING);
}
public static void decompressTarSys(String tarFilePath, String outputDir) throws IOException {
// make sure the output directory exists
ProcessBuilder pb = new ProcessBuilder("sh");
pb.redirectErrorStream(true);
Process p = pb.start();
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
bw.write("mkdir "+ outputDir + "&&tar xf " + tarFilePath + " -C " + outputDir + "\n");
Log.d("DecompressUtilSys", "tar xf " + tarFilePath + " -C " + outputDir);
bw.write("exit\n");
bw.flush();
p.waitFor();
String line;
while ((line = br.readLine()) != null) {
Log.d("DecompressUtilSys", line);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= libsealjni
LOCAL_MODULE:= libseal
LOCAL_SRC_FILES:= jni.c
include $(BUILD_SHARED_LIBRARY)
5 changes: 0 additions & 5 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@
android:title="启动参数"
android:summary="点击输入启动参数"
android:defaultValue="--address=0.0.0.0:3211" />
<androidx.preference.EditTextPreference
android:key="ld_library_path"
android:title="LD_LIBRARY_PATH"
android:summary="如果不清楚作用请不要更改"
android:defaultValue="/sealdice/lagrange/openssl-1.1" />

</androidx.preference.PreferenceCategory>
</PreferenceScreen>

0 comments on commit b9e6eb2

Please sign in to comment.