130 lines
No EOL
3.6 KiB
JavaScript
130 lines
No EOL
3.6 KiB
JavaScript
define(['appsettings'], function (appsettings) {
|
|
'use strict';
|
|
|
|
var PathSeparator = '\\';
|
|
|
|
function getValidFileName(path) {
|
|
|
|
return path;
|
|
}
|
|
|
|
function getMetadataPath() {
|
|
return Windows.Storage.ApplicationData.current.localFolder.path;
|
|
}
|
|
|
|
function getFullMetadataPath(pathArray) {
|
|
|
|
var localPath = getMetadataPath();
|
|
|
|
var clone = pathArray.slice(0);
|
|
clone.splice(0, 0, localPath);
|
|
return clone.join(PathSeparator);
|
|
}
|
|
|
|
function getLocalPath() {
|
|
|
|
var localPath = appsettings.syncPath();
|
|
|
|
if (!localPath || localPath === '') {
|
|
localPath = Windows.Storage.ApplicationData.current.localFolder.path;
|
|
}
|
|
|
|
return localPath;
|
|
|
|
}
|
|
|
|
function getFullLocalPath(pathArray) {
|
|
|
|
var localPath = getLocalPath();
|
|
|
|
var clone = pathArray.slice(0);
|
|
clone.splice(0, 0, localPath);
|
|
return clone.join(PathSeparator);
|
|
}
|
|
|
|
function getParentPath(path) {
|
|
var pathArray = path.split(PathSeparator);
|
|
|
|
if (pathArray.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
pathArray = pathArray.slice(0, pathArray.length - 1);
|
|
return pathArray.join(PathSeparator);
|
|
}
|
|
|
|
function combinePath(path1, path2) {
|
|
|
|
if (path1.endsWith(PathSeparator)) {
|
|
path1 = path1.substr(0, path1.length - 1);
|
|
}
|
|
|
|
if (path2.startsWith(PathSeparator)) {
|
|
path2 = path2.substr(1);
|
|
}
|
|
|
|
return path1 + PathSeparator + path2;
|
|
}
|
|
|
|
function deleteFile(path) {
|
|
return Windows.Storage.StorageFile.getFileFromPathAsync(path).then(function (storageFile) {
|
|
return storageFile.deleteAsync(Windows.Storage.StorageDeleteOption.permanentDelete).then(function () {
|
|
return Promise.resolve(true);
|
|
}, function () {
|
|
return Promise.resolve(false);
|
|
});
|
|
}, function () {
|
|
return Promise.resolve(false);
|
|
});
|
|
}
|
|
|
|
function deleteDirectory(path) {
|
|
return Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(function (storageFolder) {
|
|
return storageFolder.DeleteAsync(Windows.Storage.StorageDeleteOption.permanentDelete).then(function () {
|
|
return Promise.resolve(true);
|
|
}, function () {
|
|
return Promise.resolve(false);
|
|
});
|
|
}, function () {
|
|
return Promise.resolve(false);
|
|
});
|
|
}
|
|
|
|
function fileExists(path) {
|
|
|
|
return Windows.Storage.StorageFile.getFileFromPathAsync(path).then(function (storageFile) {
|
|
|
|
return Promise.resolve(storageFile !== null);
|
|
}, function (err) {
|
|
return Promise.resolve(false);
|
|
});
|
|
}
|
|
|
|
function getItemFileSize(path) {
|
|
return Windows.Storage.StorageFile.getFileFromPathAsync(path).then(function (storageFile) {
|
|
return storageFile.getBasicPropertiesAsync().then(function (basicProperties) {
|
|
return Promise.resolve(basicProperties.size);
|
|
});
|
|
});
|
|
}
|
|
|
|
function getImageUrl(pathArray) {
|
|
var path = NativeFileRepository.getImageUrl(pathArray);
|
|
return path;
|
|
}
|
|
|
|
return {
|
|
getValidFileName: getValidFileName,
|
|
getLocalPath: getLocalPath,
|
|
getFullLocalPath: getFullLocalPath,
|
|
getMetadataPath: getMetadataPath,
|
|
getFullMetadataPath: getFullMetadataPath,
|
|
getParentPath: getParentPath,
|
|
combinePath: combinePath,
|
|
deleteFile: deleteFile,
|
|
deleteDirectory: deleteDirectory,
|
|
fileExists: fileExists,
|
|
getItemFileSize: getItemFileSize,
|
|
getImageUrl: getImageUrl
|
|
};
|
|
}); |