2013-06-16 10:47:35 +00:00
|
|
|
define([
|
2013-06-19 20:33:46 +00:00
|
|
|
"underscore",
|
2013-06-16 10:47:35 +00:00
|
|
|
"utils",
|
|
|
|
"classes/FileDescriptor",
|
|
|
|
"storage",
|
2014-04-10 23:22:30 +00:00
|
|
|
], function(_, utils, FileDescriptor, storage) {
|
2013-06-16 10:47:35 +00:00
|
|
|
var fileSystem = {};
|
|
|
|
|
2013-06-19 20:33:46 +00:00
|
|
|
// Retrieve file descriptors from localStorage
|
2014-04-10 23:22:30 +00:00
|
|
|
utils.retrieveIndexArray("file.list").forEach(function(fileIndex) {
|
2013-06-19 20:33:46 +00:00
|
|
|
fileSystem[fileIndex] = new FileDescriptor(fileIndex);
|
2013-06-16 10:47:35 +00:00
|
|
|
});
|
|
|
|
|
2014-04-10 23:22:30 +00:00
|
|
|
// Clean fields from deleted files in local storage
|
|
|
|
Object.keys(storage).forEach(function(key) {
|
|
|
|
var match = key.match(/(file\.\S+?)\.\S+/);
|
|
|
|
if(match && !fileSystem.hasOwnProperty(match[1])) {
|
|
|
|
storage.removeItem(key);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-16 10:47:35 +00:00
|
|
|
return fileSystem;
|
2014-04-10 23:22:30 +00:00
|
|
|
});
|