From 212cd4f041423985fb202f339653de137af84a9d Mon Sep 17 00:00:00 2001 From: coldmint Date: Fri, 26 Aug 2022 16:47:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rust/pro/ChangePasswordActivity.kt | 11 + .../rust/pro/adapters/CompileLogAdapter.kt | 54 - .../rust/pro/adapters/ModActionAdapter.kt | 906 +------------ .../coldmint/rust/pro/edit/RustCodeToken.kt | 2 - .../rust/pro/viewmodel/EditEndViewModel.kt | 29 - .../main/res/drawable/ic_outline_email_24.xml | 5 + .../res/layout/activity_change_password.xml | 9 + .../com/coldmint/rust/core/AnalysisResult.kt | 21 - .../com/coldmint/rust/core/CodeCompiler2.kt | 1181 ----------------- .../com/coldmint/rust/core/CodeTranslate.kt | 21 + .../core/dataBean/CompileConfiguration.kt | 314 ----- .../rust/core/dataBean/ModErrorReport.kt | 27 - .../core/interfaces/CodeCompilerInterface.kt | 30 - .../core/interfaces/CodeCompilerListener.kt | 123 -- 14 files changed, 47 insertions(+), 2686 deletions(-) create mode 100644 app/src/main/java/com/coldmint/rust/pro/ChangePasswordActivity.kt delete mode 100644 app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt delete mode 100644 app/src/main/java/com/coldmint/rust/pro/viewmodel/EditEndViewModel.kt create mode 100644 app/src/main/res/drawable/ic_outline_email_24.xml create mode 100644 app/src/main/res/layout/activity_change_password.xml delete mode 100644 assistantCoreLibrary/src/main/java/com/coldmint/rust/core/AnalysisResult.kt delete mode 100644 assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt create mode 100644 assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeTranslate.kt delete mode 100644 assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt delete mode 100644 assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/ModErrorReport.kt delete mode 100644 assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerInterface.kt delete mode 100644 assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerListener.kt diff --git a/app/src/main/java/com/coldmint/rust/pro/ChangePasswordActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ChangePasswordActivity.kt new file mode 100644 index 0000000..f73cd88 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/ChangePasswordActivity.kt @@ -0,0 +1,11 @@ +package com.coldmint.rust.pro + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle + +class ChangePasswordActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_change_password) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt deleted file mode 100644 index 4a1d3c5..0000000 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.coldmint.rust.pro.adapters - -import android.content.Context -import android.text.SpannableString -import androidx.recyclerview.widget.RecyclerView -import android.view.ViewGroup -import android.view.LayoutInflater -import com.coldmint.rust.pro.R -import android.text.method.LinkMovementMethod -import android.view.View -import android.widget.TextView -import androidx.core.view.isVisible -import com.bumptech.glide.Glide -import com.coldmint.rust.core.AnalysisResult -import com.coldmint.rust.pro.base.BaseAdapter -import com.coldmint.rust.pro.databinding.LogItemBinding -import com.coldmint.rust.pro.tool.GlobalMethod - -//编译日志适配器 -class CompileLogAdapter( context: Context, analysisResults: MutableList) : - BaseAdapter(context, analysisResults) { - - override fun getViewBindingObject( - layoutInflater: LayoutInflater, - parent: ViewGroup, - viewType: Int - ): LogItemBinding { - return LogItemBinding.inflate(layoutInflater, parent, false) - } - - override fun onBingView( - data: AnalysisResult, - viewBinding: LogItemBinding, - viewHolder: ViewHolder, - position: Int - ) { -// viewBinding.logInfoView.movementMethod = LinkMovementMethod.getInstance() - viewBinding.logInfoView.text = data.errorInfo - if (data.icon == null) { - viewBinding.imageView.isVisible = false - } else { - viewBinding.imageView.isVisible = true - Glide.with(context).load(data.icon).apply(GlobalMethod.getRequestOptions()).into(viewBinding.imageView) - } - val temFun = data.function - if (temFun != null) { - viewBinding.logInfoView.setOnClickListener { - temFun.invoke(viewBinding.root) - } - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt index 51c98cb..81f06c2 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt @@ -1,908 +1,4 @@ package com.coldmint.rust.pro.adapters - -import android.annotation.SuppressLint -import android.app.Activity -import android.app.ActivityOptions -import android.content.Context -import com.google.android.material.bottomsheet.BottomSheetDialog -import android.widget.BaseAdapter -import com.coldmint.rust.core.dataBean.ModConfigurationData -import android.view.ViewGroup -import android.view.LayoutInflater -import android.widget.TextView -import com.coldmint.rust.core.tool.AppOperator -import android.widget.Toast -import android.widget.EditText -import android.os.Bundle -import android.content.Intent -import com.coldmint.rust.pro.tool.AppSettings -import com.afollestad.materialdialogs.MaterialDialog -import android.content.DialogInterface -import android.os.Handler -import android.os.Looper -import android.view.View -import android.view.inputmethod.InputMethodManager -import androidx.appcompat.app.AlertDialog -import androidx.core.content.ContentProviderCompat.requireContext -import com.coldmint.dialog.InputDialog -import com.coldmint.rust.core.* -import com.google.android.material.snackbar.Snackbar -import com.coldmint.rust.core.dataBean.CompileConfiguration -import com.coldmint.rust.core.dataBean.ModErrorReport -import com.coldmint.rust.core.database.code.ValueTypeInfo -import com.coldmint.rust.core.interfaces.* -import com.coldmint.rust.core.tool.FileFinder2 -import com.coldmint.rust.core.tool.FileOperator -import com.coldmint.rust.pro.* -import com.coldmint.rust.pro.R -import com.coldmint.rust.pro.databinding.ModActionItemBinding -import com.coldmint.rust.pro.fragments.ModFragment -import com.coldmint.rust.pro.tool.GlobalMethod -import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.google.gson.Gson -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch -import java.io.File -import java.lang.NumberFormatException -import java.util.* -import java.util.concurrent.Executor -import java.util.concurrent.Executors -import java.util.zip.ZipEntry -import kotlin.collections.ArrayList - -/** - * @author Cold Mint - */ -class ModActionAdapter( - private val mContext: Context, - private val mdata: List, - private val mModpath: String, - private val mModFragment: ModFragment, - private val mBottomSheetDialog: BottomSheetDialog -) : BaseAdapter() { - private var modConfigurationData: ModConfigurationData? = null - private val handler = Handler(Looper.getMainLooper()) - - /** - * 设置模组配置信息 - * - * @param modConfigurationData 模组配置 - */ - fun setModConfigurationData(modConfigurationData: ModConfigurationData?) { - this.modConfigurationData = modConfigurationData - } - - override fun getCount(): Int { - return mdata.size - } - - override fun getItem(position: Int): Any { - return mdata[position] - } - - override fun getItemId(position: Int): Long { - return position.toLong() - } - - @SuppressLint("ViewHolder") - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val dialogView = ModActionItemBinding.inflate(LayoutInflater.from(mContext), parent, false) - //LayoutInflater.from(mContext).inflate(R.layout.mod_action_item, parent, false) - val textView = dialogView.operation - val itemName = mdata[position] - textView.text = itemName - dialogView.root.setOnClickListener { - mBottomSheetDialog.cancel() - when (itemName) { - mContext.getString(R.string.manages_files) -> { - managesFileItem() - } - mContext.getString(R.string.packmod) -> { - packmodItem() - } - mContext.getString(R.string.share_mod) -> { - shareItem() - } - mContext.getString(R.string.mod_action10) -> { - repairItem() - } - mContext.getString(R.string.optimization) -> { - optimizationItem() - } - mContext.getString(R.string.mod_action1) -> { - editUnitItem() - } - mContext.getString(R.string.mod_action8) -> { - unzipItem() - } - mContext.getString(R.string.mod_action2) -> { - editInfoItem() - } - mContext.getString(R.string.rename) -> { - renameItem() - } - mContext.getString(R.string.release) -> { - releaseItem() - } - mContext.getString(R.string.work_of_home_page) -> { - openHomePage() - } - mContext.getString(R.string.global_operations) -> { - val intent = Intent(mContext, GlobalOperationsActivity::class.java) - intent.putExtra("modPath", mModpath) - mContext.startActivity(intent) - } - mContext.getString(R.string.generate_error_report) -> { -//而coroutineScope会挂起所在的协程直至其内部任务(包括子协程)执行完成,它不会阻塞所在的线程。 -//coroutineScope是一个挂起函数,它被挂起后,会转而执行之前的子协程。 - val scope = CoroutineScope(Job()) - scope.launch { - //启动协程 - var dialog: MaterialDialog? = null - handler.post { - dialog = MaterialDialog(mContext).show { - title(R.string.generate_error_report).message(R.string.loading_data) - .positiveButton(R.string.dialog_ok).cancelable(false) - } - } - val gson = Gson() - val modClass = ModClass(File(mModpath)) - val modErrorReport = ModErrorReport(modClass.modFile.absolutePath) - val outputFolder = - File(AppSettings.dataRootDirectory + "/modErrorReport/" + modClass.modName) - val warningFolder = File(outputFolder.absolutePath + "/warning") - if (!warningFolder.exists()) { - warningFolder.mkdirs() - } - val errorFolder = File(outputFolder.absolutePath + "/error") - if (!errorFolder.exists()) { - errorFolder.mkdirs() - } - val fileFinder2 = FileFinder2(modClass.modFile) - fileFinder2.findMode = true - fileFinder2.asRe = true - fileFinder2.findRule = modConfigurationData?.sourceFileFilteringRule - ?: ".+\\.ini|.+\\.template" - val codeCompiler2 = CodeCompiler2.getInstance(mContext) - val apkFolder = GameSynchronizer.getPackAgeFolder( - mContext, AppSettings.getValue( - AppSettings.Setting.GamePackage, - GlobalMethod.DEFAULT_GAME_PACKAGE - ) - ) - fileFinder2.setFinderListener(object : FileFinderListener { - override fun whenFindFile(file: File): Boolean { - val code = FileOperator.readFile(file) - if (code != null) { - handler.post { - dialog?.message(text = file.absolutePath) - } - codeCompiler2.translation( - code, - object : CodeTranslatorListener { - override fun beforeTranslate() { - - } - - override fun onTranslateComplete(code: String) { - codeCompiler2.compile( - code, - CompileConfiguration( - mContext, - OpenedSourceFile(file), - modClass, apkFolder - ), object : CodeCompilerListener { - override fun onCompilationComplete( - compileConfiguration: CompileConfiguration, - code: String - ) { - //如果有错误或警告那么创建文件 - if (compileConfiguration.getWarningNumber() > 0) { - val outFile = - File( - warningFolder.absolutePath + - "/" + FileOperator.getPrefixName( - file.name - ) + ".json" - ) - val warningList = - ArrayList() - compileConfiguration.getAnalysisResult() - .forEach { - if (it.errorType == CompileConfiguration.ErrorType.Warning) { - warningList.add("【" + it.lineData + "】" + it.errorInfo) - } - } - FileOperator.writeFile( - outFile, - gson.toJson(warningList) - ) - } - if (compileConfiguration.getErrorNumber() > 0) { - val outFile = - File( - errorFolder.absolutePath + - "/" + FileOperator.getPrefixName( - file.name - ) + ".json" - ) - val errorList = - ArrayList() - compileConfiguration.getAnalysisResult() - .forEach { - if (it.errorType == CompileConfiguration.ErrorType.Error) { - errorList.add("【" + it.lineData + "】" + it.errorInfo) - } - } - FileOperator.writeFile( - outFile, - gson.toJson(errorList) - ) - } - modErrorReport.addFileReport( - compileConfiguration - ) - } - - override fun beforeCompilation() { - - } - - override fun onClickKeyNotFoundItem( - lineNum: Int, - columnNum: Int, - view: View, - code: String, - section: String - ) { - - } - - override fun onClickValueTypeErrorItem( - lineNum: Int, - columnNum: Int, - view: View, - valueType: ValueTypeInfo - ) { - - } - - override fun onClickSectionIndexError( - lineNum: Int, - columnNum: Int, - view: View, - sectionName: String - ) { - - } - - override fun onClickResourceErrorItem( - lineNum: Int, - columnNum: Int, - view: View, - resourceFile: File - ) { - - } - - override fun onClickSectionErrorItem( - lineNum: Int, - view: View, - displaySectionName: String - ) { - - } - - override fun onClickSynchronizationGame( - lineNum: Int, - columnNum: Int, - view: View - ) { - - } - - override fun onClickSectionNameErrorItem( - lineNum: Int, - columnNum: Int, - view: View, - sectionName: String, - symbolIndex: Int?, - needName: Boolean - ) { - - } - - override fun onClickCodeIndexErrorItem( - lineNum: Int, - view: View, - sectionName: String - ) { - - } - - override fun onShowCompilationResult(code: String): Boolean { - return true - } - - } - ) - } - - }) - } - return true - } - - override fun whenFindFolder(folder: File): Boolean { - return true - } - - }) - val a = fileFinder2.onStart() - FileOperator.writeFile( - File(outputFolder.absolutePath + "/list.json"), - gson.toJson(modErrorReport) - ) - handler.post { - dialog?.message(R.string.generate_error_report_ok) - } - } - } - else -> { - if (modConfigurationData != null) { - val title = modConfigurationData!!.updateTitle - if ((title == itemName)) { - val type = modConfigurationData!!.updateType - if ((type == ModConfigurationManager.qqGroupType)) { - try { - val integer = Integer.valueOf( - modConfigurationData!!.updateLink - ) - val result = AppOperator.openQQGroupCard( - mContext, integer - ) - if (!result) { - Toast.makeText( - mContext, - R.string.open_qq_group_card_error, - Toast.LENGTH_SHORT - ).show() - } - } catch (e: NumberFormatException) { - Toast.makeText( - mContext, - R.string.qq_group_error, - Toast.LENGTH_SHORT - ).show() - } - } else if ((type == ModConfigurationManager.webLinkType)) { - val result = AppOperator.useBrowserAccessWebPage( - mContext, modConfigurationData!!.updateLink - ) - if (!result) { - Toast.makeText( - mContext, - R.string.not_found_activity, - Toast.LENGTH_SHORT - ).show() - } - } else { - Toast.makeText( - mContext, - R.string.update_type_error, - Toast.LENGTH_SHORT - ).show() - } - } - } else { - Toast.makeText(mContext, "没有设置事件", Toast.LENGTH_SHORT).show() - } - } - } - } - return dialogView.root - } - - - /** - * 打开作品首页 - */ - private fun openHomePage() { - val modId = modConfigurationData?.modId - if (modId != null) { - val bundle = Bundle() - bundle.putString("modId", modId) - bundle.putString("modName", modId) - val intent = Intent(mContext, WebModInfoActivity::class.java) - intent.putExtra("data", bundle) - mContext.startActivity(intent) - } - } - - /** - * 点击了发布 - */ - private fun releaseItem() { - val releaseBundle = Bundle() - val modId = modConfigurationData?.modId - releaseBundle.putString("modPath", mModpath) - if (modId == null) { - releaseBundle.putString("mode", "firstReleaseMode") - } else { - releaseBundle.putString("mode", "loadMode") - releaseBundle.putString("modId", modId) - } - val intent = Intent(mContext, ReleaseModActivity::class.java) - intent.putExtra("data", releaseBundle) - mContext.startActivity(intent) - } - - /** - * 点击了重命名 - */ - private fun renameItem() { - val mod_file = File(mModpath) - val oldname = ModClass(mod_file).modName - InputDialog(mContext).setInputCanBeEmpty(false).setTitle(R.string.rename).setMaxNumber(255) - .setHint(R.string.file_name).setText(oldname) - .setPositiveButton(R.string.dialog_ok) { string -> - if (string.isNotEmpty() && string != oldname) { - val newFile = File(FileOperator.getSuperDirectory(mod_file) + "/" + string) - mod_file.renameTo(newFile) - mModFragment.loadModList() - } - true - }.setNegativeButton(R.string.dialog_cancel) { - - }.setCancelable(false).show() - } - - /** - * 点击了编辑信息 - */ - private fun editInfoItem() { - val fileBundle = Bundle() - val infoIntent = Intent(mContext, EditModInfoActivity::class.java) -// val modClass = ModClass(File(mModpath)) - //fileBundle.putString("infoPath", modClass.getInfoFile().getAbsolutePath()); - fileBundle.putString("modPath", mModpath) - infoIntent.putExtra("data", fileBundle) - mContext.startActivity(infoIntent) - } - - /** - * 点击了解压 - */ - private fun unzipItem() { - val uzipThread = UnzipThread() - uzipThread.start() - } - - /** - * 点击编辑单位 - */ - private fun editUnitItem() { - val bundle = Bundle() - val uintent = Intent(mContext, UnitsActivity::class.java) - bundle.putString("path", mModpath) - uintent.putExtra("data", bundle) - mContext.startActivity(uintent) - } - - /** - * 点击了管理文件 - */ - private fun managesFileItem() { - val managesIntent = Intent(mContext, FileManagerActivity::class.java) - val configurationBundle = Bundle() - managesIntent.putExtra("data", configurationBundle) - configurationBundle.putString("type", "default") - configurationBundle.putString("path", mModpath) - mContext.startActivity(managesIntent) - } - - /** - * 点击了打包 - */ - private fun packmodItem() { - val packIntent = Intent(mContext, PackActivity::class.java) - val packData = Bundle() - packIntent.putExtra("data", packData) - packData.putString("modPath", mModpath) - mContext.startActivity(packIntent) - } - - /** - * 点击了优化 - */ - private fun optimizationItem() { - val oBundle = Bundle() - oBundle.putString("modPath", mModpath) - val intent = Intent(mContext, OptimizeActivity::class.java) - intent.putExtra("data", oBundle) - mContext.startActivity(intent) - } - - /** - * 点击修复项目时 - */ - private fun repairItem() { - val repairThread = RepairThread() - repairThread.start() - } - - /** - * 点击分享项目时 - */ - private fun shareItem() { - val file = File(mModpath) - if (file.isDirectory) { - val needShowTip = AppSettings.getValue(AppSettings.Setting.ShareTip, true) - if (needShowTip) { - val materialDialog = MaterialDialog(mContext, MaterialDialog.DEFAULT_BEHAVIOR) - materialDialog.title(R.string.packmod, null) - materialDialog.message(R.string.share_tip, null, null) - materialDialog.positiveButton( - R.string.dialog_ok, - null - ) { materialDialog: MaterialDialog? -> - packShare(file) - null - } - materialDialog.negativeButton( - R.string.no_longer_prompt, - null - ) { materialDialog: MaterialDialog? -> - AppSettings.setValue(AppSettings.Setting.ShareTip, false) - packShare(file) - null - } - materialDialog.show() - } else { - packShare(file) - } - } else { - FileOperator.shareFile(mContext, file) - } - } - - /** - * 打包分享事件(对话框) - * - * @param file 文件夹 - */ - private fun packShare(file: File) { - val modClass = ModClass(file) - val materialDialog = MaterialDialog(mContext) - Thread(object : Runnable { - override fun run() { - handler.post { - materialDialog.title(R.string.packmod).message( - text = - String.format( - mContext.getString(R.string.dialog_packing), - modClass.modName - ) - ).cancelable(false).positiveButton(R.string.dialog_close2) { - Snackbar.make( - (mModFragment.view)!!, - R.string.dialog_close_tip3, - Snackbar.LENGTH_SHORT - ).show() - }.show() - } - val cacheDirectory = File(mContext.cacheDir.absolutePath + "/share/mod") - if (!cacheDirectory.exists()) { - cacheDirectory.mkdirs() - } - val toFile = - File(cacheDirectory.absolutePath + "/" + file.name + ".rwmod") - val compressionManager = CompressionManager.instance - compressionManager.compression(file, toFile, object : CompressionListener { - override fun whenCompressionFile(file: File): Boolean { - handler.post { - materialDialog.message( - text = - String.format( - mContext.getString(R.string.dialog_packing), - file.name - ) - ) - } - return true - } - - override fun whenCompressionFolder(folder: File): Boolean { - handler.post { - materialDialog.message( - text = - String.format( - mContext.getString(R.string.dialog_packing), - folder.name - ) - ) - } - return true - } - - override fun whenCompressionComplete(result: Boolean) { - handler.post { - if (result) { - materialDialog.title(R.string.share_mod).message( - text = - String.format( - mContext.getString(R.string.pack_success), - modClass.modName - ) - ).clearPositiveListeners().positiveButton(R.string.share_mod) { - FileOperator.shareFile( - mContext, toFile - ) - }.negativeButton(R.string.dialog_cancel) { - toFile.delete() - }.show() - } else { - materialDialog.dismiss() - Snackbar.make( - (mModFragment.view)!!, - R.string.pack_failed, - Snackbar.LENGTH_SHORT - ).show() - } - } - } - }, null) - } - }).start() - } - - internal inner class RepairThread() : Thread(), Runnable { - private var modpath = mModpath - lateinit var materialDialog: MaterialDialog - - //设置模组路径 - fun setModpath(modpath: String) { - this.modpath = modpath - } - - override fun run() { - super.run() - val modClass = ModClass(File(modpath)) - handler.post { - materialDialog = MaterialDialog(mContext).title(R.string.dialog_title3).message( - text = String.format( - mContext.getString(R.string.dialog_repair), modClass.modName - ) - ).cancelable(false).positiveButton(R.string.dialog_close2) { - Snackbar.make( - (mModFragment.view)!!, - R.string.dialog_close_tip2, - Snackbar.LENGTH_SHORT - ).show() - } - materialDialog.show() - } - val fileFinder = FileFinder2(modClass.modFile) - var targetFile: File? = null - fileFinder.setFinderListener(object : FileFinderListener { - override fun whenFindFile(file: File): Boolean { - handler.post { - materialDialog.message( - text = String.format( - mContext.getString(R.string.dialog_search), file.name - ) - ) - } - val fileName = file.name.lowercase() - val result = fileName == modClass.INFOFILENAME - if (result) { - targetFile = file - } - return !result - } - - override fun whenFindFolder(folder: File): Boolean { - return true - } - - }) - fileFinder.onStart() - val findFile = targetFile?.parentFile - if (findFile != null) { - val modFile = modClass.modFile - val ok = - FileOperator.removeFiles(findFile, modFile, object : RemoveAndCopyListener { - override fun whenOperatorFile(file: File) { - handler.post { - materialDialog.message( - text = String.format( - mContext.getString(R.string.dialog_remove), file.name - ) - ) - } - } - - }) - if (ok) { - handler.post { - materialDialog.dismiss() - mModFragment.loadModList() - Snackbar.make( - (mModFragment.view)!!, - R.string.repair_complete, - Snackbar.LENGTH_SHORT - ).show() - } - } else { - handler.post { - materialDialog.dismiss() - Snackbar.make( - (mModFragment.view)!!, - R.string.repair_complete, - Snackbar.LENGTH_SHORT - ).setAction(R.string.create) { - createInfoFile(modClass, false) - }.show() - } - } - } else { - createInfoFile(modClass) - } - } - - /** - * 创建信息文件并显示修复完成 - * @param modClass ModClass - * @param needShowSnackbar 是否要提示 - */ - fun createInfoFile(modClass: ModClass, needShowSnackbar: Boolean = true) { - FileOperator.writeFile( - modClass.infoFile, - "[mod]\ntitle: " + modClass.modName + "\ndescription: " + mContext.getText(R.string.repair_complete) - ) - handler.post { - materialDialog.dismiss() - mModFragment.loadModList() - if (needShowSnackbar) { - Snackbar.make( - (mModFragment.view)!!, - R.string.repair_complete, - Snackbar.LENGTH_SHORT - ).show() - } - } - } - } - - - internal inner class UnzipThread() : Thread(), Runnable { - lateinit var materialDialog: MaterialDialog - override fun run() { - super.run() - val main_path = - AppSettings.getValue(AppSettings.Setting.ModFolder, "") - val unzip_path = File( - main_path + FileOperator.getPrefixName( - File( - mModpath - ) - ) - ) - - //如果模组存在 - if (unzip_path.exists()) { - handler.post { - Snackbar.make( - (mModFragment.view)!!, - mContext.resources.getText(R.string.directory_error), - Snackbar.LENGTH_SHORT - ).show() - } - return - } else { - handler.post { - materialDialog = - MaterialDialog(mContext).title(R.string.dialog_title2).message( - text = String.format( - (mContext.resources.getText(R.string.dialog_unziping) as String), - ModClass( - File( - mModpath - ) - ).modName - ) - ).cancelable(false).positiveButton(R.string.dialog_close2) { - Snackbar.make( - (mModFragment.view)!!, - mContext.resources.getText(R.string.dialog_close_tip), - Snackbar.LENGTH_SHORT - ).show() - } - materialDialog.show() - } - unzip_path.mkdirs() - } - val compressionManager = CompressionManager.instance - compressionManager.unzip(File(mModpath), unzip_path, object : UnzipListener { - - override fun whenUnzipFile(zipEntry: ZipEntry, file: File): Boolean { - handler.post { - materialDialog.message( - text = String.format( - (mContext.resources.getText(R.string.dialog_unziping) as String), - file.name - ) - ) - } - return true - } - - override fun whenUnzipFolder(zipEntry: ZipEntry, folder: File): Boolean { - handler.post { - materialDialog.message( - text = - String.format( - (mContext.resources.getText(R.string.dialog_unziping) as String), - folder.name - ) - ) - } - return true - } - - override fun whenUnzipComplete(result: Boolean) { - if (result) { - val keepFile = AppSettings.getValue(AppSettings.Setting.KeepRwmodFile, true) - if (!keepFile) { - val modFile = File(mModpath) - val needRecycling = AppSettings.getValue( - AppSettings.Setting.EnableRecoveryStation, - true - ) - if (needRecycling) { - val removeFile: File - val removePath: String = AppSettings.getValue( - AppSettings.Setting.RecoveryStationFolder, - mContext.filesDir.absolutePath + "/backup/" - ).toString() + modFile.name - removeFile = File(removePath) - FileOperator.removeFiles(modFile, removeFile) - handler.post { - Snackbar.make( - (mModFragment.view)!!, String.format( - mContext.getString(R.string.recovery_prompt), - modFile.name - ), Snackbar.LENGTH_SHORT - ).show() - } - } else { - FileOperator.delete_files(modFile) - } - } - handler.post { - materialDialog.dismiss() - val modClass = ModClass(unzip_path) - if (!modClass.hasInfo()) { - val repairThread = RepairThread() - repairThread.setModpath(unzip_path.absolutePath) - repairThread.start() - } - mModFragment.loadModList() - } - } else { - handler.post { - materialDialog.dismiss() - Snackbar.make( - (mModFragment.view)!!, - mContext.resources.getText(R.string.import_error1), - Snackbar.LENGTH_SHORT - ).show() - } - } - } - }) - } - } +class ModActionAdapter { } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/RustCodeToken.kt b/app/src/main/java/com/coldmint/rust/pro/edit/RustCodeToken.kt index 054ac2e..47c9a0b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/RustCodeToken.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/RustCodeToken.kt @@ -1,7 +1,5 @@ package com.coldmint.rust.pro.edit -import com.coldmint.rust.core.dataBean.CompileConfiguration - /** * Rust代码标记 * @property offset Int diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/EditEndViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/EditEndViewModel.kt deleted file mode 100644 index c263d93..0000000 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/EditEndViewModel.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.coldmint.rust.pro.viewmodel - -import android.app.Application -import android.text.SpannableString -import androidx.lifecycle.MutableLiveData -import com.coldmint.rust.core.AnalysisResult -import com.coldmint.rust.pro.base.BaseAndroidViewModel - -/** - * @author Cold Mint - * @date 2022/2/5 14:18 - */ -class EditEndViewModel(application: Application) : BaseAndroidViewModel(application) { - - /** - * 分析结果LiveData - */ - val analysisResultLiveData: MutableLiveData> by lazy { - MutableLiveData>() - } - - /** - *加载状态LiveData - */ - val loadStateLiveData: MutableLiveData by lazy { - MutableLiveData() - } - -} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_outline_email_24.xml b/app/src/main/res/drawable/ic_outline_email_24.xml new file mode 100644 index 0000000..033a1e0 --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_email_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_change_password.xml b/app/src/main/res/layout/activity_change_password.xml new file mode 100644 index 0000000..27fe239 --- /dev/null +++ b/app/src/main/res/layout/activity_change_password.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/AnalysisResult.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/AnalysisResult.kt deleted file mode 100644 index 8af0bac..0000000 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/AnalysisResult.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.coldmint.rust.core - -import android.graphics.drawable.Drawable -import android.text.SpannableString -import android.view.View -import com.coldmint.rust.core.dataBean.CompileConfiguration - - -/** - * 代码分析结果 - * @property text String 文本 - * @property icon Drawable 图标 - * @constructor - */ -data class AnalysisResult( - val lineData: String, - val errorInfo: String, - var icon: Drawable? = null, - var function: ((View) -> Unit)? = null, - val errorType: CompileConfiguration.ErrorType -) \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt deleted file mode 100644 index 3e8ac36..0000000 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt +++ /dev/null @@ -1,1181 +0,0 @@ -package com.coldmint.rust.core - -import android.annotation.SuppressLint -import android.content.Context -import android.os.Handler -import android.os.Looper -import android.os.Message -import android.util.Log -import com.coldmint.rust.core.dataBean.CompileConfiguration -import com.coldmint.rust.core.database.code.CodeDataBase -import com.coldmint.rust.core.database.code.SectionInfo -import com.coldmint.rust.core.database.code.ValueTypeInfo -import com.coldmint.rust.core.interfaces.* -import com.coldmint.rust.core.tool.DebugHelper -import com.coldmint.rust.core.tool.FileOperator -import com.coldmint.rust.core.tool.LineParser -import java.io.File -import java.util.* -import java.util.concurrent.Executors -import kotlin.collections.HashMap -import kotlin.text.StringBuilder - -/** - * 代码编译器 2 - * @author Cold Mint - * @date 2022/1/24 10:36 - */ -class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInterface, EnglishMode { - - - /** - * 英文模式 - */ - private var englishMode = false - - /** - * 编译结果映射 - */ - private val compileMap by lazy { - HashMap() - } - - /** - * 节结果映射 - */ - private val sectionMap by lazy { - HashMap() - } - - /** - * 值类型映射 - */ - private val valueTypeMap by lazy { - HashMap() - } - - /** - * 编译错误记录映射 - */ - private val errorRecordMap by lazy { - HashMap() - } - private val executorService by lazy { - Executors.newCachedThreadPool() - } - private val codeDataBase by lazy { - CodeDataBase.getInstance(context) - } - private val handler by lazy { - Handler(Looper.getMainLooper()) - } - - - companion object { - const val split = "\n ,:()=%{}+*/\r" - val debugKey = "代码编译器" - - @SuppressLint("StaticFieldLeak") - private var instance: CodeCompiler2? = null - - /** - * 获取实例对象 - * @param context Context - * @return CodeCompiler2 - */ - fun getInstance(context: Context): CodeCompiler2 { - if (instance == null) { - synchronized(this) - { - if (instance == null) { - instance = CodeCompiler2(context) - } - } - } - return instance!! - } - - /** - * 格式化内容 - * - * @param text 源文本 - * @return 格式化后的文本 - */ - @JvmStatic - fun format(text: String): String { - val result = StringBuilder() - val lineParser = LineParser(text) - lineParser.needTrim = true - lineParser.analyse(object : LineParserEvent { - override fun processingData( - lineNum: Int, - lineData: String, - isEnd: Boolean - ): Boolean { - if (lineData.isNotBlank()) { - if (lineNum > 0 && result.isNotBlank()) { - if (lineData.startsWith("[") && lineData.endsWith("]")) { - result.append("\n") - } - result.append("\n") - } - val needSymbol = lineData.indexOf(':') - if (needSymbol > -1) { - val key = lineData.substring(0, needSymbol).trim { it <= ' ' } - val value = - lineData.substring(needSymbol + 1, lineData.length) - .trim { it <= ' ' } - result.append(key) - result.append(":") - result.append(value) - } else { - result.append(lineData) - } - } - return true - } - - }) - return result.toString() - } - } - - /** - * 清理缓存 - */ - fun clearCache() { - compileMap.clear() - errorRecordMap.clear() - valueTypeMap.clear() - } - - /** - * 翻译活动 - * @param code String - * @param translatorListener CodeTranslatorListener - */ - private fun translationWork(code: String, translatorListener: CodeTranslatorListener) { - if (englishMode) { - handler.post { - translatorListener.beforeTranslate() - translatorListener.onTranslateComplete(code) - } - } else { - val tokenizer = StringTokenizer(code, split, true) - //缓存翻译数据,以便加速重复数据的翻译 - val translationMap = HashMap() - //保存每次代码的翻译结果 - val codeResult = StringBuilder() - //保存完整的翻译结果 - val translationResult = StringBuilder() - var codeBlockType = CompileConfiguration.CodeBlockType.Key - //保存资源引用值(应该看做整体处理) - val referenceResult = StringBuilder() - handler.post { - translatorListener.beforeTranslate() - } - while (tokenizer.hasMoreTokens()) { - val code = tokenizer.nextToken() - if (translationMap.containsKey(code)) { - if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - referenceResult.append(translationMap[code]) - } else { - translationResult.append(translationMap[code]) - } - } else { - codeResult.clear() - when (code) { - "\n" -> { - if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - val referenceValue = referenceResult.toString() - val codeInfo = - codeDataBase.getCodeDao().findCodeByCode(referenceValue) - if (codeInfo == null) { - translationResult.append(referenceResult) - } else { - translationResult.append(codeInfo.translate) - } - DebugHelper.printLog( - debugKey, - "追加引用值[" + referenceValue + "]", - "翻译行引用处理" - ) - referenceResult.clear() - } - codeBlockType = CompileConfiguration.CodeBlockType.Key - codeResult.append(code) - } - "\r" -> { - } - " ", ",", "(", ")", "=", "%", "{", "}", "+", "*", "/" -> { - if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - referenceResult.append(code) - } else { - codeResult.append( - code - ) - } - } - ":" -> { - if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - referenceResult.append(code) - } else { - if (codeBlockType == CompileConfiguration.CodeBlockType.Key) { - codeBlockType = - CompileConfiguration.CodeBlockType.Value - } - codeResult.append(code) - } - } - else -> if (codeBlockType == CompileConfiguration.CodeBlockType.Note) { - codeResult.append(code) - } else if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - //资源引用值应该被整体处理 - DebugHelper.printLog(debugKey, "翻译添加引用值[" + code + "]", "翻译代码处理") - referenceResult.append(code) - } else { - if (code.startsWith("#")) { - codeBlockType = CompileConfiguration.CodeBlockType.Note - codeResult.append(code) - } else if (code.startsWith("[") && code.endsWith("]")) { - val symbolPosition = code.lastIndexOf("_") - if (symbolPosition > 0) { - val sectionPrefixName = code.substring(1, symbolPosition) - codeResult.append("[") - val info = codeDataBase.getSectionDao() - .findSectionInfoByCode(sectionPrefixName) - codeResult.append( - info?.translate ?: sectionPrefixName - ) - codeResult.append("_") - codeResult.append(code.substring(symbolPosition + 1)) - } else { - val sectionCode = code.substring(1, code.length - 1) - codeResult.append("[") - val info = - codeDataBase.getSectionDao() - .findSectionInfoByCode(sectionCode) - codeResult.append( - info?.translate ?: sectionCode - ) - codeResult.append("]") - } - } else { - val codeInfo = codeDataBase.getCodeDao().findCodeByCode(code) - if (codeInfo == null) { - if (code.contains("_")) { - val lineParser = LineParser(code) - lineParser.symbol = "_" - lineParser.analyse(object : LineParserEvent { - override fun processingData( - lineNum: Int, - lineData: String, - isEnd: Boolean - ): Boolean { - val temCodeInfo = - codeDataBase.getCodeDao() - .findCodeByCode(lineData.trim()) - if (temCodeInfo == null) { - codeResult.append(lineData) - } else { - codeResult.append(temCodeInfo.translate) - } - if (!isEnd) { - codeResult.append(lineParser.symbol) - } - return true - } - }) - } else { - codeResult.append(code) - } - } else { - //是否需要检查值 - if (codeBlockType == CompileConfiguration.CodeBlockType.Key) { - val type = getValueData(codeInfo.type) - val tag = type?.tag - if (!tag.isNullOrBlank()) { - //如果此类型为特殊标注,那么设置为注释 - codeBlockType = - CompileConfiguration.CodeBlockType.Reference - } - } - codeResult.append(codeInfo.translate) - } - } - } - } - //如果代码不是注释,也不是换行,不是冒号,那么缓存它。 - if (codeBlockType != CompileConfiguration.CodeBlockType.Note && codeBlockType != CompileConfiguration.CodeBlockType.Reference && code != ":" && code != "\n") { - translationMap[code] = codeResult.toString() - } - translationResult.append(codeResult.toString()) - DebugHelper.printLog( - debugKey, - "代码[" + code + "]译文[" + codeResult.toString() + "]是否翻译[" + (code != codeResult.toString()) + "]", - "翻译" - ) - } - } - handler.post { - translatorListener.onTranslateComplete(translationResult.toString()) - } - } - } - - - /** - * 编译活动 - * @param sourceCode String 代码 - * @param compileConfiguration CompileConfiguration 编译配置 - * @param compilerListener CodeCompilerListener? 编译监听器 - */ - private fun compileWork( - sourceCode: String, - compileConfiguration: CompileConfiguration, - compilerListener: CodeCompilerListener? = null - ) { - compileConfiguration.setErrorRecordMap(errorRecordMap) - //添加换行符以便检测 - val finalSourceCode = sourceCode + "\n" - val tokenizer = StringTokenizer(finalSourceCode, split, true) - //保存每段代码的翻译结果 - val codeResult = StringBuilder() - //保存完整的翻译结果 - val compileResult = StringBuilder() - //是否为首次引用冒号值(首次值会直接附加到结果集合内) - var isFirstReference = false - - //保存资源引用值(应该看做整体处理) - val referenceResult = StringBuilder() - val context = compileConfiguration.context - handler.post { - compilerListener?.beforeCompilation() - } - val startTime = System.currentTimeMillis() - while (tokenizer.hasMoreTokens()) { - val translation = tokenizer.nextToken() - codeResult.clear() - if (compileMap.containsKey(translation)) { - //此处仅读取字段缓存,不涉及错误缓存的读取 - val code = compileMap[translation] - if (code != null) { - if (code.startsWith("[") && code.endsWith("]")) { - analysisSection( - code, - codeResult, - compileConfiguration, - compilerListener, false - ) - } else { - //是代码,添加到代码段结果集 - if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - referenceResult.append(code) - } else { - compileConfiguration.appendResult(code) - codeResult.append(code) - } - - } - } - } else { - when (translation) { - "\n" -> { - if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - //此段代码将临时引用数据referenceValue 附加到编译结果内,并附加到 值 数据内(附加值数据用于检查) - val referenceValue = referenceResult.toString() - compileConfiguration.appendValue(referenceResult.toString()) - val codeInfo = codeDataBase.getCodeDao() - .findCodeByTranslate(referenceResult.toString()) - if (codeInfo == null) { - codeResult.append(referenceValue) - } else { - codeResult.append(codeInfo.code) - } - DebugHelper.printLog( - debugKey, - "引用数据[" + referenceValue + "]代码信息存在状态[" + (codeInfo != null) + "]本次附加[" + codeResult.toString() + "]", - "行引用附加" - ) - referenceResult.clear() - } - isFirstReference = true - checkLineCode(compileConfiguration, compilerListener) - compileConfiguration.nextLine() - codeResult.append(translation) - } - "\r" -> { - } - " ", ",", "(", ")", "=", "%", "{", "}", "+", "*", "/" -> { - if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - referenceResult.append(translation) - } else { - codeResult.append( - translation - ) - compileConfiguration.appendResult(translation) - } - } - ":" -> { - when (compileConfiguration.codeBlockType) { - CompileConfiguration.CodeBlockType.Value -> { - compileConfiguration.appendResult(translation) - codeResult.append(translation) - } - CompileConfiguration.CodeBlockType.Key -> { - compileConfiguration.codeBlockType = - CompileConfiguration.CodeBlockType.Value - codeResult.append(translation) - } - CompileConfiguration.CodeBlockType.Reference -> { - if (isFirstReference) { - codeResult.append(translation) - isFirstReference = false - } else { - referenceResult.append(translation) - } - } - else -> { - - } - } - } - else -> if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Note) { - codeResult.append(translation) - } else if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Reference) { - //资源引用值应该被整体处理 - referenceResult.append(translation) - } else { - if (translation.startsWith("#") && compileConfiguration.codeBlockType == - CompileConfiguration.CodeBlockType.Key - ) { - compileConfiguration.codeBlockType = - CompileConfiguration.CodeBlockType.Note - codeResult.append(translation) - } else if (translation.startsWith("[") && translation.endsWith("]")) { - analysisSection( - translation, - codeResult, - compileConfiguration, - compilerListener - ) - } else { - //为代码时 - val codeInfo = - codeDataBase.getCodeDao().findCodeByTranslate(translation) - if (codeInfo == null) { - if (translation.contains("_")) { - val lineParser = LineParser(translation) - lineParser.symbol = "_" - lineParser.analyse(object : LineParserEvent { - override fun processingData( - lineNum: Int, - lineData: String, - isEnd: Boolean - ): Boolean { - val temCodeInfo = - codeDataBase.getCodeDao() - .findCodeByTranslate(lineData.trim()) - if (temCodeInfo == null) { - codeResult.append(lineData) - } else { - codeResult.append(temCodeInfo.code) - } - if (!isEnd) { - codeResult.append(lineParser.symbol) - } - return true - } - }) - } else { - codeResult.append(translation) - } - } else { - //是否需要检查值 - if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Key) { - val type = getValueData(codeInfo.type) - val tag = type?.tag - if (!tag.isNullOrBlank()) { - //如果此类型为特殊标注,那么设置为注释 - DebugHelper.printLog( - debugKey, - "数据类型从Key更改为Reference,翻译[" + translation + "]" - ) - compileConfiguration.codeBlockType = - CompileConfiguration.CodeBlockType.Reference - compileConfiguration.appendKey(codeInfo.code) - } - } - codeResult.append(codeInfo.code) - } - //翻译代码段完毕后,加入行结果集合 - compileConfiguration.appendResult(codeResult.toString()) - } - } - } - //如果代码不是注释,也不是换行,也不是冒号,那么缓存它。 - if (compileConfiguration.codeBlockType != CompileConfiguration.CodeBlockType.Note && compileConfiguration.codeBlockType != CompileConfiguration.CodeBlockType.Reference && translation != "\n" && translation != ":") { - compileMap[translation] = codeResult.toString() - } - } - //保存单次编译结果 - DebugHelper.printLog( - debugKey, - "代码中文[" + translation + "]译文[" + codeResult.toString() + "]代码块类型[" + compileConfiguration.codeBlockType + "]", - "编译器" - ) - compileResult.append(codeResult.toString()) - compileConfiguration.addColumn(translation) - } - val time = System.currentTimeMillis() - startTime - val tip = String.format( - context.getString(R.string.compilation_result_tip), - compileConfiguration.getErrorNumber(), - compileConfiguration.getWarningNumber(), - time - ) - compileConfiguration.addInfo(tip) - handler.post { - compilerListener?.onCompilationComplete( - compileConfiguration, - compileResult.substring(0, compileResult.length - 1).toString() - ) - } - } - - - /** - * 检查行数据,此函数不修改结果集。 - * @param compileConfiguration CompileConfiguration 代码配置 - * @param compilerListener CodeCompilerListener? 代码监听器 - */ - fun checkLineCode( - compileConfiguration: CompileConfiguration, - compilerListener: CodeCompilerListener? = null - ) { - DebugHelper.printLog( - debugKey, - "键[" + compileConfiguration.getKey() + "]值[" + compileConfiguration.getValue() + "]", - "行处理" - ) - compileConfiguration.setCanAddError(true) - val key = compileConfiguration.getKey() - //设置了监听器并且key不为空 - if (key.isNotBlank() && compilerListener != null) { - val value = compileConfiguration.getValue() - if (value.isBlank()) { - //缺少值(此处不会读取缓存) - val codeInfo = codeDataBase.getCodeDao().findCodeByCode(key) - val codeIndex = compileConfiguration.createCodeIndex(key) - compileConfiguration.addError( - codeIndex, CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.compiler_error10), - codeInfo?.translate - ?: key - ), errorType = CompileConfiguration.ErrorType.Error, function = { - } - ) - ) - } else { - //生成代码位置 - val codeIndex = compileConfiguration.createCodeIndex("$key:$value") - //读取缓存 - val errorRecord = errorRecordMap[codeIndex] - if (errorRecord == null) { - //没有错误缓存,检测代码 - //key必为英文 - val codeInfo = codeDataBase.getCodeDao().findCodeByCode(key) - if (codeInfo == null) { - //代码没有录入 - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = compileConfiguration.getColumnNum() - 1 - compileConfiguration.addError( - codeIndex, - CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.compiler_error9), - key - ), function = { - compilerListener.onClickKeyNotFoundItem( - finalLineNum, finalColumnNum, - it, - key, - compileConfiguration.lastSection ?: "" - ) - } - ) - ) - } else { - //判断节位置 - val section = codeInfo.section - //lastSection绝对为英文 - val lastSection = compileConfiguration.lastSection - if (lastSection == null) { - //不存在于任何节内 - compileConfiguration.addError( - codeIndex, - CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.compiler_error11), - codeInfo.translate - ), errorType = CompileConfiguration.ErrorType.Error - ) - ) - compileConfiguration.setCanAddError(false) - return - } - - //如果节不包含的话 - if (!section.contains(lastSection)) { - val finalLine = compileConfiguration.getLineNum() - val finalColumnNum = compileConfiguration.getColumnNum() - 1 - compileConfiguration.addError( - codeIndex, - CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.compiler_error6), - codeInfo.translate, sectionListToTranslate(section) - ), - errorType = CompileConfiguration.ErrorType.Warning, - verifyFunction = { - if (it.lastSection == null) { - true - } else { - //如果数据内不包含last则显示 - !section.contains(it.lastSection!!) - } - }, - function = { - compilerListener.onClickSectionIndexError( - finalLine, finalColumnNum, - it, - section - ) - } - ) - ) - compileConfiguration.setCanAddError(false) - return - } - //判断值类型是否正确,值绝对为英文 - val valueTypeInfo = getValueData(codeInfo.type) - if (valueTypeInfo != null && !value.matches(Regex(valueTypeInfo.rule))) { - //不满足规则 - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = compileConfiguration.getColumnNum() - 1 - compileConfiguration.addError( - codeIndex, - CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.compiler_error1), - value, - valueTypeInfo.name - ), - errorType = CompileConfiguration.ErrorType.Error, - function = { - compilerListener.onClickValueTypeErrorItem( - finalLineNum, - finalColumnNum, - it, - valueTypeInfo - ) - } - ) - ) - } - - //判断关联内容 - //如果是Tag标记 - if (valueTypeInfo != null && valueTypeInfo.tag.startsWith("@file") && value != "AUTO" && value != "NONE") { - //检查附加描述 - val root = "ROOT:" - //检查目录 - val sourceFileFolder = - FileOperator.getSuperDirectory(compileConfiguration.openedSourceFile.file) - var apkFolder: String? = null - //文件类型 - var type = "" - //是否仅检查此格式(默认情况apk文件不存在,检查源文件目录)此变量为真则仅检查apk内部 - var only = false - val startIndex = valueTypeInfo.tag.indexOf('(') - if (startIndex > -1) { - val endIndex = valueTypeInfo.tag.indexOf(')') - if (endIndex > -1) { - val targetValue = - valueTypeInfo.tag.subSequence(startIndex + 1, endIndex) - val apkTag = "apk{" - val typeTag = "type{" - val onlyType = "only{" - val apkIndex = targetValue.indexOf(apkTag) - val onlyIndex = targetValue.indexOf(onlyType) - val typeIndex = targetValue.indexOf(typeTag) - if (apkIndex > -1) { - //指名为apk目录 - val endIndex = targetValue.indexOf('}', apkIndex) - if (endIndex > -1) { - val tag = targetValue.subSequence( - apkIndex + apkTag.length, - endIndex - ).toString() - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = - compileConfiguration.getColumnNum() - 1 - //如果引用了apk内部文件但是,没有同步数据那么抛出异常 - if (!compileConfiguration.apkFolder.exists()) { - compileConfiguration.addError( - codeIndex, CompileConfiguration.ErrorRecord( - compileConfiguration.context.getString(R.string.compiler_error12), - verifyFunction = { - !it.apkFolder.exists() - }, function = { - compilerListener.onClickSynchronizationGame( - finalLineNum, - finalColumnNum, - it - ) - }) - ) - return - } - apkFolder = - compileConfiguration.apkFolder.absolutePath + "/" + tag - } - } - if (typeIndex > -1) { - //指定文件格式 - val endIndex = targetValue.indexOf('}', typeIndex) - if (endIndex > -1) { - val tag = targetValue.subSequence( - typeIndex + typeTag.length, - endIndex - ).toString() - type = tag - } - } - if (onlyIndex > -1) { - //指定是否仅检查 - val endIndex = targetValue.indexOf('}', onlyIndex) - if (endIndex > -1) { - val tag = targetValue.subSequence( - onlyIndex + onlyType.length, - endIndex - ).toString() - if (tag.lowercase(Locale.getDefault()) == "true") { - only = true - } - } - } - } - } - if (value.startsWith(root)) { - //文件检查Root - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = compileConfiguration.getColumnNum() - 1 - val path = value.subSequence(root.length, value.length) - val file = - File(compileConfiguration.modClass.modFile.absolutePath + "/" + path) - if (!file.exists()) { - //抛出文件不存在错误 - compileConfiguration.addError( - codeIndex, CompileConfiguration.ErrorRecord( - String.format( - compileConfiguration.context.getString(R.string.compiler_error3), - file.name, - file.absolutePath - ), - errorType = CompileConfiguration.ErrorType.Error, - function = { - compilerListener.onClickResourceErrorItem( - finalLineNum, - finalColumnNum, - it, - file - ) - } - ) - ) - } - } else { - //目录检查 - if (apkFolder == null) { - val file = getTargetFile(sourceFileFolder, value, type) - if (!file.exists()) { - //抛出文件不存在错误 - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = compileConfiguration.getColumnNum() - 1 - compileConfiguration.addError( - codeIndex, CompileConfiguration.ErrorRecord( - String.format( - compileConfiguration.context.getString(R.string.compiler_error3), - file.name, - file.absolutePath - ), - errorType = CompileConfiguration.ErrorType.Error, - function = { - compilerListener.onClickResourceErrorItem( - finalLineNum, - finalColumnNum, - it, - file - ) - } - ) - ) - } - } else { - val file = getTargetFile(apkFolder, value, type) - if (!file.exists()) { - if (only) { - //抛出文件不存在错误 - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = - compileConfiguration.getColumnNum() - 1 - compileConfiguration.addError( - codeIndex, CompileConfiguration.ErrorRecord( - String.format( - compileConfiguration.context.getString(R.string.compiler_error3), - file.name, - file.absolutePath - ), - errorType = CompileConfiguration.ErrorType.Error, - function = { - compilerListener.onClickResourceErrorItem( - finalLineNum, - finalColumnNum, - it, - file - ) - } - ) - ) - } else { - val file2 = getTargetFile(sourceFileFolder, value, type) - if (!file2.exists()) { - //抛出文件不存在错误 - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = - compileConfiguration.getColumnNum() - 1 - compileConfiguration.addError( - codeIndex, CompileConfiguration.ErrorRecord( - String.format( - compileConfiguration.context.getString(R.string.compiler_error3), - file2.name, - file2.absolutePath - ), - errorType = CompileConfiguration.ErrorType.Error, - function = { - compilerListener.onClickResourceErrorItem( - finalLineNum, - finalColumnNum, - it, - file - ) - } - ) - ) - } - } - } - } - } - } - } - } else { - //如果有错误记录,则填入 - if (errorRecord.verifyFunction == null) { - compileConfiguration.addError(codeIndex, errorRecord) - } else { - if (errorRecord.verifyFunction!!.invoke(compileConfiguration)) { - compileConfiguration.addError(codeIndex, errorRecord) - } - } - } - } - } - compileConfiguration.setCanAddError(false) - } - - /** - * 检查文件方法 - * @param folder String - * @param value String - * @param type String? - * @return 文件是否存在 - */ - fun getTargetFile(folder: String, value: String, type: String? = null): File { - if (type != null) { - //检查是否需要添加类型符 - val lineParser = LineParser(type) - lineParser.symbol = "," - //默认文件 - var result = File(folder + "/" + value) - lineParser.analyse { lineNum, lineData, isEnd -> - if (value.endsWith(lineData)) { - //不需要(确定了类型) - val file = File(folder + "/" + value) - result = file - return@analyse false - } else { - val file = File(folder + "/" + value + "." + lineData) - result = file - //如果文件不存在继续循环 - return@analyse !result.exists() - } - } - return result - } else { - val file = File(folder + "/" + value) - return file - } - } - - /** - * 将SectionList转化为翻译 - * @param sectionList String - * @return String - */ - fun sectionListToTranslate(sectionList: String): String { - val lineParser = LineParser(sectionList) - val resultBuilder = StringBuilder() - lineParser.symbol = "," - lineParser.parserSymbol = true - lineParser.analyse { lineNum, lineData, isEnd -> - if (lineData == lineParser.symbol) { - resultBuilder.append(lineData) - return@analyse true - } - //检查是否有缓存 - if (sectionMap.containsKey(lineData)) { - val section = sectionMap[lineData] - resultBuilder.append(section?.translate ?: lineData) - } else { - val section = codeDataBase.getSectionDao().findSectionInfoByCode(lineData) - if (section != null) { - sectionMap[lineData] = section - resultBuilder.append(section.translate) - } - } - true - } - return resultBuilder.toString() - } - - /** - * 获取值类型数据 - * @param type String - * @return ValueTypeInfo - */ - private fun getValueData(type: String): ValueTypeInfo? { - return if (valueTypeMap.containsKey(type)) { - valueTypeMap[type]!! - } else { - val typeInfo = codeDataBase.getValueTypeDao().findTypeByType(type) - if (typeInfo != null) { - valueTypeMap[type] = typeInfo - - } - typeInfo - } - } - - /** - * 分析节数据 - * @param section String 节 可以是英文也可以是翻译,默认为翻译 - * @param codeResult StringBuilder - * @param compileConfiguration CompileConfiguration - * @param compilerListener CodeCompilerListener? - * @param needCompile Boolean 是否需要编译默认为真 - */ - private fun analysisSection( - section: String, - codeResult: StringBuilder, - compileConfiguration: CompileConfiguration, - compilerListener: CodeCompilerListener? = null, - needCompile: Boolean = true - ) { - compileConfiguration.setCanAddError(true) - //节 - compileConfiguration.codeBlockType = CompileConfiguration.CodeBlockType.Section - val symbolPosition = section.lastIndexOf("_") - if (symbolPosition > 0) { - val sectionPrefixName = section.substring(1, symbolPosition) - codeResult.append("[") - if (needCompile) { - val info = if (englishMode) { - codeDataBase.getSectionDao() - .findSectionInfoByCode(sectionPrefixName) - } else { - codeDataBase.getSectionDao() - .findSectionInfoByTranslate(sectionPrefixName) - } - //判断是否应该有附加名(当监听器不为空时) - if (compilerListener != null) { - //不需要附加名抛出异常 - if (info == null) { - compileConfiguration.addError( - compileConfiguration.createCodeIndex(section), - CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.section_not_find_error), - section - ) - ) - ) - } else { - if (!info.needName) { - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = section.length - 1 - compileConfiguration.addError(compileConfiguration.createCodeIndex( - section - ), - CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.need_name_error1), - section - ), { - compilerListener.onClickSectionNameErrorItem( - finalLineNum, finalColumnNum, - it, - section, - symbolPosition, false - ) - } - ) - ) - } - } - } - compileConfiguration.lastSection = info?.code ?: sectionPrefixName - codeResult.append( - info?.code ?: sectionPrefixName - ) - } else { - //无需编译 - val oldError = errorRecordMap[compileConfiguration.createCodeIndex(section)] - if (oldError != null) { - compileConfiguration.addError( - compileConfiguration.createCodeIndex(section), - oldError - ) - } - compileConfiguration.lastSection = sectionPrefixName - codeResult.append(sectionPrefixName) - } - codeResult.append("_") - codeResult.append(section.substring(symbolPosition + 1)) - } else { - val sectionCode = section.substring(1, section.length - 1) - codeResult.append("[") - if (needCompile) { - val info = if (englishMode) { - codeDataBase.getSectionDao() - .findSectionInfoByCode(sectionCode) - } else { - codeDataBase.getSectionDao() - .findSectionInfoByTranslate(sectionCode) - } - //判断是否应该有附加名(当监听器不为空时) - if (compilerListener != null) { - if (info == null) { - compileConfiguration.addError( - compileConfiguration.createCodeIndex(section), - CompileConfiguration.ErrorRecord( - String.format( - context.getString(R.string.section_not_find_error), - section - ) - ) - ) - } else { - if (info.needName) { - //需要附加名抛出异常 - val finalLineNum = compileConfiguration.getLineNum() - val finalColumnNum = section.length - 1 - compileConfiguration.addError( - compileConfiguration.createCodeIndex(section), - CompileConfiguration.ErrorRecord(String.format( - context.getString(R.string.need_name_error2), - section - ), { - compilerListener.onClickSectionNameErrorItem( - finalLineNum, finalColumnNum, - it, - section, null, true - ) - }) - ) - } - } - } - compileConfiguration.lastSection = info?.code ?: sectionCode - codeResult.append( - info?.code ?: sectionCode - ) - } else { - val oldError = errorRecordMap[compileConfiguration.createCodeIndex(section)] - if (oldError != null) { - compileConfiguration.addError( - compileConfiguration.createCodeIndex(section), - oldError - ) - } - compileConfiguration.lastSection = sectionCode - codeResult.append(sectionCode) - } - codeResult.append("]") - } - compileConfiguration.setCanAddError(false) - } - - /** - * 是否为主线程 - */ - private fun isMainThread(): Boolean { - return Looper.myLooper() == Looper.getMainLooper() - } - - /** - * 翻译 - * @param code String 代码 - * @param translatorListener CodeTranslatorListener 代码翻译监听器 - */ - override fun translation(code: String, translatorListener: CodeTranslatorListener) { - if (isMainThread()) { - executorService.submit { - translationWork(code, translatorListener) - } - } else { - translationWork(code, translatorListener) - } - } - - /** - * 编译方法 - * @param code String 代码 - * @param compileConfiguration CompileConfiguration 配置 - * @param compilerListener CodeCompilerListener? 监听器 - */ - override fun compile( - code: String, - compileConfiguration: CompileConfiguration, - compilerListener: CodeCompilerListener? - ) { - if (isMainThread()) { - executorService.submit { - compileWork(code, compileConfiguration, compilerListener) - } - } else { - compileWork(code, compileConfiguration, compilerListener) - } - } - - override fun isEnglishMode(): Boolean { - return englishMode - } - - override fun setEnglish(englishMode: Boolean) { - this.englishMode = englishMode - } - -} \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeTranslate.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeTranslate.kt new file mode 100644 index 0000000..acfa1dd --- /dev/null +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeTranslate.kt @@ -0,0 +1,21 @@ +package com.coldmint.rust.core + +/** + * 代码编辑器类 + */ +class CodeCompiler(val input: String) { + + + //英文模式 + private var englishMode: Boolean = false + + /** + * 设置是否启用英文模式 当启用时禁用翻译和编译功能 + * @param enable Boolean + */ + fun setEnglishMode(enable: Boolean) { + this.englishMode = enable + } + + +} \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt deleted file mode 100644 index f4573b4..0000000 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt +++ /dev/null @@ -1,314 +0,0 @@ -package com.coldmint.rust.core.dataBean - -import android.content.Context -import android.graphics.Color -import android.graphics.drawable.Drawable -import android.text.SpannableString -import android.text.Spanned -import android.text.style.ClickableSpan -import android.text.style.ForegroundColorSpan -import android.util.Log -import android.view.View -import com.coldmint.rust.core.* -import com.coldmint.rust.core.tool.DebugHelper -import java.io.File - -/** - * @author Cold Mint - * @date 2022/1/27 15:09 - */ -data class CompileConfiguration( - val context: Context, - val openedSourceFile: OpenedSourceFile, - val modClass: ModClass, - val apkFolder: File, - private var line: Int = 0, - private var column: Int = 0, - private var errorNumber: Int = 0, - private var warningNumber: Int = 0, - var codeBlockType: CodeBlockType = CodeBlockType.Key, - var lastSection: String? = null, - //只能在特定函数内添加错误,否则将抛出异常 - private var canAddError: Boolean = false, - private val keyBuilder: StringBuilder = StringBuilder(), - private val valueBuilder: StringBuilder = StringBuilder(), - private val arrayList: ArrayList = ArrayList(), - private val errorIcon: Drawable? = context.getDrawable(R.drawable.error), - private val warningIcon: Drawable? = context.getDrawable(R.drawable.warning), - private val lineData: StringBuilder = StringBuilder(), - //错误记录映射记录表() - private - var errorRecordMap: HashMap? = null -) { - - - /** - * 增加值 - * @param string String - */ - fun appendValue(string: String) { - if (codeBlockType == CodeBlockType.Reference) { - valueBuilder.append(string) - } else { - Log.e(CodeCompiler2.debugKey, "只能在引用语句块设置值。") - } - } - - /** - * 增加键 - * @param string String - */ - fun appendKey(string: String) { - if (codeBlockType == CodeBlockType.Reference) { - keyBuilder.append(string) - } else { - Log.e(CodeCompiler2.debugKey, "只能在引用语句块设置键。") - } - } - - /** - * 设置是否可以添加错误(只能在特定的函数内添加错误) - * @param canAddError Boolean - */ - fun setCanAddError(canAddError: Boolean) { - this.canAddError = canAddError - } - - /** - * 追加结果到Key或Value,仅在行内有效 - * @param string String - */ - fun appendResult(string: String) { - when (codeBlockType) { - CodeBlockType.Key -> { - keyBuilder.append(string) - lineData.append(string) - lineData.append(':') - } - CodeBlockType.Value -> { - valueBuilder.append(string) - lineData.append(string) - } - else -> { - DebugHelper.printLog( - CodeCompiler2.debugKey, - "无法分配[" + string + "],因为代码类型为" + codeBlockType + "不是Value或Key", "追加结果", - true - ) - } - } - } - - /** - * 获取Key - * @param needTrim Boolean 是否需要去除空格 - * @return String - */ - fun getKey(needTrim: Boolean = true): String { - return if (needTrim) { - keyBuilder.toString().trim() - } else { - keyBuilder.toString() - } - } - - /** - * 获取行内容 - * @return String - */ - fun getLineData(): String { - return lineData.toString() - } - - - /** - * 获取Value - * @param needTrim Boolean 是否需要去除空格 - * @return String - */ - fun getValue(needTrim: Boolean = true): String { - return if (needTrim) { - valueBuilder.toString().trim() - } else { - valueBuilder.toString() - } - } - - /** - * 设置错误映射对象 - * @param errorRecordMap HashMap? - */ - fun setErrorRecordMap(errorRecordMap: HashMap?) { - this.errorRecordMap = errorRecordMap - } - - //通常 跟随主题色 - //警告 标识为黄色 - //错误 标识为红色 - enum class ErrorType { - General, Warning, Error - } - - /** - * 代码块类 - * 键,值,节,注释,变量名,引用 - * Reference 引用是一种特殊的数据类型,编译器会尝试编译此值,若无法编译则使用原始值 - */ - enum class CodeBlockType { - Key, Value, Section, Note, VariableName, Reference, Symbol - } - - /** - * 错误记录 - * @property info String 错误信息 - * @property function function? 点击事件 - * @property errorType ErrorType 错误类型 - * @property verifyFunction Function0? 错误验证函数(会被二次执行,返回真则不再显示内容) - * @constructor - */ - data class ErrorRecord( - val info: String, - var function: ((View) -> Unit)? = null, - val errorType: ErrorType = ErrorType.Warning, - var verifyFunction: ((CompileConfiguration) -> Boolean)? = null, - ) - - - /** - * 代码位置记录 - * @property string String - * @property line Int - * @property column Int - * @constructor - */ - data class CodeIndex(val string: String, val line: Int, val column: Int) - - /** - * 创建代码位置记录 - * @param string String - * @return CodeIndex - */ - fun createCodeIndex(string: String): CodeIndex { - return CodeIndex(string, line, column) - } - - /** - * 获取错误数量 - * @return Int - */ - fun getErrorNumber(): Int { - return errorNumber - } - - /** - * 获取解析结果 - * @return List - */ - fun getAnalysisResult(): List { - return arrayList.toList() - } - - /** - * 获取警告数量 - * @return Int - */ - fun getWarningNumber(): Int { - return warningNumber - } - - /** - * 添加错误 - * 若未同步错误表[CompileConfiguration.setErrorRecordMap]则抛出异常 - * 使用[CompileConfiguration.setCanAddError]授权方法添加错误 - * @param codeIndex 代码位置记录 - * @param errorRecord ErrorRecord 错误记录 - */ - fun addError(codeIndex: CodeIndex, errorRecord: ErrorRecord) { - if (!canAddError) { - arrayList.add( - AnalysisResult( - getLineData(), - "程序错误:未经许可的方法被调用。$errorRecord", - errorIcon, errorType = ErrorType.General - ) - ) - return - } - val location = String.format( - context.getString(R.string.location_info), - openedSourceFile.file.name, - line + 1 - ) - val analysisResult = - AnalysisResult( - getLineData(), - location + errorRecord.info, - errorType = errorRecord.errorType - ) - analysisResult.function = errorRecord.function - when (errorRecord.errorType) { - ErrorType.Error -> { - analysisResult.icon = errorIcon - errorNumber++ - } - ErrorType.Warning -> { - analysisResult.icon = warningIcon - warningNumber++ - } - else -> {} - } - if (errorRecordMap == null) { - throw NullPointerException("错误记录表未同步。") - } else { - errorRecordMap?.set(codeIndex, errorRecord) - } - arrayList.add(analysisResult) - } - - - /** - * 添加编译信息 - * @param string String - */ - fun addInfo(string: String) { - val analysisResult = AnalysisResult(getLineData(), string, errorType = ErrorType.General) - arrayList.add(analysisResult) - } - - /** - * 获取行号 - * @return Int - */ - fun getLineNum(): Int { - return line - } - - /** - * 获取列号 - * @return Int - */ - fun getColumnNum(): Int { - return column - } - - /** - * 将光标指向下一行(初始化行参数) - */ - fun nextLine() { - line++ - column = 0 - codeBlockType = CodeBlockType.Key - keyBuilder.clear() - valueBuilder.clear() - lineData.clear() - } - - /** - * 添加列内容(添加列值) - * @param string String - */ - fun addColumn(string: String) { - column += string.length - } - -} diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/ModErrorReport.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/ModErrorReport.kt deleted file mode 100644 index 5fd8cb9..0000000 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/ModErrorReport.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.coldmint.rust.core.dataBean - -/** - * 模组错误报告(开发者模式测试使用) - * @property modPath String - * @property errorNumber Int - * @property warningNumber Int - * @constructor - */ -data class ModErrorReport( - val modPath: String, - private var errorNumber: Int = 0, - private var warningNumber: Int = 0, - private val errorList: ArrayList = ArrayList() -) { - /** - * 添加单位错误报告 - * @param compileConfiguration CompileConfiguration - */ - fun addFileReport(compileConfiguration: CompileConfiguration) { - if (compileConfiguration.getErrorNumber() > 0) { - errorList.add(compileConfiguration.openedSourceFile.file.absolutePath) - } - this.errorNumber += compileConfiguration.getErrorNumber() - this.warningNumber += compileConfiguration.getWarningNumber() - } -} \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerInterface.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerInterface.kt deleted file mode 100644 index 69ba425..0000000 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerInterface.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.coldmint.rust.core.interfaces - -import com.coldmint.rust.core.dataBean.CompileConfiguration - -/** - * @author Cold Mint - * @date 2022/1/27 16:37 - */ -interface CodeCompilerInterface { - - /** - * 实现翻译方法 - * @param code String - * @param translatorListener CodeTranslatorListener - */ - fun translation(code: String, translatorListener: CodeTranslatorListener) - - - /** - * 编译方法 - * @param code String - * @param compileConfiguration CompileConfiguration - * @param compilerListener CodeCompilerListener? - */ - fun compile( - code: String, - compileConfiguration: CompileConfiguration, - compilerListener: CodeCompilerListener? = null - ) -} \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerListener.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerListener.kt deleted file mode 100644 index 68bf313..0000000 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/interfaces/CodeCompilerListener.kt +++ /dev/null @@ -1,123 +0,0 @@ -package com.coldmint.rust.core.interfaces - -import android.text.SpannableString -import android.view.View -import com.coldmint.rust.core.AnalysisResult -import com.coldmint.rust.core.dataBean.CompileConfiguration -import com.coldmint.rust.core.database.code.ValueTypeInfo -import java.io.File - -interface CodeCompilerListener { - /** - * 当编译完成时 - * @param compileConfiguration CompileConfiguration 编译配置(包含错误信息) - * @param code String 代码 - */ - fun onCompilationComplete(compileConfiguration: CompileConfiguration, code: String) - - /** - * 当翻译之前 - */ - fun beforeCompilation() - - /** - * 当点击Key不存在项目 - * @param lineNum Int 行号 - * @param view View 视图 - * @param code String 代码 - * @param section String 节 - */ - - fun onClickKeyNotFoundItem( - lineNum: Int, - columnNum: Int, - view: View, - code: String, - section: String - ) - - /** - * 当点击值类型错误项目 - * @param lineNum Int 行号 - * @param columnNum 列号 - * @param view View 视图 - * @param valueType ValueTypeInfo 值类型 - */ - - fun onClickValueTypeErrorItem( - lineNum: Int, - columnNum: Int, - view: View, - valueType: ValueTypeInfo - ) - - - /** - * 当点击节位置错误 - * @param lineNum Int - * @param columnNum Int - * @param view View - * @param sectionName String - */ - - fun onClickSectionIndexError(lineNum: Int, columnNum: Int, view: View, sectionName: String) - - /** - * 当点击资源文件不存在项目 - * @param lineNum Int 行号 - * @param view View 视图 - * @param resourceFile File 资源文件 - */ - fun onClickResourceErrorItem(lineNum: Int, columnNum: Int, view: View, resourceFile: File) - - /** - * 当点击节错误项目(未知的节) - * @param lineNum Int 行号 - * @param view View 视图 - * @param displaySectionName String 显示的节名 - */ - fun onClickSectionErrorItem(lineNum: Int, view: View, displaySectionName: String) - - - /** - * 单击了游戏同步项目 - * @param lineNum Int - * @param columnNum Int - * @param view View - */ - fun onClickSynchronizationGame(lineNum: Int, columnNum: Int, view: View) - - /** - * 当点击节名错误项目 - * @param lineNum Int 行号 - * @param columnNum Int 列名 - * @param view View 视图 - * @param sectionName String 节名 - * @param needName Boolean 是否需要附加名 - */ - - fun onClickSectionNameErrorItem( - lineNum: Int, - columnNum: Int, - view: View, - sectionName: String, - symbolIndex: Int?, - needName: Boolean - ) - - /** - * 当点击代码位置错误 - * @param lineNum Int 行号 - * @param view View 视图 - * @param sectionName String 节名 - */ - - fun onClickCodeIndexErrorItem(lineNum: Int, view: View, sectionName: String) - - /** - * 当展示编译结果 - * @param code String - * @return Boolean - */ - fun onShowCompilationResult(code: String): Boolean -} \ No newline at end of file