修复第一次运行助手时,没有游戏目录,没权限无法创建模组的问题。
This commit is contained in:
parent
a2c721dd1d
commit
ef95908cd4
|
@ -12,6 +12,7 @@ import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.widget.addTextChangedListener
|
import androidx.core.widget.addTextChangedListener
|
||||||
import com.coldmint.rust.pro.databinding.ActivityCreateModBinding
|
import com.coldmint.rust.pro.databinding.ActivityCreateModBinding
|
||||||
|
import com.coldmint.rust.pro.tool.GlobalMethod
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
@ -32,22 +33,22 @@ class CreateModActivity : BaseActivity<ActivityCreateModBinding>() {
|
||||||
val name = it.toString()
|
val name = it.toString()
|
||||||
if (name.isBlank()) {
|
if (name.isBlank()) {
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.modNameEdit,
|
viewBinding.modNameEdit,
|
||||||
String.format(
|
String.format(
|
||||||
getString(R.string.please_input_value),
|
getString(R.string.please_input_value),
|
||||||
viewBinding.modDescribeInputLayout.hint.toString()
|
viewBinding.modDescribeInputLayout.hint.toString()
|
||||||
),
|
),
|
||||||
viewBinding.modNameInputLayout, false
|
viewBinding.modNameInputLayout, false
|
||||||
)
|
)
|
||||||
return@addTextChangedListener
|
return@addTextChangedListener
|
||||||
}
|
}
|
||||||
val mod_directory =
|
val mod_directory =
|
||||||
File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name)
|
File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name)
|
||||||
if (mod_directory.exists()) {
|
if (mod_directory.exists()) {
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.modNameEdit,
|
viewBinding.modNameEdit,
|
||||||
getString(R.string.directory_error),
|
getString(R.string.directory_error),
|
||||||
viewBinding.modNameInputLayout, false
|
viewBinding.modNameInputLayout, false
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
viewBinding.modNameInputLayout.isErrorEnabled = false
|
viewBinding.modNameInputLayout.isErrorEnabled = false
|
||||||
|
@ -67,9 +68,9 @@ class CreateModActivity : BaseActivity<ActivityCreateModBinding>() {
|
||||||
override fun afterTextChanged(s: Editable) {
|
override fun afterTextChanged(s: Editable) {
|
||||||
if (s.toString().contains("\n")) {
|
if (s.toString().contains("\n")) {
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.modDescribeEdit,
|
viewBinding.modDescribeEdit,
|
||||||
getString(R.string.describe_error2),
|
getString(R.string.describe_error2),
|
||||||
viewBinding.modDescribeInputLayout
|
viewBinding.modDescribeInputLayout
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,28 +79,28 @@ class CreateModActivity : BaseActivity<ActivityCreateModBinding>() {
|
||||||
val name: String = viewBinding.modNameEdit.text.toString()
|
val name: String = viewBinding.modNameEdit.text.toString()
|
||||||
if (name.isBlank()) {
|
if (name.isBlank()) {
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.modNameEdit,
|
viewBinding.modNameEdit,
|
||||||
String.format(
|
String.format(
|
||||||
getString(R.string.please_input_value),
|
getString(R.string.please_input_value),
|
||||||
viewBinding.modNameInputLayout.hint.toString()
|
viewBinding.modNameInputLayout.hint.toString()
|
||||||
),
|
),
|
||||||
viewBinding.modNameInputLayout
|
viewBinding.modNameInputLayout
|
||||||
)
|
)
|
||||||
return@OnClickListener
|
return@OnClickListener
|
||||||
}
|
}
|
||||||
val describe: String = viewBinding.modDescribeEdit.text.toString()
|
val describe: String = viewBinding.modDescribeEdit.text.toString()
|
||||||
if (describe.isEmpty()) {
|
if (describe.isEmpty()) {
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.modDescribeEdit,
|
viewBinding.modDescribeEdit,
|
||||||
getString(R.string.describe_error),
|
getString(R.string.describe_error),
|
||||||
viewBinding.modDescribeInputLayout
|
viewBinding.modDescribeInputLayout
|
||||||
)
|
)
|
||||||
return@OnClickListener
|
return@OnClickListener
|
||||||
} else if (describe.contains("\n")) {
|
} else if (describe.contains("\n")) {
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.modDescribeEdit,
|
viewBinding.modDescribeEdit,
|
||||||
getString(R.string.describe_error2),
|
getString(R.string.describe_error2),
|
||||||
viewBinding.modDescribeInputLayout
|
viewBinding.modDescribeInputLayout
|
||||||
)
|
)
|
||||||
return@OnClickListener
|
return@OnClickListener
|
||||||
}
|
}
|
||||||
|
@ -108,34 +109,34 @@ class CreateModActivity : BaseActivity<ActivityCreateModBinding>() {
|
||||||
stringBuilder.append(name)
|
stringBuilder.append(name)
|
||||||
stringBuilder.append("\ndescription: ")
|
stringBuilder.append("\ndescription: ")
|
||||||
stringBuilder.append(describe)
|
stringBuilder.append(describe)
|
||||||
val minVersion:String = viewBinding.minVersionEdit.text.toString()
|
val minVersion: String = viewBinding.minVersionEdit.text.toString()
|
||||||
if (minVersion.isNotBlank()){
|
if (minVersion.isNotBlank()) {
|
||||||
stringBuilder.append("\nminVersion: ")
|
stringBuilder.append("\nminVersion: ")
|
||||||
stringBuilder.append(minVersion)
|
stringBuilder.append(minVersion)
|
||||||
}
|
}
|
||||||
val mod_directory =
|
GlobalMethod.requestStoragePermissions(this@CreateModActivity) {
|
||||||
File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name)
|
if (!it) {
|
||||||
if (mod_directory.exists()) {
|
return@requestStoragePermissions
|
||||||
setErrorAndInput(
|
}
|
||||||
viewBinding.modNameEdit,
|
val mod_directory =
|
||||||
getString(R.string.directory_error),
|
File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name)
|
||||||
viewBinding.modNameInputLayout
|
if (mod_directory.exists()) {
|
||||||
)
|
setErrorAndInput(
|
||||||
} else {
|
viewBinding.modNameEdit,
|
||||||
if (mod_directory.mkdirs()) {
|
getString(R.string.directory_error),
|
||||||
try {
|
viewBinding.modNameInputLayout
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (mod_directory.mkdirs()) {
|
||||||
val fileWriter = FileWriter(mod_directory.absolutePath + "/mod-info.txt")
|
val fileWriter = FileWriter(mod_directory.absolutePath + "/mod-info.txt")
|
||||||
fileWriter.write(stringBuilder.toString())
|
fileWriter.write(stringBuilder.toString())
|
||||||
fileWriter.close()
|
fileWriter.close()
|
||||||
setResult(RESULT_OK)
|
setResult(RESULT_OK)
|
||||||
finish()
|
finish()
|
||||||
} catch (e: IOException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Toast.makeText(this@CreateModActivity, "你的手机拒绝创建目录", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user