From a8001cd7b01f4613c483058ed4d72ae2c3b8ed57 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Thu, 29 May 2025 19:18:40 +0800 Subject: [PATCH] =?UTF-8?q?6.6.4=20-=20Alpha=20-=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E5=86=99=E5=85=A5=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E8=80=83=E8=99=91=E7=BC=96=E7=A0=81=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 3 +- .../org/autojs/autojs/ui/edit/EditorView.kt | 30 ++++++++++++++++--- version.properties | 6 ++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 8d4ebf66..d6193063 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -6,7 +6,8 @@ "util.dpToPx/spToPx/pxToDp/pxToSp 方法, 用于像素单位转换" ], "fix": [ - "Android 15 部分页面状态栏背景着色区域不完整的问题 _[`issue #398`](http://issues.autojs6.com/398)_" + "Android 15 部分页面状态栏背景着色区域不完整的问题 _[`issue #398`](http://issues.autojs6.com/398)_", + "代码编辑器可能使用置信度不足的编码写入文件导致内容解码异常的问题 (试修)" ], "improvement": [ "关于应用与开发者页面增加布局适配通用性并去除不必要的布局分类" diff --git a/app/src/main/java/org/autojs/autojs/ui/edit/EditorView.kt b/app/src/main/java/org/autojs/autojs/ui/edit/EditorView.kt index 3f3b9dba..808fb901 100644 --- a/app/src/main/java/org/autojs/autojs/ui/edit/EditorView.kt +++ b/app/src/main/java/org/autojs/autojs/ui/edit/EditorView.kt @@ -127,7 +127,8 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag private val mDocsWebView: EWebView = binding.docs private val mDrawerLayout: DrawerLayout = binding.drawerLayout - private var mCurrentCharset: Charset = StandardCharsets.UTF_8 + private var mCurrentCharsetConfidence: Int = 0 + private var mCurrentCharset: Charset = DEFAULT_CHARSET_TO_WRITE_FILE private var mHadBom = false private var mReadOnly = false private var mAutoCompletion: AutoCompletion? = null @@ -244,7 +245,9 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag val resolver = context.contentResolver val rawBytes = resolver.openInputStream(uri)?.use { it.readBytes() } ?: ByteArray(0) - mCurrentCharset = StringUtils.detectCharset(rawBytes).charsetOrDefault() + val detectedCharsetWrapper = StringUtils.detectCharset(rawBytes) + mCurrentCharsetConfidence = detectedCharsetWrapper.confidence ?: 0 + mCurrentCharset = detectedCharsetWrapper.charsetOrDefault() mHadBom = StringUtils.hasBom(rawBytes, mCurrentCharset) val effectiveBytes = if (mHadBom) { @@ -451,8 +454,21 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag private fun writeTextWithCharset(uri: Uri, text: String) { context.contentResolver.openOutputStream(uri, "rwt")?.use { out -> - if (mHadBom) out.write(StringUtils.bomBytes(mCurrentCharset)) - out.write(text.toByteArray(mCurrentCharset)) + val (targetCharset, needBom) = when { + mHadBom -> { + mCurrentCharset to true + } + mCurrentCharsetConfidence >= MIN_CONFIDENCE_TO_WRITE_FILE -> { + mCurrentCharset to false + } + else -> { + DEFAULT_CHARSET_TO_WRITE_FILE to false + } + } + if (needBom) { + out.write(StringUtils.bomBytes(targetCharset)) + } + out.write(text.toByteArray(targetCharset)) } ?: throw IOException("Cannot open output stream for $uri") } @@ -739,13 +755,19 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag } companion object { + private val TAG = EditorView::class.java.simpleName + + private const val MIN_CONFIDENCE_TO_WRITE_FILE = 60 + private val DEFAULT_CHARSET_TO_WRITE_FILE = StandardCharsets.UTF_8 + const val EXTRA_PATH = "path" const val EXTRA_NAME = "name" const val EXTRA_CONTENT = "content" const val EXTRA_READ_ONLY = "readOnly" const val EXTRA_SAVE_ENABLED = "saveEnabled" const val EXTRA_RUN_ENABLED = "runEnabled" + } } \ No newline at end of file diff --git a/version.properties b/version.properties index bc5db08c..8e2ffe21 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Thu May 29 16:36:29 CST 2025 -BUILD_TIME=1748507789815 +#Thu May 29 19:18:00 CST 2025 +BUILD_TIME=1748517480683 COMPILE_SDK_VERSION=35 IMAGE_QUANT_CMAKE_VERSION=3.22.1 IMAGE_QUANT_NDK_VERSION=26.1.10909125 @@ -19,6 +19,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=35 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=3270 +VERSION_BUILD=3271 VERSION_NAME=6.6.4 Alpha VSCODE_EXT_REQUIRED_VERSION=1.0.8