Make FileSystem.currentAppPath platform specific

This commit is contained in:
Jason Zhekov
2016-04-25 14:48:25 +03:00
parent 053d7201e2
commit b3561420f8
4 changed files with 26 additions and 10 deletions

View File

@ -193,6 +193,10 @@ export class FileSystemAccess {
return dir.getAbsolutePath();
}
public getCurrentAppPath(): string {
return this.getLogicalRootPath() + "/app";
}
public read(path: string, onError?: (error: any) => any) {
try {
var javaFile = new java.io.File(path);

View File

@ -104,6 +104,12 @@
*/
getLogicalRootPath(): string;
/**
* Gets the root folder for the current application. This Folder is private for the application and not accessible from Users/External apps.
* iOS - this folder is read-only and contains the app and all its resources.
*/
getCurrentAppPath(): string;
/**
* Reads a text from a file with a given path.
* @param path The path to the source file.

View File

@ -233,6 +233,20 @@ export class FileSystemAccess {
return this.getKnownPath(this.cachesDir);
}
public getCurrentAppPath(): string {
const currentDir = __dirname;
const tnsModulesIndex = currentDir.indexOf("/tns_modules");
// Module not hosted in ~/tns_modules when bundled. Use current dir.
let appPath = currentDir;
if (tnsModulesIndex !== -1) {
// Strip part after tns_modules to obtain app root
appPath = currentDir.substring(0, tnsModulesIndex);
}
return appPath;
}
public readText(path: string, onError?: (error: any) => any, encoding?: any) {
var actualEncoding = encoding;
if (!actualEncoding) {

View File

@ -483,17 +483,9 @@ export module knownFolders {
export var currentApp = function (): Folder {
if (!_app) {
const currentDir = __dirname;
const tnsModulesIndex = currentDir.indexOf("/tns_modules");
// Module not hosted in ~/tns_modules when bundled. Use current dir.
let appPath = currentDir;
if (tnsModulesIndex !== -1) {
// Strip part after tns_modules to obtain app root
appPath = currentDir.substring(0, tnsModulesIndex);
}
var path = getFileAccess().getCurrentAppPath();
_app = new Folder();
_app[pathProperty] = appPath;
_app[pathProperty] = path;
_app[isKnownProperty] = true;
}