@@ -10,98 +10,98 @@ import java.io.File
1010
1111@ReactModule(name = BsDiffPatchModule .NAME )
1212class BsDiffPatchModule (reactContext : ReactApplicationContext ? ) :
13- ReactContextBaseJavaModule (reactContext) {
14- override fun getName (): String {
15- return NAME
16- }
13+ ReactContextBaseJavaModule (reactContext) {
14+ override fun getName (): String {
15+ return NAME
16+ }
1717
18- fun getFileDir (dir : String ): String {
19- if (dir.startsWith(" file://" )) {
20- return dir.substring(7 )
21- }
22- return dir
18+ private fun getFileDir (dir : String ): String {
19+ if (dir.startsWith(" file://" )) {
20+ return dir.substring(7 )
2321 }
22+ return dir
23+ }
2424
25- // Example method
26- // See https://reactnative.dev/docs/native-modules-android
27- @ReactMethod
28- fun patch (oldFile : String? , newFile : String? , patchFile : String? , promise : Promise ) {
29- if (oldFile == null || newFile == null || patchFile == null || oldFile.isEmpty() || newFile.isEmpty() || patchFile.isEmpty()) {
30- promise.reject(" error" , " oldFile, newFile, patchFile can not be null or empty" )
31- return
32- }
33- if (oldFile == newFile || oldFile == patchFile || newFile == patchFile) {
34- promise.reject(" error" , " oldFile, newFile, patchFile can not be the same" )
35- return
36- }
37- val oldFileObj = File (getFileDir(oldFile))
38- if (! oldFileObj.exists()) {
39- promise.reject(" error" , " oldFile not exist" )
40- return
41- }
42- val patchFileObj = File (getFileDir(patchFile))
43- if (! patchFileObj.exists()) {
44- promise.reject(" error" , " patchFile not exist" )
45- return
46- }
47- val newFileObj = File (getFileDir(newFile))
48- if (newFileObj.exists()) {
49- promise.reject(" error" , " newFile already exist" )
50- return
51- }
52- try {
53- val result = bsPatchFile(oldFileObj.absolutePath, newFileObj.absolutePath, patchFileObj.absolutePath)
54- promise.resolve(result)
55- } catch (e: Exception ) {
56- promise.reject(" error" , e.message)
57- }
25+ // Example method
26+ // See https://reactnative.dev/docs/native-modules-android
27+ @ReactMethod
28+ fun patch (oldFile : String? , newFile : String? , patchFile : String? , promise : Promise ) {
29+ if (oldFile == null || newFile == null || patchFile == null || oldFile.isEmpty() || newFile.isEmpty() || patchFile.isEmpty()) {
30+ promise.reject(" error" , " oldFile, newFile, patchFile can not be null or empty" )
31+ return
32+ }
33+ if (oldFile == newFile || oldFile == patchFile || newFile == patchFile) {
34+ promise.reject(" error" , " oldFile, newFile, patchFile can not be the same" )
35+ return
36+ }
37+ val oldFileObj = File (getFileDir(oldFile))
38+ if (! oldFileObj.exists()) {
39+ promise.reject(" error" , " oldFile: $oldFile not exist" )
40+ return
41+ }
42+ val patchFileObj = File (getFileDir(patchFile))
43+ if (! patchFileObj.exists()) {
44+ promise.reject(" error" , " patchFile: $patchFile not exist" )
45+ return
5846 }
47+ val newFileObj = File (getFileDir(newFile))
48+ if (newFileObj.exists()) {
49+ promise.reject(" error" , " newFile: $newFile already exist" )
50+ return
51+ }
52+ try {
53+ val result = bsPatchFile(oldFileObj.absolutePath, newFileObj.absolutePath, patchFileObj.absolutePath)
54+ promise.resolve(result)
55+ } catch (e: Exception ) {
56+ promise.reject(" error" , e.message)
57+ }
58+ }
5959
60- @ReactMethod
61- fun diff (oldFile : String? , newFile : String? , patchFile : String? , promise : Promise ) {
62- if (oldFile == null || newFile == null || patchFile == null || oldFile.isEmpty() || newFile.isEmpty() || patchFile.isEmpty()) {
63- promise.reject(" error" , " oldFile, newFile, patchFile can not be null or empty" )
64- return
65- }
66- if (oldFile == newFile || oldFile == patchFile || newFile == patchFile) {
67- promise.reject(" error" , " oldFile, newFile, patchFile can not be the same" )
68- return
69- }
70- val oldFileObj = File (getFileDir(oldFile))
71- if (! oldFileObj.exists()) {
72- promise.reject(" error" , " oldFile not exist" )
73- return
74- }
75- val newFileObj = File (getFileDir(newFile))
76- if (! newFileObj.exists()) {
77- promise.reject(" error" , " newFile not exist" )
78- return
79- }
80- val patchFileObj = File (getFileDir(patchFile))
81- if (patchFileObj.exists()) {
82- promise.reject(" error" , " patchFile already exist" )
83- return
84- }
85- try {
86- val result = bsDiffFile(oldFileObj.absolutePath, newFileObj.absolutePath, patchFileObj.absolutePath)
87- promise.resolve(result)
88- } catch (e: Exception ) {
89- promise.reject(" error" , e.message)
90- }
60+ @ReactMethod
61+ fun diff (oldFile : String? , newFile : String? , patchFile : String? , promise : Promise ) {
62+ if (oldFile == null || newFile == null || patchFile == null || oldFile.isEmpty() || newFile.isEmpty() || patchFile.isEmpty()) {
63+ promise.reject(" error" , " oldFile, newFile, patchFile can not be null or empty" )
64+ return
65+ }
66+ if (oldFile == newFile || oldFile == patchFile || newFile == patchFile) {
67+ promise.reject(" error" , " oldFile, newFile, patchFile can not be the same" )
68+ return
9169 }
70+ val oldFileObj = File (getFileDir(oldFile))
71+ if (! oldFileObj.exists()) {
72+ promise.reject(" error" , " oldFile: $oldFile not exist" )
73+ return
74+ }
75+ val newFileObj = File (getFileDir(newFile))
76+ if (! newFileObj.exists()) {
77+ promise.reject(" error" , " newFile: $newFile not exist" )
78+ return
79+ }
80+ val patchFileObj = File (getFileDir(patchFile))
81+ if (patchFileObj.exists()) {
82+ promise.reject(" error" , " patchFile: $patchFile already exist" )
83+ return
84+ }
85+ try {
86+ val result = bsDiffFile(oldFileObj.absolutePath, newFileObj.absolutePath, patchFileObj.absolutePath)
87+ promise.resolve(result)
88+ } catch (e: Exception ) {
89+ promise.reject(" error" , e.message)
90+ }
91+ }
9292
93- companion object {
94- const val NAME = " BsDiffPatch"
93+ companion object {
94+ const val NAME = " BsDiffPatch"
9595
96- init {
97- System .loadLibrary(" react-native-bs-diff-patch" )
98- }
96+ init {
97+ System .loadLibrary(" react-native-bs-diff-patch" )
98+ }
9999
100- // Used to load the 'native-lib' library on application startup.
101- // get new file from old file and patch file
102- private external fun bsPatchFile (oldFile : String , newFile : String , patchFile : String ): Int
100+ // Used to load the 'native-lib' library on application startup.
101+ // get new file from old file and patch file
102+ private external fun bsPatchFile (oldFile : String , newFile : String , patchFile : String ): Int
103103
104- // generate patch file
105- private external fun bsDiffFile (oldFile : String , newFile : String , patchFile : String ): Int
106- }
104+ // generate patch file
105+ private external fun bsDiffFile (oldFile : String , newFile : String , patchFile : String ): Int
106+ }
107107}
0 commit comments