修复第一次运行助手时,没有游戏目录,没权限无法创建模组的问题。

This commit is contained in:
Cold-Mint 2024-03-02 15:25:40 +08:00
parent a2c721dd1d
commit ef95908cd4

View File

@ -12,6 +12,7 @@ import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.core.widget.addTextChangedListener
import com.coldmint.rust.pro.databinding.ActivityCreateModBinding
import com.coldmint.rust.pro.tool.GlobalMethod
import java.io.File
import java.io.FileWriter
import java.io.IOException
@ -108,11 +109,15 @@ class CreateModActivity : BaseActivity<ActivityCreateModBinding>() {
stringBuilder.append(name)
stringBuilder.append("\ndescription: ")
stringBuilder.append(describe)
val minVersion:String = viewBinding.minVersionEdit.text.toString()
if (minVersion.isNotBlank()){
val minVersion: String = viewBinding.minVersionEdit.text.toString()
if (minVersion.isNotBlank()) {
stringBuilder.append("\nminVersion: ")
stringBuilder.append(minVersion)
}
GlobalMethod.requestStoragePermissions(this@CreateModActivity) {
if (!it) {
return@requestStoragePermissions
}
val mod_directory =
File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name)
if (mod_directory.exists()) {
@ -123,19 +128,15 @@ class CreateModActivity : BaseActivity<ActivityCreateModBinding>() {
)
} else {
if (mod_directory.mkdirs()) {
try {
val fileWriter = FileWriter(mod_directory.absolutePath + "/mod-info.txt")
fileWriter.write(stringBuilder.toString())
fileWriter.close()
setResult(RESULT_OK)
finish()
} catch (e: IOException) {
e.printStackTrace()
}
} else {
Toast.makeText(this@CreateModActivity, "你的手机拒绝创建目录", Toast.LENGTH_SHORT).show()
}
}
}
})
}