From 8f5b970c69a512fa29aec5b62f88c72528db55ea Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 20 May 2021 17:00:16 +0800 Subject: [PATCH] =?UTF-8?q?v3.1=201.=20=E4=B8=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=8E=8B=E7=BC=A9=E6=97=B6=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=9C=A8?= =?UTF-8?q?=E5=86=85=E5=AD=98=E7=9B=B4=E6=8E=A5=E7=BC=96=E8=A7=A3=E7=A0=81?= =?UTF-8?q?=202.=20=E5=87=8F=E5=B0=91=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 2 +- .idea/dictionaries/rumia.xml | 2 + .idea/misc.xml | 2 +- .idea/runConfigurations.xml | 10 +++++ app/build.gradle | 4 +- app/src/main/cpp/CMakeLists.txt | 2 +- app/src/main/cpp/base14/32/CMakeLists.txt | 2 +- app/src/main/cpp/base14/64/CMakeLists.txt | 2 +- app/src/main/cpp/base14/CMakeLists.txt | 11 ++--- app/src/main/cpp/base14/base16384.cpp | 24 +++++++++-- app/src/main/cpp/base14/base16384.hpp | 40 +++++++++++++++++++ app/src/main/cpp/lzma1900/CMakeLists.txt | 1 - .../top/fumiama/base16384/MainActivity.kt | 32 ++++++++++----- .../base16384/tools/PropertiesTools.kt | 34 ++++++++++------ build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 16 files changed, 130 insertions(+), 44 deletions(-) create mode 100644 .idea/runConfigurations.xml create mode 100644 app/src/main/cpp/base14/base16384.hpp diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 61a9130..fb7f4a8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/dictionaries/rumia.xml b/.idea/dictionaries/rumia.xml index 095863d..f5bfa7b 100644 --- a/.idea/dictionaries/rumia.xml +++ b/.idea/dictionaries/rumia.xml @@ -1,8 +1,10 @@ + bufi cpubit fumiama + lendat lzma diff --git a/.idea/misc.xml b/.idea/misc.xml index d5d35ec..860da66 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index bf94616..8fea2ed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 070deb4..3c253b8 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) - project("base16384") +SET(CMAKE_BUILD_TYPE "Release") add_subdirectory(base14) add_subdirectory(lzma1900) diff --git a/app/src/main/cpp/base14/32/CMakeLists.txt b/app/src/main/cpp/base14/32/CMakeLists.txt index b8ccaac..5d04237 100644 --- a/app/src/main/cpp/base14/32/CMakeLists.txt +++ b/app/src/main/cpp/base14/32/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/app/src/main/cpp/base14/64/CMakeLists.txt b/app/src/main/cpp/base14/64/CMakeLists.txt index 8ee6dec..92ed70f 100644 --- a/app/src/main/cpp/base14/64/CMakeLists.txt +++ b/app/src/main/cpp/base14/64/CMakeLists.txt @@ -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) diff --git a/app/src/main/cpp/base14/CMakeLists.txt b/app/src/main/cpp/base14/CMakeLists.txt index 7bb5f86..3c60440 100644 --- a/app/src/main/cpp/base14/CMakeLists.txt +++ b/app/src/main/cpp/base14/CMakeLists.txt @@ -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) diff --git a/app/src/main/cpp/base14/base16384.cpp b/app/src/main/cpp/base14/base16384.cpp index 0784195..5020345 100644 --- a/app/src/main/cpp/base14/base16384.cpp +++ b/app/src/main/cpp/base14/base16384.cpp @@ -1,7 +1,8 @@ #include #include #include -#include "base16384.h" +#include +#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) \ No newline at end of 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) \ No newline at end of file diff --git a/app/src/main/cpp/base14/base16384.hpp b/app/src/main/cpp/base14/base16384.hpp new file mode 100644 index 0000000..b664e0e --- /dev/null +++ b/app/src/main/cpp/base14/base16384.hpp @@ -0,0 +1,40 @@ +// +// Created by fumiama on 2021/5/20. +// + +#ifndef BASE16384_BASE16384_HPP +#define BASE16384_BASE16384_HPP +#include + +#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 diff --git a/app/src/main/cpp/lzma1900/CMakeLists.txt b/app/src/main/cpp/lzma1900/CMakeLists.txt index 8535b67..62a54f6 100644 --- a/app/src/main/cpp/lzma1900/CMakeLists.txt +++ b/app/src/main/cpp/lzma1900/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.10.2) - project("base16384") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_7ZIP_ST") diff --git a/app/src/main/java/top/fumiama/base16384/MainActivity.kt b/app/src/main/java/top/fumiama/base16384/MainActivity.kt index 4d4244b..0535373 100644 --- a/app/src/main/java/top/fumiama/base16384/MainActivity.kt +++ b/app/src/main/java/top/fumiama/base16384/MainActivity.kt @@ -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 { diff --git a/app/src/main/java/top/fumiama/base16384/tools/PropertiesTools.kt b/app/src/main/java/top/fumiama/base16384/tools/PropertiesTools.kt index 606d80e..e664f93 100644 --- a/app/src/main/java/top/fumiama/base16384/tools/PropertiesTools.kt +++ b/app/src/main/java/top/fumiama/base16384/tools/PropertiesTools.kt @@ -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() + + 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() diff --git a/build.gradle b/build.gradle index e8e3d5d..2b01cc6 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4c5814e..c16dd17 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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