Skip to content

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

Implementing directory indexing

uggrock03f89b64177a
diff --git a/data/js/ioapi.mozilla.js b/data/js/ioapi.mozilla.js
index 9e03a303e..a5843011e 100644
--- a/data/js/ioapi.mozilla.js
+++ b/data/js/ioapi.mozilla.js
@@ -145,4 +145,14 @@ IOAPI.openExtensionsDirectory = function() {
"command": "openExtensionsDirectory"
}});
document.documentElement.dispatchEvent(event);
+}
+
+IOAPI.createDirectoryIndex = function(dirPath) {
+ console.debug("Creating directory index for: "+dirPath);
+ var event = document.createEvent('CustomEvent');
+ event.initCustomEvent("addon-message", true, true, {"detail":{
+ "command": "createDirectoryIndex",
+ "path": dirPath
+ }});
+ document.documentElement.dispatchEvent(event);
}
\ No newline at end of file
diff --git a/data/js/main.js b/data/js/main.js
index ac16fa03a..60d50ed86 100644
--- a/data/js/main.js
+++ b/data/js/main.js
@@ -26,7 +26,11 @@ var initApp = function(){
require([
"js/ioapi.chrome"
]);
- }
+ } else { // TODO a more sophisticated check is required for cordova
+ require([
+ "js/ioapi.cordova"
+ ]);
+ }
// TODO refactor all libs for integration of backbone.js
require([
diff --git a/data/js/messaging.mozilla.js b/data/js/messaging.mozilla.js
index 9c4b36e03..39673c693 100644
--- a/data/js/messaging.mozilla.js
+++ b/data/js/messaging.mozilla.js
@@ -80,6 +80,14 @@ document.documentElement.addEventListener("addon-message1", function(event) {
UIAPI.updateLogger("List directory failed");
}
break;
+ case "indexDirectory":
+ if(message.success){
+ console.debug("Directory Index: "+JSON.stringify(message.content));
+ // UIAPI.updateFileBrowserData(message.content);
+ } else {
+ UIAPI.updateLogger("Indexing directory failed");
+ }
+ break;
case "getSubdirs":
if(message.success){
var dirListing = [];
diff --git a/data/manifest.json b/data/manifest.json
index 0dd0b1a04..a24d8e96c 100644
--- a/data/manifest.json
+++ b/data/manifest.json
@@ -1,6 +1,6 @@
{
"name": "TagSpaces",
- "version": "1.2.1200",
+ "version": "1.2.1209",
"manifest_version": 2,
"description": "TagSpaces Explorer",
"icons": {
@@ -13,18 +13,16 @@
"scripts": ["chrome/background.js"]
},
"options_page": "index.html",
- "app": {
- "launch": {
- "local_path": "index.html"
- }
- },
+ "browser_action": {
+ "default_icon": "icons/icon16.png"
+ },
"plugins": [
{"path": "chrome/npapi-fileio/npapi-file-io-32.dll", "public": false},
{"path": "chrome/npapi-fileio/npapi-file-io-32.so", "public": false},
{"path": "chrome/npapi-fileio/npapi-file-io-64.so", "public": false}
],
"permissions": [
- "tabs", "http://*/*", "file://*/*"
+ "tabs", "http://*/*", "file://*/*"
],
"content_security_policy": "script-src 'self' ; object-src 'self'",
"web_accessible_resources": [
diff --git a/lib/ioutils.js b/lib/ioutils.js
index dfeaca67c..1b41da177 100644
--- a/lib/ioutils.js
+++ b/lib/ioutils.js
@@ -33,24 +33,49 @@ function searchDir(dirPath, index, keewords) {
}
}
+exports.searchDirectory = function searchDirectory(dirPath, keewords, worker) {
+ console.debug("Searching directory: "+dirPath+" for: "+keewords);
+ var resultIndex = [];
+ resultIndex = searchDir(dirPath, resultIndex, keewords);
+// IOUtils.saveTextFile("/media/truecrypt1/searchresult.js", JSON.stringify(resultIndex));
+// console.debug("Index: "+JSON.stringify(resultIndex));
+ worker.postMessage({
+ "command": "indexDirectory",
+ "success": true,
+ "content": directoryIndex
+ });
+}
+
+exports.createDirectoryIndex = function createDirectoryIndex(dirPath, worker) {
+ console.debug("Creating index for directory: "+dirPath);
+ var directoryIndex = [];
+ directoryIndex = scanDirectory(dirPath, directoryIndex);
+ // IOUtils.saveTextFile("/media/truecrypt1/myoffice.js", JSON.stringify(directoryIndex), worker);
+// console.debug("Index: "+JSON.stringify(directoryIndex));
+ worker.postMessage({
+ "command": "indexDirectory",
+ "success": true,
+ "content": directoryIndex
+ });
+}
+
function scanDirectory(dirPath, index) {
try {
var dirList = filesIO.list(dirPath);
var path = "";
for (var i=0; i < dirList.length; i++) {
path = filesIO.join(dirPath,dirList[i]);
- if(filesIO.isFile(path)) {
- index.push({
- "name": dirList[i],
- "type": "file",
- "path": path
- })
- } else {
- index.push({
- "name": dirList[i],
- "type": "directory",
- "path": path
- });
+
+ var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsIFile);
+ file.initWithPath(filesIO.join(dirPath,dirList[i]));
+ index.push({
+ "name": file.leafName,
+ "type": file.isFile()?"file":"directory",
+ "size": file.fileSize,
+ "lmdt": file.lastModifiedTime
+ });
+
+ if(!file.isFile()) {
scanDirectory(path, index);
}
}
@@ -97,39 +122,12 @@ exports.loadTextFile = function loadTextFile(filePath, worker) {
}
}
-exports.searchDirectory = function searchDirectory(dirPath, keewords, worker) {
- console.debug("Searching directory: "+dirPath+" for: "+keewords);
- var resultIndex = [];
- resultIndex = searchDir(dirPath, resultIndex, keewords);
-// IOUtils.saveTextFile("/media/truecrypt1/searchresult.js", JSON.stringify(resultIndex));
-// console.debug("Index: "+JSON.stringify(resultIndex));
- worker.postMessage({
- "command": "indexDirectory",
- "success": true,
- "content": directoryIndex
- });
-}
-
-exports.createDirectoryIndex = function createDirectoryIndex(dirPath, worker) {
- console.debug("Creating index for directory: "+dirPath);
- var directoryIndex = [];
- directoryIndex = scanDirectory(dirPath, directoryIndex);
- // IOUtils.saveTextFile("/media/truecrypt1/myoffice.js", JSON.stringify(directoryIndex), worker);
-// console.debug("Index: "+JSON.stringify(directoryIndex));
- worker.postMessage({
- "command": "indexDirectory",
- "success": true,
- "content": directoryIndex
- });
-}
-
exports.listDirectory = function listDirectory(dirPath, worker) {
console.debug("Listing directory: "+dirPath);
try {
var dirList = filesIO.list(dirPath);
var anotatedDirList = [];
for (var i=0; i < dirList.length; i++) {
- var type = "directory";
var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsIFile);
file.initWithPath(filesIO.join(dirPath,dirList[i]));
anotatedDirList.push({
diff --git a/lib/main.js b/lib/main.js
index 364e81940..0e5aaab13 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -156,6 +156,9 @@ function handleMessage(msg, worker) {
case "openExtensionsDirectory":
ioutils.openExtensionsDirectory(worker);
break;
+ case "createDirectoryIndex":
+ ioutils.createDirectoryIndex(msg.detail.path,worker);
+ break;
default:
break;
}