mirror of
https://github.com/fumiama/android-base16384.git
synced 2026-06-09 20:40:34 +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"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<bytecodeTargetLevel target="1.8" />
|
<bytecodeTargetLevel target="11" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
2
.idea/dictionaries/rumia.xml
generated
2
.idea/dictionaries/rumia.xml
generated
@@ -1,8 +1,10 @@
|
|||||||
<component name="ProjectDictionaryState">
|
<component name="ProjectDictionaryState">
|
||||||
<dictionary name="rumia">
|
<dictionary name="rumia">
|
||||||
<words>
|
<words>
|
||||||
|
<w>bufi</w>
|
||||||
<w>cpubit</w>
|
<w>cpubit</w>
|
||||||
<w>fumiama</w>
|
<w>fumiama</w>
|
||||||
|
<w>lendat</w>
|
||||||
<w>lzma</w>
|
<w>lzma</w>
|
||||||
</words>
|
</words>
|
||||||
</dictionary>
|
</dictionary>
|
||||||
|
|||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<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"
|
applicationId "top.fumiama.base16384"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 13
|
versionCode 14
|
||||||
versionName '3.0.1'
|
versionName '3.1'
|
||||||
resConfigs "zh", "en"
|
resConfigs "zh", "en"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.10.2)
|
cmake_minimum_required(VERSION 3.10.2)
|
||||||
|
|
||||||
project("base16384")
|
project("base16384")
|
||||||
|
SET(CMAKE_BUILD_TYPE "Release")
|
||||||
|
|
||||||
add_subdirectory(base14)
|
add_subdirectory(base14)
|
||||||
add_subdirectory(lzma1900)
|
add_subdirectory(lzma1900)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.0)
|
cmake_minimum_required(VERSION 3.0.0)
|
||||||
project(base1432 VERSION 2.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)
|
cmake_minimum_required(VERSION 3.0.0)
|
||||||
project(base1464 VERSION 2.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)
|
cmake_minimum_required(VERSION 3.10.2)
|
||||||
|
|
||||||
project("base16384")
|
project("base16384")
|
||||||
|
|
||||||
add_library(base14 SHARED base16384.cpp)
|
|
||||||
|
|
||||||
add_library(base14c STATIC base16384.c)
|
|
||||||
|
|
||||||
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
add_definitions("-DCPUBIT64")
|
add_definitions("-DCPUBIT64")
|
||||||
add_subdirectory("./64")
|
add_subdirectory("./64")
|
||||||
target_link_libraries(base14c base1464)
|
|
||||||
ELSE()
|
ELSE()
|
||||||
add_definitions("-DCPUBIT32")
|
add_definitions("-DCPUBIT32")
|
||||||
add_subdirectory("./32")
|
add_subdirectory("./32")
|
||||||
target_link_libraries(base14c base1432)
|
|
||||||
ENDIF()
|
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 <jni.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "base16384.h"
|
#include <cstring>
|
||||||
|
#include "base16384.hpp"
|
||||||
|
|
||||||
#define execute(function){\
|
#define execute(function){\
|
||||||
const char *inputFileDir = env->GetStringUTFChars(sf, JNI_FALSE);\
|
const char *inputFileDir = env->GetStringUTFChars(sf, JNI_FALSE);\
|
||||||
@@ -12,11 +13,26 @@
|
|||||||
return re;\
|
return re;\
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int encode_file(const char* input, const char* output);
|
#define exe_byte(fun) {\
|
||||||
extern "C" int decode_file(const char* input, const char* output);
|
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
|
extern "C" JNIEXPORT int JNICALL
|
||||||
Java_top_fumiama_base16384_MainActivity_encode(JNIEnv* env, jobject, jstring sf, jstring df) execute(encode_file)
|
Java_top_fumiama_base16384_MainActivity_encode(JNIEnv* env, jobject, jstring sf, jstring df) execute(encode_file)
|
||||||
|
|
||||||
extern "C" JNIEXPORT int JNICALL
|
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)
|
cmake_minimum_required(VERSION 3.10.2)
|
||||||
|
|
||||||
project("base16384")
|
project("base16384")
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_7ZIP_ST")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_7ZIP_ST")
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import android.content.Intent
|
|||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Base64
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.Switch
|
import android.widget.Switch
|
||||||
@@ -156,15 +158,23 @@ class MainActivity : Activity() {
|
|||||||
val tou = if(isEncode)tde else ten
|
val tou = if(isEncode)tde else ten
|
||||||
tin.text?.let {
|
tin.text?.let {
|
||||||
if(it.isNotEmpty()){
|
if(it.isNotEmpty()){
|
||||||
val inputFile = generateCacheFile("input")
|
if(sl.isChecked) {
|
||||||
val outputFile = generateCacheFile("output")
|
val inputFile = generateCacheFile("input")
|
||||||
|
val outputFile = generateCacheFile("output")
|
||||||
|
|
||||||
inputFile.writeText(it.toString(), getCharset(getCustomCharsetPosition(isEncode, pc)))
|
inputFile.writeText(it.toString(), getCharset(getCustomCharsetPosition(isEncode, pc)))
|
||||||
val re = base16(isEncode, inputFile.absolutePath, outputFile.absolutePath)
|
val re = base16(isEncode, inputFile.absolutePath, outputFile.absolutePath)
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
tou.setText(outputFile.readText(getCharset(getCustomCharsetPosition(!isEncode, pc))))
|
tou.setText(outputFile.readText(getCharset(getCustomCharsetPosition(!isEncode, pc))))
|
||||||
copyText(tou, cm)
|
copyText(tou, cm)
|
||||||
if(re != "") Toast.makeText(this, re, Toast.LENGTH_SHORT).show()
|
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
|
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 base16384(isEncode: Boolean, sf: String, of: String): Int = if(isEncode) encode(sf, of) else decode(sf, of)
|
||||||
|
|
||||||
private fun setViewsVisibility(){
|
private fun setViewsVisibility(){
|
||||||
@@ -246,6 +258,8 @@ class MainActivity : Activity() {
|
|||||||
*/
|
*/
|
||||||
private external fun encode(sf: String, df: String): Int
|
private external fun encode(sf: String, df: String): Int
|
||||||
private external fun decode(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
|
private external fun lzma(sf: String, df: String, isEncode: Boolean): String
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -7,45 +7,55 @@ import java.io.InputStream
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class PropertiesTools(private val f: File):Properties() {
|
class PropertiesTools(private val f: File):Properties() {
|
||||||
private val propfile:File
|
private var cache = hashMapOf<String, String>()
|
||||||
get() {
|
|
||||||
|
init {
|
||||||
if(!f.exists()) {
|
if(!f.exists()) {
|
||||||
if(f.parentFile?.exists() != true) f.parentFile?.mkdirs()
|
if(f.parentFile?.exists() != true) f.parentFile?.mkdirs()
|
||||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||||
createNew(f)
|
createNew(f)
|
||||||
}else if(f.isDirectory) {
|
} else if(f.isDirectory) {
|
||||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||||
f.delete()
|
f.delete()
|
||||||
createNew(f)
|
createNew(f)
|
||||||
}
|
}
|
||||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||||
if(f.parentFile?.canRead() != true) f.parentFile?.setReadable(true)
|
if(f.parentFile?.canRead() != true) f.parentFile?.setReadable(true)
|
||||||
return f
|
|
||||||
}
|
}
|
||||||
private fun createNew(f: File){
|
|
||||||
|
private fun createNew(f: File) {
|
||||||
f.createNewFile()
|
f.createNewFile()
|
||||||
val o = f.outputStream()
|
val o = f.outputStream()
|
||||||
this.storeToXML(o, "store")
|
this.storeToXML(o, "store")
|
||||||
Log.d("MyPT", "Generate new prop.")
|
Log.d("MyPT", "Generate new prop.")
|
||||||
o.close()
|
o.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadFromXml(`in`: InputStream?): PropertiesTools {
|
private fun loadFromXml(`in`: InputStream?): PropertiesTools {
|
||||||
this.loadFromXML(`in`)
|
this.loadFromXML(`in`)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setProp(key: String?, value: String?): PropertiesTools {
|
private fun setProp(key: String?, value: String?): PropertiesTools {
|
||||||
this.setProperty(key, value)
|
this.setProperty(key, value)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun get(key: String): String{
|
operator fun get(key: String): String{
|
||||||
val i = propfile.inputStream()
|
return if(cache.containsKey(key)) cache[key]?:"null"
|
||||||
val re = this.loadFromXml(i).getProperty(key)?:"null"
|
else {
|
||||||
Log.d("MyPT", "Get $key = $re")
|
val i = f.inputStream()
|
||||||
i.close()
|
val re = this.loadFromXml(i).getProperty(key)?:"null"
|
||||||
return re
|
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")
|
this.setProp(key, value).storeToXML(o, "store")
|
||||||
Log.d("MyPT", "Set $key = $value")
|
Log.d("MyPT", "Set $key = $value")
|
||||||
o.close()
|
o.close()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.4.32'
|
ext.kotlin_version = '1.5.0'
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
@@ -8,7 +8,7 @@ buildscript {
|
|||||||
maven { url 'https://maven.google.com' }
|
maven { url 'https://maven.google.com' }
|
||||||
}
|
}
|
||||||
dependencies {
|
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 "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
//classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.20'
|
//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
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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