Skip to content

TagSpaces is an offline, open source, document manager with tagging support

addinf file properties method to the IO api

Ilian063b8ef7d5f6
diff --git a/build.number b/build.number
index 64f6086b9..7bb164825 100644
--- a/build.number
+++ b/build.number
@@ -1,4 +1,4 @@
#Build Number for ANT. Do not edit!
-#Fri Jan 03 12:15:36 CET 2014
-build.number=1756
+#Fri Jan 03 22:35:56 CET 2014
+build.number=1763
3=
diff --git a/data/js/fileopener.js b/data/js/fileopener.js
index 2411e8d2f..934387a98 100644
--- a/data/js/fileopener.js
+++ b/data/js/fileopener.js
@@ -193,19 +193,19 @@ define(function(require, exports, module) {
$( "#viewer" ).empty();
TSCORE.IO.checkAccessFileURLAllowed();
+
+ TSCORE.IO.getFileProperties(filePath.replace("\\\\","\\"));
if(!viewerExt) {
$( "#viewer" ).html("<div class='alert alert-info'><strong>Info</strong> File type not supported for viewing.</div>");
} else if (viewerExt == "viewerBrowser") {
- var filePathURI = undefined;
-
- //TODO minimize platform specific calls
- if(isCordova) {
+ var filePathURI = undefined;
+ if(isCordova) {
filePathURI = filePath;
- } else {
+ } else {
filePathURI = "file:///"+filePath;
- }
-
+ }
+
$('#viewer').append($('<iframe>', {
id: "iframeViewer",
src: filePathURI
diff --git a/data/js/ioapi.chrome.js b/data/js/ioapi.chrome.js
index 655220e00..dd8e6beaf 100644
--- a/data/js/ioapi.chrome.js
+++ b/data/js/ioapi.chrome.js
@@ -249,7 +249,7 @@ IO-API
TSCORE.showLoadingAnimation();
try {
nativeIO.createDirectory(dirPath);
- TSPOSTIO.createDirectory();
+ TSPOSTIO.createDirectory(dirPath);
} catch(ex) {
console.error("Deleting file failed "+ex);
}
@@ -348,6 +348,21 @@ IO-API
console.log("Open extensions directory functionality not implemented in chrome yet!");
TSCORE.showAlertDialog("Open extensions directory functionality not implemented on chrome yet!");
};
+
+ var getFileProperties = function(filePath) {
+ var fileProperties = {};
+ if(!nativeIO.isDirectory(filePath)) {
+ fileProperties.path = filePath;
+ fileProperties.size = nativeIO.getFileSize(filePath);
+ fileProperties.lmdt = 0;
+ if(isWin) {
+ fileProperties.lmdt = new Date(nativeIO.getFileLastDateModified(filePath)*1000);
+ }
+ TSPOSTIO.getFileProperties(fileProperties);
+ } else {
+ console.warn("Error getting file properties. "+filePath+" is directory");
+ }
+ };
exports.createDirectory = createDirectory;
exports.renameFile = renameFile;
@@ -363,4 +378,6 @@ IO-API
exports.openExtensionsDirectory = openExtensionsDirectory;
exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;
exports.checkNewVersion = checkNewVersion;
+ exports.getFileProperties = getFileProperties;
+
});
diff --git a/data/js/ioapi.cordova.js b/data/js/ioapi.cordova.js
index 270a82e6a..2b89706dd 100644
--- a/data/js/ioapi.cordova.js
+++ b/data/js/ioapi.cordova.js
@@ -316,7 +316,7 @@ define(function (require, exports, module) {
fsRoot.getDirectory(dirPath, {create: true, exclusive: false},
function (dirEntry) {
- TSPOSTIO.createDirectory();
+ TSPOSTIO.createDirectory(dirPath);
},
function (error) {
console.log("Creating directory failed: "+dirPath+" failed with error code: " + error.code);
@@ -387,6 +387,34 @@ define(function (require, exports, module) {
TSCORE.showAlertDialog("Open extensions directory functionality not supported on Android!");
};
+ var getFileProperties = function(filePath) {
+ filePath = normalizePath(filePath);
+ var fileProperties = {};
+ fsRoot.getFile(filePath, {create: false, exclusive: false},
+ function(entry) {
+ if(entry.isFile) {
+ entry.file(
+ function(file) {
+ fileProperties.path = entry.fullPath;
+ fileProperties.size = file.size;
+ fileProperties.lmdt = file.lastModifiedDate;
+ fileProperties.mimetype = file.type;
+ TSPOSTIO.getFileProperties(fileProperties);
+ },
+ function() {
+ console.warn("Error retrieving file properties of "+filePath);
+ }
+ );
+ } else {
+ console.warn("Error getting file properties. "+filePath+" is directory");
+ }
+ },
+ function() {
+ console.log("error getting file");
+ }
+ );
+ };
+
exports.createDirectory = createDirectory;
exports.renameFile = renameFile;
exports.loadTextFile = loadTextFile;
@@ -401,5 +429,7 @@ define(function (require, exports, module) {
exports.selectFile = selectFile;
exports.openExtensionsDirectory = openExtensionsDirectory;
exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;
- exports.checkNewVersion = checkNewVersion;
+ exports.checkNewVersion = checkNewVersion;
+ exports.getFileProperties = getFileProperties;
+
});
\ No newline at end of file
diff --git a/data/js/ioapi.dropbox.js b/data/js/ioapi.dropbox.js
index f0ec03818..c9a20f484 100644
--- a/data/js/ioapi.dropbox.js
+++ b/data/js/ioapi.dropbox.js
@@ -178,7 +178,7 @@ define(function (require, exports, module) {
console.log("Error creating directory: "+err);
} else {
console.log("Directory created: "+stat.path);
- TSPOSTIO.createDirectory();
+ TSPOSTIO.createDirectory(dirPath);
}
});
};
@@ -218,6 +218,10 @@ define(function (require, exports, module) {
TSCORE.showAlertDialog("Open extensions directory functionality not supported in the Dropbox mode!");
};
+ var getFileProperties = function(filePath) {
+ console.log("getFileProperties not implemented for dropbox");
+ };
+
exports.init = init;
exports.createDirectory = createDirectory;
@@ -233,5 +237,7 @@ define(function (require, exports, module) {
exports.selectFile = selectFile;
exports.openExtensionsDirectory = openExtensionsDirectory;
exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;
- exports.checkNewVersion = checkNewVersion;
+ exports.checkNewVersion = checkNewVersion;
+ exports.getFileProperties = getFileProperties;
+
});
\ No newline at end of file
diff --git a/data/js/ioapi.mozilla.js b/data/js/ioapi.mozilla.js
index a6a33ddc7..ce5eb2b37 100644
--- a/data/js/ioapi.mozilla.js
+++ b/data/js/ioapi.mozilla.js
@@ -22,7 +22,7 @@ define(function(require, exports, module) {
console.log("Loading settings...: "+JSON.stringify(message.content));
TSCORE.Config.updateSettingMozillaPreferences(message.content);
- TSCORE.initConnections();
+ TSCORE.initLocations();
TSCORE.generateTagGroups();
} catch (ex) {
@@ -55,7 +55,7 @@ define(function(require, exports, module) {
break;
case "createDirectory":
if(message.success){
- TSPOSTIO.createDirectory();
+ TSPOSTIO.createDirectory(message.content);
} else {
TSCORE.updateLogger("Create dir failed");
}
@@ -107,7 +107,13 @@ define(function(require, exports, module) {
if(message.success){
TSPOSTIO.checkNewVersion(message.content);
} else {
- TSCORE.updateLogger("Create dir failed");
+ TSCORE.updateLogger("Checking for new version failed.");
+ }
+ case "getFileProperties":
+ if(message.success){
+ TSPOSTIO.getFileProperties(message.content);
+ } else {
+ TSCORE.updateLogger("Getting file properties failed.");
}
break;
default:
@@ -277,6 +283,17 @@ define(function(require, exports, module) {
document.documentElement.dispatchEvent(event);
};
+ var getFileProperties = function(filePath) {
+ console.log("Getting file properties...");
+ TSCORE.showLoadingAnimation();
+ var event = document.createEvent('CustomEvent');
+ event.initCustomEvent("addon-message", true, true, {"detail":{
+ "command": "getFileProperties",
+ "path": filePath
+ }});
+ document.documentElement.dispatchEvent(event);
+ };
+
exports.saveSettings = saveSettings;
exports.loadSettings = loadSettings;
@@ -293,6 +310,7 @@ define(function(require, exports, module) {
exports.selectFile = selectFile;
exports.openExtensionsDirectory = openExtensionsDirectory;
exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;
- exports.checkNewVersion = checkNewVersion;
+ exports.checkNewVersion = checkNewVersion;
+ exports.getFileProperties = getFileProperties;
});
diff --git a/data/js/ioapi.node.js b/data/js/ioapi.node.js
index fd28ba4d7..64aaf3cae 100644
--- a/data/js/ioapi.node.js
+++ b/data/js/ioapi.node.js
@@ -11,22 +11,6 @@ define(function(require, exports, module) {
var TSPOSTIO = require("tspostioapi");
-/* stats for file:
- dev: 2114,
- ino: 48064969,
- mode: 33188,
- nlink: 1,
- uid: 85,
- gid: 100,
- rdev: 0,
- size: 527,
- blksize: 4096,
- blocks: 8,
- atime: Mon, 10 Oct 2011 23:24:11 GMT,
- mtime: Mon, 10 Oct 2011 23:24:11 GMT,
- ctime: Mon, 10 Oct 2011 23:24:11 GMT
-*/
-
function scanDirectory(dirPath, index) {
try {
var dirList = fs.readdirSync(dirPath);
@@ -93,26 +77,26 @@ define(function(require, exports, module) {
console.error("Scanning directory "+dirPath+" failed "+ex);
}
}
-
+/*
var getFileSize = function(filePath) {
console.log("Get filesize of: "+filePath);
var stats = fs.statSync(filePath);
return stats.size;
- //TSPOSTIO.createDirectoryIndex(directoryIndex);
+ //TSPOSTIO.
};
var getLMDT = function(filePath) {
console.log("Get last modified date time of: "+filePath);
var stats = fs.statSync(filePath);
return stats.mtime;
- //TSPOSTIO.createDirectoryIndex(directoryIndex);
+ //TSPOSTIO.
};
var directoryExist = function(dirPath) {
console.log("Checks if a directory exist: "+dirPath);
- //TSPOSTIO.createDirectoryIndex(directoryIndex);
- };
+ //TSPOSTIO.
+ }; */
var createDirectoryIndex = function(dirPath) {
console.log("Creating index for directory: "+dirPath);
@@ -142,7 +126,7 @@ define(function(require, exports, module) {
console.log("Creating directory "+dirPath+" failed "+error);
return;
}
- TSPOSTIO.createDirectory();
+ TSPOSTIO.createDirectory(dirPath);
});
};
@@ -300,6 +284,34 @@ define(function(require, exports, module) {
console.log("Open extensions directory functionality not implemented on chrome yet!");
TSCORE.showAlertDialog("Open extensions directory functionality not implemented on chrome yet!");
};
+
+/* stats for file:
+ dev: 2114,
+ ino: 48064969,
+ mode: 33188,
+ nlink: 1,
+ uid: 85,
+ gid: 100,
+ rdev: 0,
+ size: 527,
+ blksize: 4096,
+ blocks: 8,
+ atime: Mon, 10 Oct 2011 23:24:11 GMT,
+ mtime: Mon, 10 Oct 2011 23:24:11 GMT,
+ ctime: Mon, 10 Oct 2011 23:24:11 GMT
+*/
+ var getFileProperties = function(filePath) {
+ var fileProperties = {};
+ var stats = fs.statSync(filePath);
+ if (stats.isFile()) {
+ fileProperties.path = filePath;
+ fileProperties.size = stats.size;
+ fileProperties.lmdt = stats.mtime;
+ TSPOSTIO.getFileProperties(fileProperties);
+ } else {
+ console.warn("Error getting file properties. "+filePath+" is directory");
+ }
+ };
exports.createDirectory = createDirectory;
exports.renameFile = renameFile;
@@ -316,5 +328,6 @@ define(function(require, exports, module) {
exports.openExtensionsDirectory = openExtensionsDirectory;
exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;
exports.checkNewVersion = checkNewVersion;
+ exports.getFileProperties = getFileProperties;
});
diff --git a/data/js/postioapi.js b/data/js/postioapi.js
index ea66cb323..d2db0c630 100644
--- a/data/js/postioapi.js
+++ b/data/js/postioapi.js
@@ -20,8 +20,9 @@ define(function(require, exports, module) {
//TSCORE.hideLoadingAnimation();
};
- exports.createDirectory = function() {
- //TODO refresh the directory area
+ exports.createDirectory = function(dirPath) {
+ //TODO evtl navigate to parent dir
+ TSCORE.navigateToDirectory(dirPath);
TSCORE.hideLoadingAnimation();
};
@@ -107,4 +108,9 @@ define(function(require, exports, module) {
exports.openExtensionsDirectory = function() {
};
+
+ exports.getFileProperties = function(fileProperties) {
+ console.log("File properties: "+JSON.stringify(fileProperties));
+ };
+
});
\ No newline at end of file
diff --git a/lib/ioutils.js b/lib/ioutils.js
index 37cd922ee..0f252c1de 100644
--- a/lib/ioutils.js
+++ b/lib/ioutils.js
@@ -87,19 +87,6 @@ exports.createDirectoryTree = function createDirectoryTree(dirPath, worker) {
});
};
-/*
- "leafName":"2013",
- "permissions":438,
- "permissionsOfLink":438,
- "lastModifiedTime":1350309208000,
- "lastModifiedTimeOfLink":1350309208000,
- "fileSize":0,
- "fileSizeOfLink":0,
- "target":"Z:\\Chronique\\2013",
- "path":"Z:\\Chronique\\2013",
- "parent":{}
-*/
-
function directoryTree(dirPath) {
try {
var tree = {};
@@ -203,12 +190,13 @@ exports.listDirectory = function listDirectory(dirPath, worker) {
}
};
-exports.createDirectory = function createDirectory(filePath, worker) {
- console.log("Creating directory: "+filePath);
+exports.createDirectory = function createDirectory(dirPath, worker) {
+ console.log("Creating directory: "+dirPath);
try {
- filesIO.mkpath(filePath);
+ filesIO.mkpath(dirPath);
worker.postMessage({
"command": "createDirectory",
+ "content": dirPath,
"success": true
});
console.log("Creating successful!");
@@ -464,3 +452,38 @@ exports.openExtensionsDirectory = function openExtensionsDirectory(worker) {
console.error("Opening extensions directory failed "+ex);
} */
};
+
+/*
+ "leafName":"2013",
+ "permissions":438,
+ "permissionsOfLink":438,
+ "lastModifiedTime":1350309208000,
+ "lastModifiedTimeOfLink":1350309208000,
+ "fileSize":0,
+ "fileSizeOfLink":0,
+ "target":"Z:\\Chronique\\2013",
+ "path":"Z:\\Chronique\\2013",
+ "parent":{}
+*/
+
+exports.getFileProperties = function(filePath, worker) {
+ var fileProperties = {};
+ try {
+ var targetFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+ targetFile.initWithPath(filesIO.join(filePath,""));
+ if(targetFile.isFile()) {
+ fileProperties.path = filePath;
+ fileProperties.size = targetFile.fileSize;
+ fileProperties.lmdt = targetFile.lastModifiedTime;
+ worker.postMessage({
+ "command": "getFileProperties",
+ "success": true,
+ "content": fileProperties
+ });
+ } else {
+ console.warn("Error getting file properties. "+filePath+" is directory");
+ }
+ } catch(ex) {
+ console.error("Error getting properties for file "+filePath+" - "+ex);
+ }
+};
\ No newline at end of file
diff --git a/lib/main.js b/lib/main.js
index 97bb576ce..f965d31da 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -218,6 +218,9 @@ function handleMessage(msg, worker) {
break;
case "createDirectoryTree":
ioutils.createDirectoryTree(msg.detail.path,worker);
+ break;
+ case "getFileProperties":
+ ioutils.getFileProperties(msg.detail.path,worker);
break;
default:
break;