Skip to content

Commit

Permalink
enhance resiliency of provider json parsing
Browse files Browse the repository at this point in the history
update version to 2.5.6
  • Loading branch information
newhinton committed Sep 10, 2024
1 parent 5cac200 commit b0d1edb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
minSdkVersion 23
compileSdk 34
targetSdkVersion 34
versionCode 400 // last digit is reserved for ABI, only ever end on 0!
versionName '2.5.5'
versionCode 410 // last digit is reserved for ABI, only ever end on 0!
versionName '2.5.6'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "java.lang.String", "CLI", System.getenv('RCX_BUILD_CLI') ? System.getenv('RCX_BUILD_CLI') : "\"c03129b6-b09f-9cb4-8fcd-7f143b8f94ef\""
buildConfigField "java.lang.String", "VCP_AUTHORITY", "\"" + applicationId + ".vcp\"";
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/ca/pkay/rcloneexplorer/rclone/Provider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class Provider(val name: String) {
item.prefix = data.optString("Prefix")
item.commandHelp = data.optString("CommandHelp")

val options = data.getJSONArray("Options")
val options = data.optJSONArray("Options")

for (i in 0 until options.length()) {
item.options.add(ProviderOption.newInstance(options.getJSONObject(i)))
for (i in 0 until (options?.length() ?: 0)) {
ProviderOption.newInstance(options.getJSONObject(i))?.let { item.options.add(it) }
}

return item
Expand Down
61 changes: 35 additions & 26 deletions app/src/main/java/ca/pkay/rcloneexplorer/rclone/ProviderOption.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ca.pkay.rcloneexplorer.rclone

import android.util.Log
import de.felixnuesse.extract.extensions.tag
import org.json.JSONObject
import java.util.Objects

Expand All @@ -23,37 +25,44 @@ class ProviderOption {
var type: String = ""

companion object {
fun newInstance(data: JSONObject): ProviderOption {
val item = ProviderOption()
fun newInstance(data: JSONObject): ProviderOption? {

item.name = data.getString("Name")
item.help = data.getString("Help")
item.provider = data.getString("Type")
item.default = data.getString("Default")
//item.value = data.get("Value")
item.shortOpt = data.getString("ShortOpt")
item.hide = data.getInt("Hide")
item.required = data.getBoolean("Required")
item.isPassword = data.getBoolean("IsPassword")
item.noPrefix = data.getBoolean("NoPrefix")
item.advanced = data.getBoolean("Advanced")
item.exclusive = data.getBoolean("Exclusive")
item.defaultStr = data.getString("DefaultStr")
item.valueStr = data.getString("ValueStr")
item.type = data.getString("Type")
try {
val item = ProviderOption()

val examples = data.optJSONArray("Examples")
if (examples != null) {
for (i in 0 until examples.length()) {
item.examples.add(OptionExampleItem(
examples.getJSONObject(i).getString("Value"),
examples.getJSONObject(i).getString("Help"),
examples.getJSONObject(i).getString("Provider")
))
item.name = data.optString("Name")
item.help = data.optString("Help")
item.provider = data.optString("Type")
item.default = data.optString("Default")
//item.value = data.get("Value")
item.shortOpt = data.optString("ShortOpt")
item.hide = data.optInt("Hide")
item.required = data.optBoolean("Required")
item.isPassword = data.optBoolean("IsPassword")
item.noPrefix = data.optBoolean("NoPrefix")
item.advanced = data.optBoolean("Advanced")
item.exclusive = data.optBoolean("Exclusive")
item.defaultStr = data.optString("DefaultStr")
item.valueStr = data.optString("ValueStr")
item.type = data.optString("Type")

val examples = data.optJSONArray("Examples")
if (examples != null) {
for (i in 0 until examples.length()) {
item.examples.add(OptionExampleItem(
examples.getJSONObject(i).optString("Value"),
examples.getJSONObject(i).optString("Help"),
examples.getJSONObject(i).optString("Provider")
))
}
}

return item
} catch (e: Exception) {
Log.e(tag(), data.toString(4))
}

return item
return null
}
}

Expand Down

0 comments on commit b0d1edb

Please sign in to comment.