2
2
3
3
import java .io .File ;
4
4
import java .io .IOException ;
5
+ import java .net .URI ;
6
+ import java .net .URISyntaxException ;
5
7
import java .util .HashMap ;
6
8
7
9
import org .json .JSONException ;
@@ -28,10 +30,17 @@ public static void init(Context context)
28
30
{
29
31
return ;
30
32
}
31
-
32
- RootPackageDir = context .getApplicationInfo ().dataDir ;
33
-
34
- ApplicationFilesPath = context .getApplicationContext ().getFilesDir ().getPath ();
33
+
34
+ try
35
+ {
36
+ RootPackageDir = new File (context .getApplicationInfo ().dataDir ).getCanonicalPath ();
37
+ ApplicationFilesPath = context .getApplicationContext ().getFilesDir ().getCanonicalPath ();
38
+ }
39
+ catch (IOException e )
40
+ {
41
+ e .printStackTrace ();
42
+ }
43
+
35
44
ModulesFilesPath = "/app/" ;
36
45
37
46
NativeScriptModulesFilesPath = "/app/tns_modules/" ;
@@ -80,43 +89,43 @@ public static String getModulePath(String moduleName, String callingDirName)
80
89
{
81
90
// This method is called my the NativeScriptRuntime.cpp RequireCallback method.
82
91
// The currentModuleDir is the directory path of the calling module.
83
- // checkForExternalPath = true;
92
+ checkForExternalPath = true ;
84
93
File file = findModuleFile (moduleName , callingDirName );
85
94
86
95
if (file != null && file .exists ())
87
96
{
88
97
File projectRootDir = new File (RootPackageDir );
89
- // if (checkForExternalPath && isFileExternal(file, projectRootDir))
90
- // {
91
- // return "EXTERNAL_FILE_ERROR";
92
- // }
93
- // else
94
- // {
98
+ if (checkForExternalPath && isFileExternal (file , projectRootDir ))
99
+ {
100
+ return "EXTERNAL_FILE_ERROR" ;
101
+ }
102
+ else
103
+ {
95
104
return file .getAbsolutePath ();
96
- // }
105
+ }
97
106
}
98
107
99
108
// empty path will be handled by the NativeScriptRuntime.cpp and a JS error will be thrown
100
109
return "" ;
101
110
}
102
111
103
- // private static boolean isFileExternal(File source, File target)
104
- // {
105
- // File currentParentDir = source.getParentFile();
106
- //
107
- // while (currentParentDir != null)
108
- // {
109
- // if (currentParentDir.equals(target))
110
- // {
111
- // return false;
112
- // }
113
- //
114
- // currentParentDir = currentParentDir.getParentFile();
115
- // }
116
- //
117
- // return true;
118
- // }
112
+ private static boolean isFileExternal (File source , File target )
113
+ {
114
+ File currentParentDir = source .getParentFile ();
115
+
116
+ while (currentParentDir != null )
117
+ {
118
+ if (currentParentDir .equals (target ))
119
+ {
120
+ return false ;
121
+ }
119
122
123
+ currentParentDir = currentParentDir .getParentFile ();
124
+ }
125
+
126
+ return true ;
127
+ }
128
+
120
129
private static File findModuleFile (String moduleName , String currentDirectory )
121
130
{
122
131
File directory = null ;
0 commit comments