- Please select the file titles.idx :
-
- Please select the files wikipedia_*.dat from the same dump :
-
- Please select the file math.idx from the same dump:
-
- Please select the file math.dat from the same dump:
-
- Please select the file metadata.txt from the same dump:
-
+ Please select all the files inside the archive (wikipedia_*.dat, metadata.txt etc)
+
Scanning your sdcard for archives... Please wait
diff --git a/js/app.js b/js/app.js
index 31d62fae..790c1239 100644
--- a/js/app.js
+++ b/js/app.js
@@ -99,10 +99,11 @@ define(function(require) {
function setLocalArchiveFromArchiveList() {
var archiveDirectory = $('#archiveList').val();
localArchive = new evopedia.LocalArchive();
- localArchive.readTitleFileFromStorage(storage, archiveDirectory);
+ localArchive.readTitleFilesFromStorage(storage, archiveDirectory);
localArchive.readDataFilesFromStorage(storage, archiveDirectory, 0);
localArchive.readMathFilesFromStorage(storage, archiveDirectory);
localArchive.readMetadataFileFromStorage(storage, archiveDirectory);
+ localArchive.readCoordinateFilesFromStorage(storage, archiveDirectory, 0);
}
/**
@@ -110,28 +111,15 @@ define(function(require) {
*/
function displayFileSelect() {
$('#openLocalFiles').show();
- $('#dataFiles').on('change', setLocalArchiveFromFileSelect);
- $('#titleFile').on('change', setLocalArchiveFromFileSelect);
- $('#mathIndexFile').on('change', setLocalArchiveFromFileSelect);
- $('#mathDataFile').on('change', setLocalArchiveFromFileSelect);
- $('#metadataFile').on('change', setLocalArchiveFromFileSelect);
+ $('#archiveFiles').on('change', setLocalArchiveFromFileSelect);
}
/**
* Sets the localArchive from the File selects populated by user
*/
function setLocalArchiveFromFileSelect() {
- var dataFiles = document.getElementById('dataFiles').files;
- var titleFile = document.getElementById('titleFile').files[0];
- var mathIndexFile = document.getElementById('mathIndexFile').files[0];
- var mathDataFile = document.getElementById('mathDataFile').files[0];
- var metadataFile = document.getElementById('metadataFile').files[0];
localArchive = new evopedia.LocalArchive();
- localArchive.dataFiles = dataFiles;
- localArchive.titleFile = titleFile;
- localArchive.mathIndexFile = mathIndexFile;
- localArchive.mathDataFile = mathDataFile;
- localArchive.readMetadataFile(metadataFile);
+ localArchive.initializeFromArchiveFiles(document.getElementById('archiveFiles').files);
}
/**
diff --git a/js/lib/evopedia.js b/js/lib/evopedia.js
index b9f6dc93..2056c243 100644
--- a/js/lib/evopedia.js
+++ b/js/lib/evopedia.js
@@ -44,7 +44,7 @@ define(function(require) {
var bits, h1, h2, h3, h4, i = 0;
var enc = "";
- for (i = 0; i < byteArray.length; ) {
+ for (var i = 0; i < byteArray.length; ) {
bits = byteArray[i++] << 16;
bits |= byteArray[i++] << 8;
bits |= byteArray[i++];
@@ -65,26 +65,27 @@ define(function(require) {
/**
* LocalArchive class : defines a wikipedia dump on the filesystem
- * It's still minimal for now. TODO : complete implementation to handle maths and coordinates
*/
function LocalArchive() {
this.dataFiles = new Array();
+ this.coordinateFiles = new Array();
this.titleFile = null;
this.mathIndexFile = null;
this.mathDataFile = null;
this.date = null;
this.language = null;
+ this.titleSearchFile = null;
};
/**
- * Read the title File in the given directory, and assign it to the
+ * Read the title Files in the given directory, and assign them to the
* current LocalArchive
*
* @param storage
* @param directory
*/
- LocalArchive.prototype.readTitleFileFromStorage = function(storage, directory) {
+ LocalArchive.prototype.readTitleFilesFromStorage = function(storage, directory) {
var currentLocalArchiveInstance = this;
var filerequest = storage.get(directory + '/titles.idx');
filerequest.onsuccess = function() {
@@ -93,6 +94,13 @@ define(function(require) {
filerequest.onerror = function(event) {
alert("error reading title file in directory " + directory + " : " + event.target.error.name);
};
+ var filerequestSearch = storage.get(directory + '/titles_search.idx');
+ filerequestSearch.onsuccess = function() {
+ currentLocalArchiveInstance.titleSearchFile = filerequest.result;
+ };
+ filerequest.onerror = function(event) {
+ // Do nothing : this file is not mandatory in an archive
+ };
};
/**
@@ -128,6 +136,39 @@ define(function(require) {
};
};
+ /**
+ * Read the coordinate Files in the given directory (starting at given index), and
+ * assign them to the current LocalArchive
+ *
+ * @param storage
+ * @param directory
+ * @param index
+ */
+ LocalArchive.prototype.readCoordinateFilesFromStorage = function(storage, directory, index) {
+ var currentLocalArchiveInstance = this;
+
+ var prefixedFileNumber = "";
+ if (index < 10) {
+ prefixedFileNumber = "0" + index;
+ } else {
+ prefixedFileNumber = index;
+ }
+ var filerequest = storage.get(directory + '/coordinates_' + prefixedFileNumber
+ + '.idx');
+ filerequest.onsuccess = function() {
+ currentLocalArchiveInstance.coordinateFiles[index] = filerequest.result;
+ currentLocalArchiveInstance.readCoordinateFilesFromStorage(storage, directory,
+ index + 1);
+ };
+ filerequest.onerror = function(event) {
+ // TODO there must be a better to way to detect a FileNotFound
+ if (event.target.error.name != "NotFoundError") {
+ alert("error reading data file " + index + " in directory "
+ + directory + " : " + event.target.error.name);
+ }
+ };
+ };
+
/**
* Read the metadata.txt file in the given directory, and store its content
* in the current instance
@@ -164,6 +205,53 @@ define(function(require) {
};
reader.readAsText(file);
};
+
+ /**
+ * Initialize the localArchive from given archive files
+ * @param {type} archiveFiles
+ * @returns {undefined}
+ */
+ LocalArchive.prototype.initializeFromArchiveFiles = function(archiveFiles) {
+ var dataFileRegex = /^wikipedia_(\d\d).dat$/;
+ var coordinateFileRegex = /^coordinates_(\d\d).idx$/;
+ this.dataFiles = new Array();
+ this.coordinateFiles = new Array();
+ for (var i=0; i 0) {
+ var intFileNr = 1 * coordinateFileNr[1];
+ this.coordinateFiles[intFileNr] = file;
+ }
+ else {
+ var dataFileNr = dataFileRegex.exec(file.name);
+ if (dataFileNr && dataFileNr.length > 0) {
+ var intFileNr = 1 * dataFileNr[1];
+ this.dataFiles[intFileNr] = file;
+ }
+ }
+ }
+ }
+ }
+
+ };
/**
* Read the math files (math.idx and math.dat) in the given directory, and assign it to the
diff --git a/tests/tests.html b/tests/tests.html
index 74409797..617659fe 100644
--- a/tests/tests.html
+++ b/tests/tests.html
@@ -18,17 +18,8 @@
- Please select the file titles.idx from wikipedia_small_2010-08-14 (included with source code) :
-
- Please select the file wikipedia_00.dat from the same dump :
-
- Please select the file math.idx from the same dump:
-
- Please select the file math.dat from the same dump:
-
- Please select the file metadata.txt from the same dump:
-
-
+ Please select all the files inside the archive wikipedia_small_2010-08-14 (included with source code) : wikipedia_*.dat, metadata.txt etc
+
diff --git a/tests/tests.js b/tests/tests.js
index e2fb1622..c01827b1 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -17,25 +17,15 @@ define(function(require) {
equal("test", "test", "QUnit is properly configured");
});
- test("check title and data files are set", function() {
- var titleFile = document.getElementById('titleFile').files[0];
- var dataFiles = document.getElementById('dataFiles').files;
- ok(titleFile && titleFile.size > 0, "Title file set and not empty");
- ok(dataFiles && dataFiles[0] && dataFiles[0].size > 0, "First data file set and not empty");
- var mathIndexFile = document.getElementById('mathIndexFile').files[0];
- var mathDataFile = document.getElementById('mathDataFile').files[0];
- ok(mathIndexFile && mathIndexFile.size > 0, "Math index file set and not empty");
- ok(mathDataFile && mathDataFile.size > 0, "Math data file set and not empty");
+ test("check archive files are selected", function() {
+ var archiveFiles = document.getElementById('archiveFiles').files;
+ ok(archiveFiles && archiveFiles[0] && archiveFiles[0].size > 0, "First archive file set and not empty");
+ ok(archiveFiles.length >= 5, "At least 5 files are selected");
});
// Create a localArchive from selected files, in order to run the following tests
var localArchive = new evopedia.LocalArchive();
- localArchive.titleFile = document.getElementById('titleFile').files[0];
- localArchive.dataFiles = document.getElementById('dataFiles').files;
- localArchive.mathIndexFile = document.getElementById('mathIndexFile').files[0];
- localArchive.mathDataFile = document.getElementById('mathDataFile').files[0];
- var metadataFile = document.getElementById('metadataFile').files[0];
- localArchive.readMetadataFile(metadataFile);
+ localArchive.initializeFromArchiveFiles(document.getElementById('archiveFiles').files);
module("evopedia");
asyncTest("check getTitlesStartingAtOffset 0", function() {