mirror of
https://github.com/fumiama/android-base16384.git
synced 2026-06-06 10:40:30 +08:00
v3.1
1. 不使用压缩时字符串在内存直接编解码 2. 减少读取配置次数
This commit is contained in:
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
||||
2
.idea/dictionaries/rumia.xml
generated
2
.idea/dictionaries/rumia.xml
generated
@@ -1,8 +1,10 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="rumia">
|
||||
<words>
|
||||
<w>bufi</w>
|
||||
<w>cpubit</w>
|
||||
<w>fumiama</w>
|
||||
<w>lendat</w>
|
||||
<w>lzma</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
10
.idea/runConfigurations.xml
generated
Normal file
10
.idea/runConfigurations.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -12,8 +12,8 @@ android {
|
||||
applicationId "top.fumiama.base16384"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 13
|
||||
versionName '3.0.1'
|
||||
versionCode 14
|
||||
versionName '3.1'
|
||||
resConfigs "zh", "en"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -5,13 +5,13 @@
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "top.fumiama.base16384",
|
||||
"variantName": "processReleaseResources",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"versionCode": 13,
|
||||
"versionName": "3.0.1",
|
||||
"versionCode": 14,
|
||||
"versionName": "3.1",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.10.2)
|
||||
|
||||
project("base16384")
|
||||
SET(CMAKE_BUILD_TYPE "Release")
|
||||
|
||||
add_subdirectory(base14)
|
||||
add_subdirectory(lzma1900)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(base1432 VERSION 2.0)
|
||||
|
||||
add_library(base1432 ./base1432le.c)
|
||||
add_library(base14c STATIC base1432le.c)
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(base1464 VERSION 2.0)
|
||||
|
||||
add_library(base1464 ./base1464le.c)
|
||||
add_library(base14c STATIC base1464le.c)
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.10.2)
|
||||
|
||||
project("base16384")
|
||||
|
||||
add_library(base14 SHARED base16384.cpp)
|
||||
|
||||
add_library(base14c STATIC base16384.c)
|
||||
|
||||
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
add_definitions("-DCPUBIT64")
|
||||
add_subdirectory("./64")
|
||||
target_link_libraries(base14c base1464)
|
||||
ELSE()
|
||||
add_definitions("-DCPUBIT32")
|
||||
add_subdirectory("./32")
|
||||
target_link_libraries(base14c base1432)
|
||||
ENDIF()
|
||||
|
||||
target_link_libraries(base14 base14c)
|
||||
add_library(base14 SHARED base16384.cpp)
|
||||
add_library(base14s STATIC base16384.c)
|
||||
target_link_libraries(base14 base14s base14c)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <jni.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "base16384.h"
|
||||
#include <cstring>
|
||||
#include "base16384.hpp"
|
||||
|
||||
#define execute(function){\
|
||||
const char *inputFileDir = env->GetStringUTFChars(sf, JNI_FALSE);\
|
||||
@@ -12,11 +13,26 @@
|
||||
return re;\
|
||||
}
|
||||
|
||||
extern "C" int encode_file(const char* input, const char* output);
|
||||
extern "C" int decode_file(const char* input, const char* output);
|
||||
#define exe_byte(fun) {\
|
||||
uint32_t len = env->GetArrayLength(buf);\
|
||||
const uint8_t* data = (uint8_t*)env->GetByteArrayElements(buf, JNI_FALSE);\
|
||||
LENDAT* ld = fun(data, len);\
|
||||
jbyteArray out = env->NewByteArray(ld->len);\
|
||||
auto out_data = env->GetByteArrayElements(out, JNI_FALSE);\
|
||||
memcpy(out_data, ld->data, ld->len);\
|
||||
free(ld);\
|
||||
env->ReleaseByteArrayElements(out, out_data, JNI_COMMIT);\
|
||||
return out;\
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT int JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_encode(JNIEnv* env, jobject, jstring sf, jstring df) execute(encode_file)
|
||||
|
||||
extern "C" JNIEXPORT int JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode_file)
|
||||
Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode_file)
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_encodeByteArray(JNIEnv* env, jobject, jbyteArray buf) exe_byte(encode)
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_decodeByteArray(JNIEnv* env, jobject, jbyteArray buf) exe_byte(decode)
|
||||
40
app/src/main/cpp/base14/base16384.hpp
Normal file
40
app/src/main/cpp/base14/base16384.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// Created by fumiama on 2021/5/20.
|
||||
//
|
||||
|
||||
#ifndef BASE16384_BASE16384_HPP
|
||||
#define BASE16384_BASE16384_HPP
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef CPUBIT32
|
||||
#ifndef CPUBIT64
|
||||
#define CPUBIT32
|
||||
#endif
|
||||
#endif
|
||||
#ifdef CPUBIT32
|
||||
#define B14BUFSIZ 8192
|
||||
struct LENDAT {
|
||||
uint8_t* data;
|
||||
uint32_t len;
|
||||
};
|
||||
typedef struct LENDAT LENDAT;
|
||||
|
||||
extern "C" LENDAT* encode(const uint8_t* data, const u_int32_t len);
|
||||
extern "C" LENDAT* decode(const uint8_t* data, const u_int32_t len);
|
||||
#endif
|
||||
#ifdef CPUBIT64
|
||||
#define B14BUFSIZ 16384
|
||||
struct LENDAT {
|
||||
uint8_t* data;
|
||||
uint64_t len;
|
||||
};
|
||||
typedef struct LENDAT LENDAT;
|
||||
|
||||
extern "C" LENDAT* encode(const uint8_t* data, const u_int64_t len);
|
||||
extern "C" LENDAT* decode(const uint8_t* data, const u_int64_t len);
|
||||
#endif
|
||||
|
||||
extern "C" int encode_file(const char* input, const char* output);
|
||||
extern "C" int decode_file(const char* input, const char* output);
|
||||
|
||||
#endif //BASE16384_BASE16384_HPP
|
||||
@@ -1,5 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.10.2)
|
||||
|
||||
project("base16384")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_7ZIP_ST")
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.content.Intent
|
||||
import android.graphics.Rect
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Switch
|
||||
@@ -156,15 +158,23 @@ class MainActivity : Activity() {
|
||||
val tou = if(isEncode)tde else ten
|
||||
tin.text?.let {
|
||||
if(it.isNotEmpty()){
|
||||
val inputFile = generateCacheFile("input")
|
||||
val outputFile = generateCacheFile("output")
|
||||
|
||||
inputFile.writeText(it.toString(), getCharset(getCustomCharsetPosition(isEncode, pc)))
|
||||
val re = base16(isEncode, inputFile.absolutePath, outputFile.absolutePath)
|
||||
runOnUiThread {
|
||||
tou.setText(outputFile.readText(getCharset(getCustomCharsetPosition(!isEncode, pc))))
|
||||
copyText(tou, cm)
|
||||
if(re != "") Toast.makeText(this, re, Toast.LENGTH_SHORT).show()
|
||||
if(sl.isChecked) {
|
||||
val inputFile = generateCacheFile("input")
|
||||
val outputFile = generateCacheFile("output")
|
||||
|
||||
inputFile.writeText(it.toString(), getCharset(getCustomCharsetPosition(isEncode, pc)))
|
||||
val re = base16(isEncode, inputFile.absolutePath, outputFile.absolutePath)
|
||||
runOnUiThread {
|
||||
tou.setText(outputFile.readText(getCharset(getCustomCharsetPosition(!isEncode, pc))))
|
||||
copyText(tou, cm)
|
||||
if(re != "") Toast.makeText(this, re, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} else {
|
||||
val re = base16(isEncode, it.toString().toByteArray(getCharset(getCustomCharsetPosition(isEncode, pc))))
|
||||
if(re.isNotEmpty()) runOnUiThread {
|
||||
tou.setText(re.toString(getCharset(getCustomCharsetPosition(!isEncode, pc))))
|
||||
copyText(tou, cm)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,6 +195,8 @@ class MainActivity : Activity() {
|
||||
return re
|
||||
}
|
||||
|
||||
private fun base16(isEncode: Boolean, input: ByteArray) = if(isEncode) encodeByteArray(input) else decodeByteArray(input)
|
||||
|
||||
private fun base16384(isEncode: Boolean, sf: String, of: String): Int = if(isEncode) encode(sf, of) else decode(sf, of)
|
||||
|
||||
private fun setViewsVisibility(){
|
||||
@@ -246,6 +258,8 @@ class MainActivity : Activity() {
|
||||
*/
|
||||
private external fun encode(sf: String, df: String): Int
|
||||
private external fun decode(sf: String, df: String): Int
|
||||
private external fun encodeByteArray(buf: ByteArray): ByteArray
|
||||
private external fun decodeByteArray(buf: ByteArray): ByteArray
|
||||
private external fun lzma(sf: String, df: String, isEncode: Boolean): String
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -7,45 +7,55 @@ import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
class PropertiesTools(private val f: File):Properties() {
|
||||
private val propfile:File
|
||||
get() {
|
||||
private var cache = hashMapOf<String, String>()
|
||||
|
||||
init {
|
||||
if(!f.exists()) {
|
||||
if(f.parentFile?.exists() != true) f.parentFile?.mkdirs()
|
||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||
createNew(f)
|
||||
}else if(f.isDirectory) {
|
||||
} else if(f.isDirectory) {
|
||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||
f.delete()
|
||||
createNew(f)
|
||||
}
|
||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||
if(f.parentFile?.canRead() != true) f.parentFile?.setReadable(true)
|
||||
return f
|
||||
}
|
||||
private fun createNew(f: File){
|
||||
|
||||
private fun createNew(f: File) {
|
||||
f.createNewFile()
|
||||
val o = f.outputStream()
|
||||
this.storeToXML(o, "store")
|
||||
Log.d("MyPT", "Generate new prop.")
|
||||
o.close()
|
||||
}
|
||||
|
||||
private fun loadFromXml(`in`: InputStream?): PropertiesTools {
|
||||
this.loadFromXML(`in`)
|
||||
return this
|
||||
}
|
||||
|
||||
private fun setProp(key: String?, value: String?): PropertiesTools {
|
||||
this.setProperty(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
operator fun get(key: String): String{
|
||||
val i = propfile.inputStream()
|
||||
val re = this.loadFromXml(i).getProperty(key)?:"null"
|
||||
Log.d("MyPT", "Get $key = $re")
|
||||
i.close()
|
||||
return re
|
||||
return if(cache.containsKey(key)) cache[key]?:"null"
|
||||
else {
|
||||
val i = f.inputStream()
|
||||
val re = this.loadFromXml(i).getProperty(key)?:"null"
|
||||
Log.d("MyPT", "Read $key = $re")
|
||||
i.close()
|
||||
cache[key] = re
|
||||
re
|
||||
}
|
||||
}
|
||||
operator fun set(key: String, value: String){
|
||||
val o = propfile.outputStream()
|
||||
|
||||
operator fun set(key: String, value: String) {
|
||||
cache[key] = value
|
||||
val o = f.outputStream()
|
||||
this.setProp(key, value).storeToXML(o, "store")
|
||||
Log.d("MyPT", "Set $key = $value")
|
||||
o.close()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.4.32'
|
||||
ext.kotlin_version = '1.5.0'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
@@ -8,7 +8,7 @@ buildscript {
|
||||
maven { url 'https://maven.google.com' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.3'
|
||||
classpath 'com.android.tools.build:gradle:4.2.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
//classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.20'
|
||||
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip
|
||||
|
||||
Reference in New Issue
Block a user