You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2012/06/07 22:40:44 UTC

[39/48] js commit: got things to an almost writing state - currently experiencing error 2004 when writing

got things to an almost writing state - currently experiencing error 2004 when writing


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/23ccd0b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/23ccd0b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/23ccd0b8

Branch: refs/heads/master
Commit: 23ccd0b8e6d5066475690ca9735babeedf18bd83
Parents: 34b6e3f
Author: Tim Kim <ti...@adobe.com>
Authored: Tue May 8 18:16:41 2012 -0700
Committer: Tim Kim <ti...@nitobi.com>
Committed: Thu Jun 7 13:40:22 2012 -0700

----------------------------------------------------------------------
 lib/playbook/platform.js                          |    8 +-
 lib/playbook/plugin/playbook/FileEntry.js         |  116 +++++++---------
 lib/playbook/plugin/playbook/FileWriter.js        |   27 ++++-
 lib/playbook/plugin/playbook/requestFileSystem.js |    3 +-
 4 files changed, 82 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/23ccd0b8/lib/playbook/platform.js
----------------------------------------------------------------------
diff --git a/lib/playbook/platform.js b/lib/playbook/platform.js
index 0ec37a6..adabc6c 100644
--- a/lib/playbook/platform.js
+++ b/lib/playbook/platform.js
@@ -8,9 +8,6 @@ module.exports = {
         File:{
             path: 'cordova/plugin/playbook/File'
         },
-        FileEntry:{
-            path: 'cordova/plugin/playbook/FileEntry'
-        },
         FileReader:{
             path: 'cordova/plugin/playbook/FileReader'
         },
@@ -34,6 +31,9 @@ module.exports = {
         },
         Entry: {
             path: 'cordova/plugin/playbook/Entry'
-        }
+        },
+        FileEntry:{
+            path: 'cordova/plugin/playbook/FileEntry'
+        },
     }
 };

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/23ccd0b8/lib/playbook/plugin/playbook/FileEntry.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/FileEntry.js b/lib/playbook/plugin/playbook/FileEntry.js
index 77a2588..5edfa37 100644
--- a/lib/playbook/plugin/playbook/FileEntry.js
+++ b/lib/playbook/plugin/playbook/FileEntry.js
@@ -1,73 +1,59 @@
-var utils = require('cordova/utils'),
+var FileEntry = require('cordova/plugin/FileEntry')
     Entry = require('cordova/plugin/playbook/Entry'),
     FileWriter = require('cordova/plugin/playbook/FileWriter'),
     File = require('cordova/plugin/playbook/File'),
     FileError = require('cordova/plugin/FileError');
 
-/**
- * An interface representing a file on the file system.
- *
- * {boolean} isFile always true (readonly)
- * {boolean} isDirectory always false (readonly)
- * {DOMString} name of the file, excluding the path leading to it (readonly)
- * {DOMString} fullPath the absolute full path to the file (readonly)
- * {FileSystem} filesystem on which the file resides (readonly)
- */
-var FileEntry = function(name, fullPath) {
-     FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath]);
-};
-
-utils.extend(FileEntry, Entry);
-
-/**
- * Creates a new FileWriter associated with the file that this FileEntry represents.
- *
- * @param {Function} successCallback is called with the new FileWriter
- * @param {Function} errorCallback is called with a FileError
- */
-FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
-    this.file(function(filePointer) {
-        var writer = new FileWriter(filePointer);
-
-        if (writer.fileName === null || writer.fileName === "") {
-            if (typeof errorCallback === "function") {
-                errorCallback(new FileError(FileError.INVALID_STATE_ERR));
-            }
-        } else {
-            if (typeof successCallback === "function") {
-                successCallback(writer);
+module.exports = {
+    /**
+     * Creates a new FileWriter associated with the file that this FileEntry represents.
+     *
+     * @param {Function} successCallback is called with the new FileWriter
+     * @param {Function} errorCallback is called with a FileError
+     */
+    createWriter : function(successCallback, errorCallback) {
+        this.file(function(filePointer) {
+            var writer = new FileWriter(filePointer);
+
+            if (writer.fileName === null || writer.fileName === "") {
+                if (typeof errorCallback === "function") {
+                    errorCallback(new FileError(FileError.INVALID_STATE_ERR));
+                }
+            } else {
+                if (typeof successCallback === "function") {
+                    successCallback(writer);
+                }
             }
-        }
-    }, errorCallback);
+        }, errorCallback);
+    },
+
+    /**
+     * Returns a File that represents the current state of the file that this FileEntry represents.
+     *
+     * @param {Function} successCallback is called with the new File object
+     * @param {Function} errorCallback is called with a FileError
+     */
+    file : function(successCallback, errorCallback) {
+        var win = typeof successCallback !== 'function' ? null : function(f) {
+            var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size);
+            successCallback(file);
+        };
+        var fail = typeof errorCallback !== 'function' ? null : function(code) {
+            errorCallback(new FileError(code));
+        };
+        console.log('getting file properties');
+        // TODO Need to set up win/fail callbacks
+        var theFileProperties = blackberry.io.file.getFileProperties(this.fullPath);
+        var theFile = {};
+        console.log(this.fullPath);
+        console.log(this.name);
+        //theFile.name =
+        theFile.fullPath = this.fullPath;
+        theFile.type = theFileProperties.fileExtension;
+        theFile.lastModifiedDate = theFileProperties.dateModified;
+        theFile.size = theFileProperties.size;
+        win(theFile);
+        //exec(win, fail, "File", "getFileMetadata", [this.fullPath]);
+    }
 };
 
-/**
- * Returns a File that represents the current state of the file that this FileEntry represents.
- *
- * @param {Function} successCallback is called with the new File object
- * @param {Function} errorCallback is called with a FileError
- */
-FileEntry.prototype.file = function(successCallback, errorCallback) {
-    var win = typeof successCallback !== 'function' ? null : function(f) {
-        var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size);
-        successCallback(file);
-    };
-    var fail = typeof errorCallback !== 'function' ? null : function(code) {
-        errorCallback(new FileError(code));
-    };
-    console.log('getting file properties');
-
-    var theFileProperties = blackberry.io.file.getFileProperties(this.fullPath);
-    var theFile = {};
-    console.log(this.fullPath);
-    console.log(this.name);
-    //theFile.name =
-    theFile.fullPath = this.fullPath;
-    theFile.type = theFileProperties.fileExtension;
-    theFile.lastModifiedDate = theFileProperties.dateModified;
-    theFile.size = theFileProperties.size;
-    //exec(win, fail, "File", "getFileMetadata", [this.fullPath]);
-};
-
-
-module.exports = FileEntry;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/23ccd0b8/lib/playbook/plugin/playbook/FileWriter.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/FileWriter.js b/lib/playbook/plugin/playbook/FileWriter.js
index ee43231..f7f2186 100644
--- a/lib/playbook/plugin/playbook/FileWriter.js
+++ b/lib/playbook/plugin/playbook/FileWriter.js
@@ -85,10 +85,35 @@ FileWriter.prototype.write = function(text) {
 
     // Write file
     // TODO: Need to think about how to make this asynch
+    // can't append to file - must open a temp file, write to temp, then delete current file
+    // and save again - lame
+    // also have to investigate how bb blobs work in order to set proper seek positions :S
     console.log('writing to file');
     var textBlob = blackberry.utils.stringToBlob(text);
-    blackberry.io.file.saveFile(this.fileName, textBlob);
+    if(blackberry.io.file.exists(this.fileName)){
+        // for now just overwrite
+        var oldTextBlob = '';
+        var getFileContents = function(path,blob){
+            if(blob){
+                oldTextBlob = blackberry.utils.blobToString(blob);
+            }
+            // seek position stuff here
+            var newTextBlob = text;
+            console.log('old text: ' + oldTextBlob);
+            console.log('new text: ' + newTextBlob);
+            blackberry.io.file.saveFile(this.fileName+'temp', blackberry.utils.stringToBlob(newTextBlob));
+            blackberry.io.file.deleteFile(this.fileName);
+            blackberry.io.file.rename(this.fileName+'temp', this.fileName);
+        }
+        // setting asynch to off - worry about making this all callbacks later
+        blackberry.io.file.readFile(this.fileName, getFileContents, false);
+
+    }else{
+        blackberry.io.file.saveFile(this.fileName, textBlob);
+    }
+
     me.readyState = FileWriter.DONE;
+    console.log('done writing file');
     /*
     exec(
         // Success callback

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/23ccd0b8/lib/playbook/plugin/playbook/requestFileSystem.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/requestFileSystem.js b/lib/playbook/plugin/playbook/requestFileSystem.js
index aa7d3e9..20aab56 100644
--- a/lib/playbook/plugin/playbook/requestFileSystem.js
+++ b/lib/playbook/plugin/playbook/requestFileSystem.js
@@ -1,7 +1,6 @@
-var DirectoryEntry = require('cordova/plugin/playbook/DirectoryEntry'),
+var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
 FileError = require('cordova/plugin/FileError'),
 FileSystem = require('cordova/plugin/FileSystem');
-    var exec = require('cordova/exec');
 
 /**
  * Request a file system in which to store application data.