Commit 9f122193 authored by Mygod's avatar Mygod

Use file to persist custom rules to avoid 1MB limit

parent f3b2920d
......@@ -97,9 +97,9 @@ object Core {
if (Build.VERSION.SDK_INT >= 24) { // migrate old files
deviceStorage.moveDatabaseFrom(app, Key.DB_PUBLIC)
val old = Acl.getFile(Acl.CUSTOM_RULES, app)
val old = Acl.getFile(Acl.CUSTOM_RULES_USER, app)
if (old.canRead()) {
Acl.getFile(Acl.CUSTOM_RULES).writeText(old.readText())
Acl.getFile(Acl.CUSTOM_RULES_USER).writeText(old.readText())
old.delete()
}
}
......
......@@ -24,7 +24,6 @@ import android.content.Context
import androidx.recyclerview.widget.SortedList
import com.github.shadowsocks.Core
import com.github.shadowsocks.net.Subnet
import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.BaseSorter
import com.github.shadowsocks.utils.URLSorter
import com.github.shadowsocks.utils.asIterable
......@@ -48,6 +47,7 @@ class Acl {
const val GFWLIST = "gfwlist"
const val CHINALIST = "china-list"
const val CUSTOM_RULES = "custom-rules"
const val CUSTOM_RULES_USER = "custom-rules-user"
private val networkAclParser = "^IMPORT_URL\\s*<(.+)>\\s*$".toRegex()
......@@ -56,17 +56,15 @@ class Acl {
var customRules: Acl
get() {
val acl = Acl()
val str = DataStore.publicStore.getString(CUSTOM_RULES)
if (str != null) acl.fromReader(str.reader(), true)
val file = getFile(CUSTOM_RULES_USER)
if (file.canRead()) acl.fromReader(file.reader(), true)
if (!acl.bypass) {
acl.bypass = true
acl.subnets.clear()
}
return acl
}
set(value) = DataStore.publicStore.putString(CUSTOM_RULES,
if ((!value.bypass || value.subnets.size() == 0) && value.bypassHostnames.size() == 0 &&
value.proxyHostnames.size() == 0 && value.urls.size() == 0) null else value.toString())
set(value) = getFile(CUSTOM_RULES_USER).writeText(value.toString())
fun save(id: String, acl: Acl) = getFile(id).writeText(acl.toString())
suspend fun <T> parse(reader: Reader, bypassHostnames: (String) -> T, proxyHostnames: (String) -> T,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment