mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Make FileSystem.currentAppPath platform specific
This commit is contained in:
@ -192,6 +192,10 @@ export class FileSystemAccess {
|
|||||||
var dir = utils.ad.getApplicationContext().getCacheDir();
|
var dir = utils.ad.getApplicationContext().getCacheDir();
|
||||||
return dir.getAbsolutePath();
|
return dir.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getCurrentAppPath(): string {
|
||||||
|
return this.getLogicalRootPath() + "/app";
|
||||||
|
}
|
||||||
|
|
||||||
public read(path: string, onError?: (error: any) => any) {
|
public read(path: string, onError?: (error: any) => any) {
|
||||||
try {
|
try {
|
||||||
|
6
file-system/file-system-access.d.ts
vendored
6
file-system/file-system-access.d.ts
vendored
@ -104,6 +104,12 @@
|
|||||||
*/
|
*/
|
||||||
getLogicalRootPath(): string;
|
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.
|
* Reads a text from a file with a given path.
|
||||||
* @param path The path to the source file.
|
* @param path The path to the source file.
|
||||||
|
@ -232,6 +232,20 @@ export class FileSystemAccess {
|
|||||||
public getTempFolderPath(): string {
|
public getTempFolderPath(): string {
|
||||||
return this.getKnownPath(this.cachesDir);
|
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) {
|
public readText(path: string, onError?: (error: any) => any, encoding?: any) {
|
||||||
var actualEncoding = encoding;
|
var actualEncoding = encoding;
|
||||||
|
@ -483,17 +483,9 @@ export module knownFolders {
|
|||||||
|
|
||||||
export var currentApp = function (): Folder {
|
export var currentApp = function (): Folder {
|
||||||
if (!_app) {
|
if (!_app) {
|
||||||
const currentDir = __dirname;
|
var path = getFileAccess().getCurrentAppPath();
|
||||||
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);
|
|
||||||
}
|
|
||||||
_app = new Folder();
|
_app = new Folder();
|
||||||
_app[pathProperty] = appPath;
|
_app[pathProperty] = path;
|
||||||
_app[isKnownProperty] = true;
|
_app[isKnownProperty] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user