cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Fry (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-2212) FileSystem getFile() call never finds file on WP8 as isolated storage is empty
Date Wed, 16 Jan 2013 17:24:13 GMT

    [ https://issues.apache.org/jira/browse/CB-2212?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13555234#comment-13555234
] 

Michael Fry commented on CB-2212:
---------------------------------

Well, to demo it requires a bit of setup but it can be pretty easily replicated following
these steps.

# Create a new project using the Cordova 2.3.0 Standalone template.
# Add a file called readme.txt in the www directory with some random text in it.
# Replace the contents of index.js with this (a mix of the template code and the file reader
example from the documentation):
{code:JavaScript}
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // `load`, `deviceready`, `offline`, and `online`.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of `this` is the event. In order to call the `receivedEvent`
    // function, we must explicity call `app.receivedEvent(...);`
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, app.gotFS, app.fail);
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');
        
        console.log('Received Event: ' + id);
    },
    gotFS: function (fileSystem) {
        fileSystem.root.getFile("www/readme.txt", null, app.gotFileEntry, app.fail);
    },
    gotFileEntry: function (fileEntry) {
        fileEntry.file(app.gotFile, app.fail);
    },
    gotFile: function (file){
        app.readAsText(file);
    },
    readAsText: function (file) {
        var reader = new FileReader();
        reader.onloadend = function(evt) {
            console.log("Read as text");
            console.log(evt.target.result);
        };
        reader.readAsText(file);
    },
    fail: function (evt) {
        console.log(JSON.stringify(evt));
    }
};
{code}
# Run the project... In the console you should see the error code: 1 (file not found)
# Now, to fix the error we need to make sure files are added to isolated storage.
# Create a CordovaSourceDictionary.xml in the project root and add the following to it.
{code:xml}
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated, do not edit! -jm -->
<CordovaSourceDictionary>
  <FilePath Value="www\index.html"/>
  <FilePath Value="www\readme.txt"/>
</CordovaSourceDictionary>
{code}
# Open the code behind file CordovaView.xaml.cs and go to line 254.  Uncomment this large
block of code so that the dictionary is parsed and files are added to isolated storage.
# Run again... the contents of readme.txt will now be shown in the console.

The problem lies in the File.cs Command class.  The call to GetFileOrDirectory counts on the
files being in IsolatedStorage.  With the code commented out in CordovaView.xaml.cs this is
never created and then any attempts to use the FileReader will not work.
                
> FileSystem getFile() call never finds file on WP8 as isolated storage is empty
> ------------------------------------------------------------------------------
>
>                 Key: CB-2212
>                 URL: https://issues.apache.org/jira/browse/CB-2212
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: WP8
>    Affects Versions: 2.3.0
>            Reporter: Michael Fry
>            Assignee: Jesse MacFadyen
>
> In attempting read a file included in my www folder I was continually returned an error
code of 0.  In digging in it appears it was due to file not found.
> In the GapBrowser_Loaded handler there is a large chunk of commented out code that notes
that in WP8 "isolated storage is no more required in WP8". It appears that this suppresses
the loading of isolated storage because when I view my emulator using WP power tools it is
empty.
> The file i/o code in File.cs reads/writes using isolated storage.  Without the www files
being loaded at startup it will never be able to make the reads from things like settings
or readme files.
> After uncommenting the code and creating a CordovaSourceDictionary.xml file I was able
to load isolated storage. File reads then worked as designed.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message