Skip to content

Commit

Permalink
Merge pull request #2028 from NativeScript/jasssonpet/current-app-path
Browse files Browse the repository at this point in the history
Make FileSystem.currentAppPath platform specific
  • Loading branch information
jasssonpet committed Apr 27, 2016
2 parents e655670 + b356142 commit 264fe17
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions file-system/file-system-access.android.ts
Expand Up @@ -192,6 +192,10 @@ export class FileSystemAccess {
var dir = utils.ad.getApplicationContext().getCacheDir();
return dir.getAbsolutePath();
}

public getCurrentAppPath(): string {
return this.getLogicalRootPath() + "/app";
}

public read(path: string, onError?: (error: any) => any) {
try {
Expand Down
6 changes: 6 additions & 0 deletions file-system/file-system-access.d.ts
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions file-system/file-system-access.ios.ts
Expand Up @@ -232,6 +232,20 @@ export class FileSystemAccess {
public getTempFolderPath(): string {
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;
Expand Down
12 changes: 2 additions & 10 deletions file-system/file-system.ts
Expand Up @@ -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;
}

Expand Down

0 comments on commit 264fe17

Please sign in to comment.