diff --git a/www/index.html b/www/index.html
index 19fefe12..93b379cd 100644
--- a/www/index.html
+++ b/www/index.html
@@ -55,8 +55,8 @@ License:
- On desktops, it works on recent Firefox and Chrome, and maybe on other browsers
- - On the Firefos OS simulator, you have (for now) to put the French dump files in a "fake-sdcard/evopedia" folder of your firefox profile (ex : ~/.mozilla/firefox/xxxx.default/extensions/r2d2b2g@mozilla.org/profile/fake-sdcard). It looks for evopedia/wikipedia_fr_2013-02-16/titles.idx in it. You also need to install the application from the dashboard of the simulator instead of accessing via the browser (due to security restrictions in Firefox OS : only certified webapps can access the sdcard)
- - On a real Firefox OS device, you also have (for now) to put the French dump files in an "evopedia" directory at the root of your sdcard, so that it finds a file /evopedia/wikipedia_fr_2013-02-16/titles.idx on it
+ - On the Firefos OS simulator, you have to put the archive files in a "fake-sdcard/evopedia" folder of your firefox profile (ex : ~/.mozilla/firefox/xxxx.default/extensions/r2d2b2g@mozilla.org/profile/fake-sdcard). It looks for evopedia/*/titles.idx in it. You also need to install the application from the dashboard of the simulator instead of accessing via the browser (due to security restrictions in Firefox OS : only certified webapps can access the sdcard)
+ - On a real Firefox OS device, you also have to put the archive files in an "evopedia" directory at the root of your sdcard, so that it finds a file /evopedia/*/titles.idx on it
It's only a proof of concept so far : there are many many ways this could be enhanced (suggestions and patches are welcome : the source code is on github). In particular :
diff --git a/www/js/app.js b/www/js/app.js
index 8d383ebb..e5848f44 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -49,13 +49,12 @@ define(function(require) {
}
if (storage != null) {
- //var directory = 'evopedia/wikipedia_small_2010-08-14';
- var directory = 'evopedia/wikipedia_fr_2013-02-16';
- localArchive = new evopedia.LocalArchive();
- localArchive.readTitleFile(storage, directory);
- localArchive.readDataFiles(storage, directory, 0);
+ // If DeviceStorage is available, we look for archives in it
+ var directory = 'evopedia';
+ evopedia.LocalArchive.scanForArchives(storage,directory,selectFirstArchive);
}
else {
+ // If DeviceStorage is not available, we display the file select components
displayFileSelect();
setLocalArchiveFromFileSelect();
}
@@ -65,6 +64,15 @@ define(function(require) {
var titleName = event.state.titleName;
goToArticle(titleName);
};
+
+ /**
+ * Selects the first archive found on device storage
+ */
+ function selectFirstArchive(archiveDirectories) {
+ localArchive = new evopedia.LocalArchive();
+ localArchive.readTitleFile(storage, archiveDirectories[0]);
+ localArchive.readDataFiles(storage, archiveDirectories[0], 0);
+ }
/**
* Displays the zone to select files from the dump
diff --git a/www/js/lib/evopedia.js b/www/js/lib/evopedia.js
index c59a1793..4b133cfb 100644
--- a/www/js/lib/evopedia.js
+++ b/www/js/lib/evopedia.js
@@ -419,6 +419,47 @@ define(function(require) {
reader.readAsArrayBuffer(blob);
};
+ /**
+ * Scans the DeviceStorage for archives
+ *
+ * @param storage DeviceStorage instance
+ * @param rootDirectory Directory from which to start scanning
+ * @param callbackFunction Function to call with the list of directories where archives are found
+ */
+ LocalArchive.scanForArchives = function(storage, rootDirectory, callbackFunction) {
+ var directories = [];
+ var cursor = storage.enumerate();
+ cursor.onerror = function() {
+ alert("Error scanning directory " + rootDirectory + " : " + cursor.error);
+ }
+ cursor.onsuccess = function() {
+ if (cursor.result) {
+ var file = cursor.result;
+ var fileName = file.name;
+
+ // We look for files "titles.idx"
+ if (!endsWith(fileName,"titles.idx")) {
+ cursor.continue();
+ return;
+ }
+
+ // We want to return the directory where titles.idx is stored
+ var directory = fileName.substring(0, fileName.lastIndexOf('/'));
+ console.log(directory);
+ directories.push(directory);
+ cursor.continue();
+ }
+ else {
+ callbackFunction(directories);
+ }
+ };
+ };
+
+ function endsWith(str, suffix) {
+ return str.indexOf(suffix, str.length - suffix.length) !== -1;
+ }
+
+
/**
* Title class : defines the title of an article and some methods to manipulate it