Restore Gaia settings and media workflows, extend native network adapters, and align the APK payload. Generate French/English changelogs and website entries from the simplified JSON source. Validation: shared JS and Tundra unit tests; desktop workflows and persistence; signed APK payload parity; Sargo RAM and installed startup with boot readback. Android runtime qualification is recorded separately.
101 lines
2.6 KiB
JavaScript
Executable file
101 lines
2.6 KiB
JavaScript
Executable file
define(function(require, exports, module) {
|
|
'use strict';
|
|
|
|
// This handles the logic pertaining to the naming of files according
|
|
// to the Design rule for Camera File System
|
|
// * http://en.wikipedia.org/wiki/Design_rule_for_Camera_File_system
|
|
|
|
/**
|
|
* Dependencies
|
|
*/
|
|
|
|
var asyncStorage = require('asyncStorage');
|
|
var debug = require('debug')('dcf');
|
|
var format = require('format');
|
|
|
|
/**
|
|
* Locals
|
|
*/
|
|
|
|
var dcfConfigLoaded = false;
|
|
var deferredArgs = null;
|
|
var defaultSeq = {file: 1, dir: 100};
|
|
var dcfConfig = {
|
|
key: 'dcf_key',
|
|
seq: null,
|
|
postFix: 'MZLLA',
|
|
prefix: {video: 'VID_', image: 'IMG_'},
|
|
ext: {video: window.VulpesVideoExtension || '3gp', image: 'jpg'}
|
|
};
|
|
|
|
exports.init = function() {
|
|
debug('initializing');
|
|
exports.checkFileCounter(function() {
|
|
// We have a previous call to createDCFFilename that is waiting for
|
|
// a response, fire it again
|
|
if (deferredArgs) {
|
|
var args = deferredArgs;
|
|
exports.createDCFFilename(args.storage, args.type, args.callback);
|
|
deferredArgs = null;
|
|
}
|
|
|
|
debug('initialized');
|
|
});
|
|
};
|
|
|
|
exports.checkFileCounter = function(callback) {
|
|
asyncStorage.getItem(dcfConfig.key, function(value) {
|
|
dcfConfigLoaded = true;
|
|
dcfConfig.seq = value ? value : defaultSeq;
|
|
|
|
if (callback) {
|
|
callback();
|
|
}
|
|
});
|
|
};
|
|
|
|
exports.createDCFFilename = function(storage, type, callback) {
|
|
|
|
// We havent loaded the current counters from indexedDB yet, defer
|
|
// the call
|
|
if (!dcfConfigLoaded) {
|
|
deferredArgs = {storage: storage, type: type, callback: callback};
|
|
return;
|
|
}
|
|
|
|
var dir = 'DCIM/' + dcfConfig.seq.dir + dcfConfig.postFix + '/';
|
|
var filename = dcfConfig.prefix[type] +
|
|
format.padLeft(dcfConfig.seq.file, 4, '0') + '.' +
|
|
dcfConfig.ext[type];
|
|
var filepath = dir + filename;
|
|
|
|
// A file with this name may have been written by the user or
|
|
// our indexeddb sequence tracker was cleared, check we wont overwrite
|
|
// anything
|
|
var req = storage.get(filepath);
|
|
|
|
// A file existed, we bump the directory then try to generate a
|
|
// new filename
|
|
req.onsuccess = function() {
|
|
dcfConfig.seq.file = 1;
|
|
dcfConfig.seq.dir += 1;
|
|
asyncStorage.setItem(dcfConfig.key, dcfConfig.seq, function() {
|
|
exports.createDCFFilename(storage, type, callback);
|
|
});
|
|
};
|
|
|
|
// No file existed, we are good to go
|
|
req.onerror = function() {
|
|
if (dcfConfig.seq.file < 9999) {
|
|
dcfConfig.seq.file += 1;
|
|
} else {
|
|
dcfConfig.seq.file = 1;
|
|
dcfConfig.seq.dir += 1;
|
|
}
|
|
asyncStorage.setItem(dcfConfig.key, dcfConfig.seq, function() {
|
|
callback(filepath, filename, dir);
|
|
});
|
|
};
|
|
};
|
|
|
|
});
|