@@ -8,13 +8,30 @@ import java.io.File
8
8
object Repositories {
9
9
10
10
const val RULES_DATABASE_NAME = " rules_database"
11
+ private const val LOCAL_RULES_VERSION_FILE = " lcrules/version"
11
12
12
13
fun checkRulesDatabase (context : Context ) {
13
14
if (! checkMd5(context) && ! checkVersion(context)) {
14
15
deleteRulesDatabase(context)
15
16
}
16
17
}
17
18
19
+ fun getLocalRulesVersion (context : Context ): Int {
20
+ val localCloudVersionFile = File (context.filesDir, LOCAL_RULES_VERSION_FILE )
21
+ if (localCloudVersionFile.exists().not ()) return LCRules .getVersion()
22
+ if (localCloudVersionFile.isDirectory.not ()) return LCRules .getVersion()
23
+ localCloudVersionFile.listFiles()?.takeIf { it.isNotEmpty() }?.let {
24
+ return runCatching { it[0 ].name.toInt() }.getOrDefault(LCRules .getVersion())
25
+ } ? : return LCRules .getVersion()
26
+ }
27
+
28
+ fun setLocalRulesVersion (context : Context , version : Int ): Boolean {
29
+ val localCloudVersionFile = File (context.filesDir, LOCAL_RULES_VERSION_FILE )
30
+ if (localCloudVersionFile.isDirectory.not ()) localCloudVersionFile.delete()
31
+ if (localCloudVersionFile.exists().not ()) localCloudVersionFile.mkdirs()
32
+ return File (localCloudVersionFile, version.toString()).createNewFile()
33
+ }
34
+
18
35
private fun deleteRulesDatabase (context : Context ) {
19
36
val databaseDir = context.getDatabasePath(RULES_DATABASE_NAME ).parent
20
37
FileUtils .delete(File (databaseDir, RULES_DATABASE_NAME ))
@@ -34,7 +51,7 @@ object Repositories {
34
51
}
35
52
36
53
private fun checkVersion (context : Context ): Boolean {
37
- val versionFile = File (context.filesDir, " lcrules/version " )
54
+ val versionFile = File (context.filesDir, LOCAL_RULES_VERSION_FILE )
38
55
if (versionFile.exists().not ()) return false
39
56
if (versionFile.isDirectory.not ()) return false
40
57
versionFile.listFiles()?.takeIf { it.isNotEmpty() }?.let {
0 commit comments