Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
101
gaia/apps/camera/js/lib/dcf.js
Executable file
101
gaia/apps/camera/js/lib/dcf.js
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
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: '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);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue