You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/07/25 21:09:52 UTC
[2/2] js commit: [Windows8] remove all plugins
[Windows8] remove all plugins
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/da415064
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/da415064
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/da415064
Branch: refs/heads/master
Commit: da415064997a1a9e84b197a31f873aaed8bba8dc
Parents: d716e31
Author: purplecabbage <pu...@gmail.com>
Authored: Thu Jul 25 12:09:01 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Thu Jul 25 12:09:01 2013 -0700
----------------------------------------------------------------------
lib/windows8/plugin/capture/symbols.js | 31 -
lib/windows8/plugin/file/symbols.js | 27 -
lib/windows8/plugin/media/symbols.js | 25 -
.../plugin/windows8/AccelerometerProxy.js | 70 --
lib/windows8/plugin/windows8/CameraProxy.js | 341 --------
lib/windows8/plugin/windows8/CaptureProxy.js | 161 ----
lib/windows8/plugin/windows8/CompassProxy.js | 65 --
lib/windows8/plugin/windows8/ContactsProxy.js | 48 --
lib/windows8/plugin/windows8/DeviceProxy.js | 49 --
lib/windows8/plugin/windows8/FileProxy.js | 845 -------------------
.../plugin/windows8/FileTransferProxy.js | 110 ---
lib/windows8/plugin/windows8/MediaFile.js | 65 --
lib/windows8/plugin/windows8/MediaProxy.js | 183 ----
.../plugin/windows8/NetworkStatusProxy.js | 87 --
.../plugin/windows8/NotificationProxy.js | 123 ---
lib/windows8/plugin/windows8/console.js | 46 -
lib/windows8/plugin/windows8/console/symbols.js | 24 -
.../plugin/windows8/notification/plugininit.js | 23 -
18 files changed, 2323 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/capture/symbols.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/capture/symbols.js b/lib/windows8/plugin/capture/symbols.js
deleted file mode 100644
index d47db46..0000000
--- a/lib/windows8/plugin/capture/symbols.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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 modulemapper = require('cordova/modulemapper');
-
-modulemapper.clobbers('cordova/plugin/CaptureError', 'CaptureError');
-modulemapper.clobbers('cordova/plugin/CaptureAudioOptions', 'CaptureAudioOptions');
-modulemapper.clobbers('cordova/plugin/CaptureImageOptions', 'CaptureImageOptions');
-modulemapper.clobbers('cordova/plugin/CaptureVideoOptions', 'CaptureVideoOptions');
-modulemapper.clobbers('cordova/plugin/MediaFile', 'MediaFile');
-modulemapper.clobbers('cordova/plugin/MediaFileData', 'MediaFileData');
-modulemapper.clobbers('cordova/plugin/capture', 'navigator.device.capture');
-
-modulemapper.merges('cordova/plugin/windows8/MediaFile', 'MediaFile');
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/file/symbols.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/file/symbols.js b/lib/windows8/plugin/file/symbols.js
deleted file mode 100644
index 12a1c8c..0000000
--- a/lib/windows8/plugin/file/symbols.js
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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 modulemapper = require('cordova/modulemapper'),
- symbolshelper = require('cordova/plugin/file/symbolshelper');
-
-symbolshelper(modulemapper.defaults);
-modulemapper.clobbers('cordova/plugin/File', 'File');
-modulemapper.clobbers('cordova/plugin/FileReader', 'FileReader');
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/media/symbols.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/media/symbols.js b/lib/windows8/plugin/media/symbols.js
deleted file mode 100644
index 2039a1f..0000000
--- a/lib/windows8/plugin/media/symbols.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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 modulemapper = require('cordova/modulemapper');
-
-modulemapper.defaults('cordova/plugin/Media', 'Media');
-modulemapper.clobbers('cordova/plugin/MediaError', 'MediaError');
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/windows8/AccelerometerProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/AccelerometerProxy.js b/lib/windows8/plugin/windows8/AccelerometerProxy.js
deleted file mode 100644
index 6ce617f..0000000
--- a/lib/windows8/plugin/windows8/AccelerometerProxy.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-/*global Windows:true */
-
-var cordova = require('cordova'),
- Acceleration = require('cordova/plugin/Acceleration');
-
-/* This is the actual implementation part that returns the result on Windows 8
-*/
-
-module.exports = {
- onDataChanged:null,
- start:function(win,lose){
-
- var accel = Windows.Devices.Sensors.Accelerometer.getDefault();
- if(!accel) {
- lose && lose("No accelerometer found");
- }
- else {
- var self = this;
- accel.reportInterval = Math.max(16,accel.minimumReportInterval);
-
- // store our bound function
- this.onDataChanged = function(e) {
- var a = e.reading;
- win(new Acceleration(a.accelerationX,a.accelerationY,a.accelerationZ));
- };
- accel.addEventListener("readingchanged",this.onDataChanged);
-
- setTimeout(function(){
- var a = accel.getCurrentReading();
- win(new Acceleration(a.accelerationX,a.accelerationY,a.accelerationZ));
- },0); // async do later
- }
- },
- stop:function(win,lose){
- win = win || function(){};
- var accel = Windows.Devices.Sensors.Accelerometer.getDefault();
- if(!accel) {
- lose && lose("No accelerometer found");
- }
- else {
- accel.removeEventListener("readingchanged",this.onDataChanged);
- this.onDataChanged = null;
- accel.reportInterval = 0; // back to the default
- win();
- }
- }
-};
-
-require("cordova/commandProxy").add("Accelerometer",module.exports);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/windows8/CameraProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/CameraProxy.js b/lib/windows8/plugin/windows8/CameraProxy.js
deleted file mode 100644
index 13fe029..0000000
--- a/lib/windows8/plugin/windows8/CameraProxy.js
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-/*global Windows:true, URL:true */
-
-
-var cordova = require('cordova'),
- Camera = require('cordova/plugin/CameraConstants'),
- FileEntry = require('cordova/plugin/FileEntry'),
- FileError = require('cordova/plugin/FileError'),
- FileReader = require('cordova/plugin/FileReader');
-
-module.exports = {
-
- // args will contain :
- // ... it is an array, so be careful
- // 0 quality:50,
- // 1 destinationType:Camera.DestinationType.FILE_URI,
- // 2 sourceType:Camera.PictureSourceType.CAMERA,
- // 3 targetWidth:-1,
- // 4 targetHeight:-1,
- // 5 encodingType:Camera.EncodingType.JPEG,
- // 6 mediaType:Camera.MediaType.PICTURE,
- // 7 allowEdit:false,
- // 8 correctOrientation:false,
- // 9 saveToPhotoAlbum:false,
- // 10 popoverOptions:null
-
- takePicture: function (successCallback, errorCallback, args) {
- var encodingType = args[5];
- var targetWidth = args[3];
- var targetHeight = args[4];
- var sourceType = args[2];
- var destinationType = args[1];
- var mediaType = args[6];
- var saveToPhotoAlbum = args[9];
-
- var pkg = Windows.ApplicationModel.Package.current;
- var packageId = pkg.installedLocation;
-
- var fail = function (fileError) {
- errorCallback("FileError, code:" + fileError.code);
- };
-
- // resize method :)
- var resizeImage = function (file) {
- var tempPhotoFileName = "";
- if (encodingType == Camera.EncodingType.PNG) {
- tempPhotoFileName = "camera_cordova_temp_return.png";
- } else {
- tempPhotoFileName = "camera_cordova_temp_return.jpg";
- }
- var imgObj = new Image();
- var success = function (fileEntry) {
- var successCB = function (filePhoto) {
- var fileType = file.contentType,
- reader = new FileReader();
- reader.onloadend = function () {
- var image = new Image();
- image.src = reader.result;
- image.onload = function () {
- var imageWidth = targetWidth,
- imageHeight = targetHeight;
- var canvas = document.createElement('canvas');
-
- canvas.width = imageWidth;
- canvas.height = imageHeight;
-
- var ctx = canvas.getContext("2d");
- ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
-
- // The resized file ready for upload
- var _blob = canvas.msToBlob();
- var _stream = _blob.msDetachStream();
- Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
- storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
- file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
- Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
- var _imageUrl = URL.createObjectURL(file);
- successCallback(_imageUrl);
- }, function () { errorCallback("Resize picture error."); });
- }, function () { errorCallback("Resize picture error."); });
- }, function () { errorCallback("Resize picture error."); });
- });
- };
- };
-
- reader.readAsDataURL(filePhoto);
- };
-
- var failCB = function () {
- errorCallback("File not found.");
- };
- fileEntry.file(successCB, failCB);
- };
-
- Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
- file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
- success(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }, function () {
- errorCallback("Folder not access.");
- });
- });
-
- };
-
- // because of asynchronous method, so let the successCallback be called in it.
- var resizeImageBase64 = function (file) {
- var imgObj = new Image();
- var success = function (fileEntry) {
- var successCB = function (filePhoto) {
- var fileType = file.contentType,
- reader = new FileReader();
- reader.onloadend = function () {
- var image = new Image();
- image.src = reader.result;
-
- image.onload = function () {
- var imageWidth = targetWidth,
- imageHeight = targetHeight;
- var canvas = document.createElement('canvas');
-
- canvas.width = imageWidth;
- canvas.height = imageHeight;
-
- var ctx = canvas.getContext("2d");
- ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
-
- // The resized file ready for upload
- var finalFile = canvas.toDataURL(fileType);
-
- // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
- var arr = finalFile.split(",");
- var newStr = finalFile.substr(arr[0].length + 1);
- successCallback(newStr);
- };
- };
-
- reader.readAsDataURL(filePhoto);
-
- };
- var failCB = function () {
- errorCallback("File not found.");
- };
- fileEntry.file(successCB, failCB);
- };
-
- Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
- file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
- success(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }, function () {
- errorCallback("Folder not access.");
- });
- });
-
- };
-
- if (sourceType != Camera.PictureSourceType.CAMERA) {
- var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
- fileOpenPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
- if (mediaType == Camera.MediaType.PICTURE) {
- fileOpenPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
- } else if (mediaType == Camera.MediaType.VIDEO) {
- fileOpenPicker.fileTypeFilter.replaceAll([".avi", ".flv", ".asx", ".asf", ".mov", ".mp4", ".mpg", ".rm", ".srt", ".swf", ".wmv", ".vob"]);
- } else {
- fileOpenPicker.fileTypeFilter.replaceAll(["*"]);
- }
-
- fileOpenPicker.pickSingleFileAsync().then(function (file) {
- if (file) {
- if (destinationType == Camera.DestinationType.FILE_URI) {
- if (targetHeight > 0 && targetWidth > 0) {
- resizeImage(file);
- } else {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
- file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
- var _imageUrl = URL.createObjectURL(storageFile);
- successCallback(_imageUrl);
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }, function () {
- errorCallback("Folder not access.");
- });
- });
-
- }
- }
- else {
- if (targetHeight > 0 && targetWidth > 0) {
- resizeImageBase64(file);
- } else {
- Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer) {
- var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
- successCallback(strBase64);
- });
- }
-
- }
-
- } else {
- errorCallback("User didn't choose a file.");
- }
- }, function () {
- errorCallback("User didn't choose a file.");
- });
- }
- else {
-
- var cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
- cameraCaptureUI.photoSettings.allowCropping = true;
- var allowCrop = !!args[7];
- if (!allowCrop) {
- cameraCaptureUI.photoSettings.allowCropping = false;
- }
-
- if (encodingType == Camera.EncodingType.PNG) {
- cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.png;
- } else {
- cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
- }
- // decide which max pixels should be supported by targetWidth or targetHeight.
- if (targetWidth >= 1280 || targetHeight >= 960) {
- cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.large3M;
- } else if (targetWidth >= 1024 || targetHeight >= 768) {
- cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
- } else if (targetWidth >= 800 || targetHeight >= 600) {
- cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
- } else if (targetWidth >= 640 || targetHeight >= 480) {
- cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.smallVga;
- } else if (targetWidth >= 320 || targetHeight >= 240) {
- cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.verySmallQvga;
- } else {
- cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
- }
-
- cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function (picture) {
- if (picture) {
- // save to photo album successCallback
- var success = function (fileEntry) {
- if (destinationType == Camera.DestinationType.FILE_URI) {
- if (targetHeight > 0 && targetWidth > 0) {
- resizeImage(picture);
- } else {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
- picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
- var _imageUrl = URL.createObjectURL(storageFile);
- successCallback(_imageUrl);
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }, function () {
- errorCallback("Folder not access.");
- });
- });
- }
- } else {
- if (targetHeight > 0 && targetWidth > 0) {
- resizeImageBase64(picture);
- } else {
- Windows.Storage.FileIO.readBufferAsync(picture).done(function (buffer) {
- var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
- successCallback(strBase64);
- });
- }
- }
- };
- // save to photo album errorCallback
- var fail = function () {
- //errorCallback("FileError, code:" + fileError.code);
- errorCallback("Save fail.");
- };
-
- if (saveToPhotoAlbum) {
- Windows.Storage.StorageFile.getFileFromPathAsync(picture.path).then(function (storageFile) {
- storageFile.copyAsync(Windows.Storage.KnownFolders.picturesLibrary, picture.name, Windows.Storage.NameCollisionOption.generateUniqueName).then(function (storageFile) {
- success(storageFile);
- }, function () {
- fail();
- });
- });
- //var directory = new DirectoryEntry("Pictures", parentPath);
- //new FileEntry(picture.name, picture.path).copyTo(directory, null, success, fail);
- } else {
- if (destinationType == Camera.DestinationType.FILE_URI) {
- if (targetHeight > 0 && targetWidth > 0) {
- resizeImage(picture);
- } else {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
- picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
- var _imageUrl = URL.createObjectURL(storageFile);
- successCallback(_imageUrl);
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }, function () {
- errorCallback("Folder not access.");
- });
- });
- }
- } else {
- if (targetHeight > 0 && targetWidth > 0) {
- resizeImageBase64(picture);
- } else {
- Windows.Storage.FileIO.readBufferAsync(picture).done(function (buffer) {
- var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
- successCallback(strBase64);
- });
- }
- }
- }
- } else {
- errorCallback("User didn't capture a photo.");
- }
- }, function () {
- errorCallback("Fail to capture a photo.");
- });
- }
- }
-};
-
-require("cordova/commandProxy").add("Camera",module.exports);
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/windows8/CaptureProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/CaptureProxy.js b/lib/windows8/plugin/windows8/CaptureProxy.js
deleted file mode 100644
index 1e76ddb..0000000
--- a/lib/windows8/plugin/windows8/CaptureProxy.js
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-/*global Windows:true */
-
-var MediaFile = require('cordova/plugin/MediaFile');
-var CaptureError = require('cordova/plugin/CaptureError');
-var CaptureAudioOptions = require('cordova/plugin/CaptureAudioOptions');
-var CaptureImageOptions = require('cordova/plugin/CaptureImageOptions');
-var CaptureVideoOptions = require('cordova/plugin/CaptureVideoOptions');
-var MediaFileData = require('cordova/plugin/MediaFileData');
-
-module.exports = {
-
- captureAudio:function(successCallback, errorCallback, args) {
- var options = args[0];
-
- var audioOptions = new CaptureAudioOptions();
- if (typeof(options.duration) == 'undefined') {
- audioOptions.duration = 3600; // Arbitrary amount, need to change later
- } else if (options.duration > 0) {
- audioOptions.duration = options.duration;
- } else {
- errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
- return;
- }
-
- var cameraCaptureAudioDuration = audioOptions.duration;
- var mediaCaptureSettings;
- var initCaptureSettings = function () {
- mediaCaptureSettings = null;
- mediaCaptureSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
- mediaCaptureSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio;
- };
-
- initCaptureSettings();
- var mediaCapture = new Windows.Media.Capture.MediaCapture();
- mediaCapture.initializeAsync(mediaCaptureSettings).done(function () {
- Windows.Storage.KnownFolders.musicLibrary.createFileAsync("captureAudio.mp3", Windows.Storage.NameCollisionOption.generateUniqueName).then(function (storageFile) {
- var mediaEncodingProfile = new Windows.Media.MediaProperties.MediaEncodingProfile.createMp3(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
- var stopRecord = function () {
- mediaCapture.stopRecordAsync().then(function (result) {
- storageFile.getBasicPropertiesAsync().then(function (basicProperties) {
- var results = [];
- results.push(new MediaFile(storageFile.name, storageFile.path, storageFile.contentType, basicProperties.dateModified, basicProperties.size));
- successCallback(results);
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
- });
- }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
- };
- mediaCapture.startRecordToStorageFileAsync(mediaEncodingProfile, storageFile).then(function () {
- setTimeout(stopRecord, cameraCaptureAudioDuration * 1000);
- }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
- }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
- });
- },
-
- captureImage:function (successCallback, errorCallback, args) {
- var options = args[0];
- var imageOptions = new CaptureImageOptions();
- var cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
- cameraCaptureUI.photoSettings.allowCropping = true;
- cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
- cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
- cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function (file) {
- file.moveAsync(Windows.Storage.KnownFolders.picturesLibrary, "cameraCaptureImage.jpg", Windows.Storage.NameCollisionOption.generateUniqueName).then(function () {
- file.getBasicPropertiesAsync().then(function (basicProperties) {
- var results = [];
- results.push(new MediaFile(file.name, file.path, file.contentType, basicProperties.dateModified, basicProperties.size));
- successCallback(results);
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
- });
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
- });
- }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
- },
-
- captureVideo:function (successCallback, errorCallback, args) {
- var options = args[0];
- var videoOptions = new CaptureVideoOptions();
- if (options.duration && options.duration > 0) {
- videoOptions.duration = options.duration;
- }
- if (options.limit > 1) {
- videoOptions.limit = options.limit;
- }
- var cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
- cameraCaptureUI.videoSettings.allowTrimming = true;
- cameraCaptureUI.videoSettings.format = Windows.Media.Capture.CameraCaptureUIVideoFormat.mp4;
- cameraCaptureUI.videoSettings.maxDurationInSeconds = videoOptions.duration;
- cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.video).then(function (file) {
- file.moveAsync(Windows.Storage.KnownFolders.videosLibrary, "cameraCaptureVedio.mp4", Windows.Storage.NameCollisionOption.generateUniqueName).then(function () {
- file.getBasicPropertiesAsync().then(function (basicProperties) {
- var results = [];
- results.push(new MediaFile(file.name, file.path, file.contentType, basicProperties.dateModified, basicProperties.size));
- successCallback(results);
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
- });
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
- });
- }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
-
- },
-
- getFormatData: function (successCallback, errorCallback, args) {
- Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
- function (storageFile) {
- var mediaTypeFlag = String(storageFile.contentType).split("/")[0].toLowerCase();
- if (mediaTypeFlag === "audio") {
- storageFile.properties.getMusicPropertiesAsync().then(function (audioProperties) {
- successCallback(new MediaFileData(null, audioProperties.bitrate, 0, 0, audioProperties.duration / 1000));
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
- });
- }
- else if (mediaTypeFlag === "video") {
- storageFile.properties.getVideoPropertiesAsync().then(function (videoProperties) {
- successCallback(new MediaFileData(null, videoProperties.bitrate, videoProperties.height, videoProperties.width, videoProperties.duration / 1000));
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
- });
- }
- else if (mediaTypeFlag === "image") {
- storageFile.properties.getImagePropertiesAsync().then(function (imageProperties) {
- successCallback(new MediaFileData(null, 0, imageProperties.height, imageProperties.width, 0));
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
- });
- }
- else { errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT)); }
- }, function () {
- errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
- }
- );
- }
-};
-
-require("cordova/commandProxy").add("Capture",module.exports);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/windows8/CompassProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/CompassProxy.js b/lib/windows8/plugin/windows8/CompassProxy.js
deleted file mode 100644
index 91a4037..0000000
--- a/lib/windows8/plugin/windows8/CompassProxy.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-/*global Windows:true */
-
-var cordova = require('cordova'),
- CompassHeading = require('cordova/plugin/CompassHeading');
-
-
-module.exports = {
-
- onReadingChanged:null,
- getHeading:function(win,lose) {
- var deviceCompass = Windows.Devices.Sensors.Compass.getDefault();
- if(!deviceCompass) {
- setTimeout(function(){lose("Compass not available");},0);
- }
- else {
-
- deviceCompass.reportInterval = Math.max(16,deviceCompass.minimumReportInterval);
-
- this.onReadingChanged = function(e) {
- var reading = e.reading;
- var heading = new CompassHeading(reading.headingMagneticNorth, reading.headingTrueNorth);
- win(heading);
- };
- deviceCompass.addEventListener("readingchanged",this.onReadingChanged);
- }
-
- },
- stopHeading:function(win,lose) {
- var deviceCompass = Windows.Devices.Sensors.Compass.getDefault();
- if(!deviceCompass) {
- setTimeout(function(){lose("Compass not available");},0);
- }
- else {
-
- deviceCompass.removeEventListener("readingchanged",this.onReadingChanged);
- this.onReadingChanged = null;
- deviceCompass.reportInterval = 0;
- win();
- }
-
- }
-};
-
-require("cordova/commandProxy").add("Compass",module.exports);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/windows8/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/ContactsProxy.js b/lib/windows8/plugin/windows8/ContactsProxy.js
deleted file mode 100644
index 629dbca..0000000
--- a/lib/windows8/plugin/windows8/ContactsProxy.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *
- * 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 cordova = require('cordova');
-
-module.exports = {
- search: function (win, fail, args) {
- var fields = args[0];
- var options = args[1];
- var picker = Windows.ApplicationModel.Contacts.ContactPicker();
- picker.commitButtonText = "Select";
- picker.selectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.contacts;
-
- picker.desiredFields.push.apply(picker.desiredFields, fields);
-
- if (options.multiple) {
- picker.pickMultipleContactsAsync().then(function (contacts) {
- win(contacts);
- });
- }
- else {
- picker.pickSingleContactAsync().then(function (contact) {
- win([contact]);
- });
- }
- }
-
-};
-
-require("cordova/commandProxy").add("Contacts",module.exports);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/windows8/DeviceProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/DeviceProxy.js b/lib/windows8/plugin/windows8/DeviceProxy.js
deleted file mode 100644
index 7379f48..0000000
--- a/lib/windows8/plugin/windows8/DeviceProxy.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *
- * 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 cordova = require('cordova');
-var utils = require('cordova/utils');
-var FileError = require('cordova/plugin/FileError');
-
-
-module.exports = {
-
- getDeviceInfo:function(win,fail,args) {
-
- // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId
- var deviceId;
- var localSettings = Windows.Storage.ApplicationData.current.localSettings;
-
- if (localSettings.values.deviceId) {
- deviceId = localSettings.values.deviceId;
- }
- else {
- deviceId = localSettings.values.deviceId = utils.createUUID();
- }
-
- setTimeout(function () {
- win({ platform: "windows8", version: "8", uuid: deviceId, cordova: CORDOVA_JS_BUILD_LABEL });
- }, 0);
- }
-
-};
-
-require("cordova/commandProxy").add("Device",module.exports);
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/da415064/lib/windows8/plugin/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/FileProxy.js b/lib/windows8/plugin/windows8/FileProxy.js
deleted file mode 100644
index 717f143..0000000
--- a/lib/windows8/plugin/windows8/FileProxy.js
+++ /dev/null
@@ -1,845 +0,0 @@
-/*
- *
- * 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 cordova = require('cordova');
-var Entry = require('cordova/plugin/Entry'),
- File = require('cordova/plugin/File'),
- FileEntry = require('cordova/plugin/FileEntry'),
- FileError = require('cordova/plugin/FileError'),
- DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
- Flags = require('cordova/plugin/Flags'),
- FileSystem = require('cordova/plugin/FileSystem'),
- LocalFileSystem = require('cordova/plugin/LocalFileSystem');
-
-module.exports = {
-
- getFileMetadata:function(win,fail,args) {
- var fullPath = args[0];
-
- Windows.Storage.StorageFile.getFileFromPathAsync(fullPath).done(
- function (storageFile) {
- storageFile.getBasicPropertiesAsync().then(
- function (basicProperties) {
- win(new File(storageFile.name, storageFile.path, storageFile.fileType, basicProperties.dateModified, basicProperties.size));
- }, function () {
- fail && fail(FileError.NOT_READABLE_ERR);
- }
- );
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- },
-
- getMetadata:function(success,fail,args) {
- var fullPath = args[0];
-
- var dealFile = function (sFile) {
- Windows.Storage.StorageFile.getFileFromPathAsync(fullPath).then(
- function (storageFile) {
- return storageFile.getBasicPropertiesAsync();
- },
- function () {
- fail && fail(FileError.NOT_READABLE_ERR);
- }
- // get the basic properties of the file.
- ).then(
- function (basicProperties) {
- success(basicProperties.dateModified);
- },
- function () {
- fail && fail(FileError.NOT_READABLE_ERR);
- }
- );
- };
-
- var dealFolder = function (sFolder) {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(
- function (storageFolder) {
- return storageFolder.getBasicPropertiesAsync();
- },
- function () {
- fail && fail(FileError.NOT_READABLE_ERR);
- }
- // get the basic properties of the folder.
- ).then(
- function (basicProperties) {
- success(basicProperties.dateModified);
- },
- function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- };
-
- Windows.Storage.StorageFile.getFileFromPathAsync(fullPath).then(
- // the path is file.
- function (sFile) {
- dealFile(sFile);
- },
- // the path is folder
- function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(
- function (sFolder) {
- dealFolder(sFolder);
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- }
- );
- },
-
- getParent:function(win,fail,args) { // ["fullPath"]
- var fullPath = args[0];
-
- var storageFolderPer = Windows.Storage.ApplicationData.current.localFolder;
- var storageFolderTem = Windows.Storage.ApplicationData.current.temporaryFolder;
-
- if (fullPath == storageFolderPer.path) {
- win(new DirectoryEntry(storageFolderPer.name, storageFolderPer.path));
- return;
- } else if (fullPath == storageFolderTem.path) {
- win(new DirectoryEntry(storageFolderTem.name, storageFolderTem.path));
- return;
- }
- var splitArr = fullPath.split(new RegExp(/\/|\\/g));
-
- var popItem = splitArr.pop();
-
- var result = new DirectoryEntry(popItem, fullPath.substr(0, fullPath.length - popItem.length - 1));
- Windows.Storage.StorageFolder.getFolderFromPathAsync(result.fullPath).done(
- function () { win(result); },
- function () { fail && fail(FileError.INVALID_STATE_ERR); }
- );
- },
-
- readAsText:function(win,fail,args) {
- var fileName = args[0];
- var enc = args[1];
-
- Windows.Storage.StorageFile.getFileFromPathAsync(fileName).done(
- function (storageFile) {
- var value = Windows.Storage.Streams.UnicodeEncoding.utf8;
- if (enc == 'Utf16LE' || enc == 'utf16LE') {
- value = Windows.Storage.Streams.UnicodeEncoding.utf16LE;
- }else if (enc == 'Utf16BE' || enc == 'utf16BE') {
- value = Windows.Storage.Streams.UnicodeEncoding.utf16BE;
- }
- Windows.Storage.FileIO.readTextAsync(storageFile, value).done(
- function (fileContent) {
- win(fileContent);
- },
- function () {
- fail && fail(FileError.ENCODING_ERR);
- }
- );
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- },
-
- readAsDataURL:function(win,fail,args) {
- var fileName = args[0];
-
-
- Windows.Storage.StorageFile.getFileFromPathAsync(fileName).then(
- function (storageFile) {
- Windows.Storage.FileIO.readBufferAsync(storageFile).done(
- function (buffer) {
- var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
- //the method encodeToBase64String will add "77u/" as a prefix, so we should remove it
- if(String(strBase64).substr(0,4) == "77u/") {
- strBase64 = strBase64.substr(4);
- }
- var mediaType = storageFile.contentType;
- var result = "data:" + mediaType + ";base64," + strBase64;
- win(result);
- }
- );
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- },
-
- getDirectory:function(win,fail,args) {
- var fullPath = args[0];
- var path = args[1];
- var options = args[2];
-
- var flag = "";
- if (options !== null) {
- flag = new Flags(options.create, options.exclusive);
- } else {
- flag = new Flags(false, false);
- }
-
- Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(
- function (storageFolder) {
- if (flag.create === true && flag.exclusive === true) {
- storageFolder.createFolderAsync(path, Windows.Storage.CreationCollisionOption.failIfExists).done(
- function (storageFolder) {
- win(new DirectoryEntry(storageFolder.name, storageFolder.path));
- }, function () {
- fail && fail(FileError.PATH_EXISTS_ERR);
- }
- );
- } else if (flag.create === true && flag.exclusive === false) {
- storageFolder.createFolderAsync(path, Windows.Storage.CreationCollisionOption.openIfExists).done(
- function (storageFolder) {
- win(new DirectoryEntry(storageFolder.name, storageFolder.path));
- }, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
- } else if (flag.create === false) {
- if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(path)) {
- fail && fail(FileError.ENCODING_ERR);
- return;
- }
-
- storageFolder.getFolderAsync(path).done(
- function (storageFolder) {
- win(new DirectoryEntry(storageFolder.name, storageFolder.path));
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- }
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- },
-
- remove:function(win,fail,args) {
- var fullPath = args[0];
-
- Windows.Storage.StorageFile.getFileFromPathAsync(fullPath).then(
- function (sFile) {
- Windows.Storage.StorageFile.getFileFromPathAsync(fullPath).done(function (storageFile) {
- storageFile.deleteAsync().done(win, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
-
- });
- });
- },
- function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(
- function (sFolder) {
- var removeEntry = function () {
- var storageFolderTop = null;
-
- Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(
- function (storageFolder) {
- // FileSystem root can't be removed!
- var storageFolderPer = Windows.Storage.ApplicationData.current.localFolder;
- var storageFolderTem = Windows.Storage.ApplicationData.current.temporaryFolder;
- if (fullPath == storageFolderPer.path || fullPath == storageFolderTem.path) {
- fail && fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
- return;
- }
- storageFolderTop = storageFolder;
- return storageFolder.createFileQuery().getFilesAsync();
- }, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
-
- }
- // check sub-files.
- ).then(function (fileList) {
- if (fileList) {
- if (fileList.length === 0) {
- return storageFolderTop.createFolderQuery().getFoldersAsync();
- } else {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- }
- }
- // check sub-folders.
- }).then(function (folderList) {
- if (folderList) {
- if (folderList.length === 0) {
- storageFolderTop.deleteAsync().done(win, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
-
- });
- } else {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- }
- }
-
- });
- };
- removeEntry();
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- }
- );
- },
-
- removeRecursively:function(successCallback,fail,args) {
- var fullPath = args[0];
-
- Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).done(function (storageFolder) {
- var storageFolderPer = Windows.Storage.ApplicationData.current.localFolder;
- var storageFolderTem = Windows.Storage.ApplicationData.current.temporaryFolder;
-
- if (storageFolder.path == storageFolderPer.path || storageFolder.path == storageFolderTem.path) {
- fail && fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
- return;
- }
-
- var removeFolders = function (path) {
- return new WinJS.Promise(function (complete) {
- var filePromiseArr = [];
- var storageFolderTop = null;
- Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(
- function (storageFolder) {
- var fileListPromise = storageFolder.createFileQuery().getFilesAsync();
-
- storageFolderTop = storageFolder;
- return fileListPromise;
- }
- // remove all the files directly under the folder.
- ).then(function (fileList) {
- if (fileList !== null) {
- for (var i = 0; i < fileList.length; i++) {
- var filePromise = fileList[i].deleteAsync();
- filePromiseArr.push(filePromise);
- }
- }
- WinJS.Promise.join(filePromiseArr).then(function () {
- var folderListPromise = storageFolderTop.createFolderQuery().getFoldersAsync();
- return folderListPromise;
- // remove empty folders.
- }).then(function (folderList) {
- var folderPromiseArr = [];
- if (folderList.length !== 0) {
- for (var j = 0; j < folderList.length; j++) {
-
- folderPromiseArr.push(removeFolders(folderList[j].path));
- }
- WinJS.Promise.join(folderPromiseArr).then(function () {
- storageFolderTop.deleteAsync().then(complete);
- });
- } else {
- storageFolderTop.deleteAsync().then(complete);
- }
- }, function () { });
- }, function () { });
- });
- };
- removeFolders(storageFolder.path).then(function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(storageFolder.path).then(
- function () {},
- function () {
- if (typeof successCallback !== 'undefined' && successCallback !== null) { successCallback(); }
- });
- });
- });
- },
-
- getFile:function(win,fail,args) {
- var fullPath = args[0];
- var path = args[1];
- var options = args[2];
-
- var flag = "";
- if (options !== null) {
- flag = new Flags(options.create, options.exclusive);
- } else {
- flag = new Flags(false, false);
- }
-
- Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(
- function (storageFolder) {
- if (flag.create === true && flag.exclusive === true) {
- storageFolder.createFileAsync(path, Windows.Storage.CreationCollisionOption.failIfExists).done(
- function (storageFile) {
- win(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
- fail && fail(FileError.PATH_EXISTS_ERR);
- }
- );
- } else if (flag.create === true && flag.exclusive === false) {
- storageFolder.createFileAsync(path, Windows.Storage.CreationCollisionOption.openIfExists).done(
- function (storageFile) {
- win(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
- } else if (flag.create === false) {
- if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(path)) {
- fail && fail(FileError.ENCODING_ERR);
- return;
- }
- storageFolder.getFileAsync(path).done(
- function (storageFile) {
- win(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- }
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- },
-
- readEntries:function(win,fail,args) { // ["fullPath"]
- var path = args[0];
-
- var result = [];
-
- Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(function (storageFolder) {
- var promiseArr = [];
- var index = 0;
- promiseArr[index++] = storageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
- if (fileList !== null) {
- for (var i = 0; i < fileList.length; i++) {
- result.push(new FileEntry(fileList[i].name, fileList[i].path));
- }
- }
- });
- promiseArr[index++] = storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
- if (folderList !== null) {
- for (var j = 0; j < folderList.length; j++) {
- result.push(new FileEntry(folderList[j].name, folderList[j].path));
- }
- }
- });
- WinJS.Promise.join(promiseArr).then(function () {
- win(result);
- });
-
- }, function () { fail && fail(FileError.NOT_FOUND_ERR); });
- },
-
- write:function(win,fail,args) {
- var fileName = args[0];
- var text = args[1];
- var position = args[2];
-
- Windows.Storage.StorageFile.getFileFromPathAsync(fileName).done(
- function (storageFile) {
- Windows.Storage.FileIO.writeTextAsync(storageFile,text,Windows.Storage.Streams.UnicodeEncoding.utf8).done(
- function() {
- win(String(text).length);
- }, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
- }, function() {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- },
-
- truncate:function(win,fail,args) { // ["fileName","size"]
- var fileName = args[0];
- var size = args[1];
-
- Windows.Storage.StorageFile.getFileFromPathAsync(fileName).done(function(storageFile){
- //the current length of the file.
- var leng = 0;
-
- storageFile.getBasicPropertiesAsync().then(function (basicProperties) {
- leng = basicProperties.size;
- if (Number(size) >= leng) {
- win(this.length);
- return;
- }
- if (Number(size) >= 0) {
- Windows.Storage.FileIO.readTextAsync(storageFile, Windows.Storage.Streams.UnicodeEncoding.utf8).then(function (fileContent) {
- fileContent = fileContent.substr(0, size);
- var fullPath = storageFile.path;
- var name = storageFile.name;
- var entry = new Entry(true, false, name, fullPath);
- var parentPath = "";
- var successCallBack = function (entry) {
- parentPath = entry.fullPath;
- storageFile.deleteAsync().then(function () {
- return Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath);
- }).then(function (storageFolder) {
- storageFolder.createFileAsync(name).then(function (newStorageFile) {
- Windows.Storage.FileIO.writeTextAsync(newStorageFile, fileContent).done(function () {
- win(String(fileContent).length);
- }, function () {
- fail && fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
- });
- });
- });
- };
- entry.getParent(successCallBack, null);
- }, function () { fail && fail(FileError.NOT_FOUND_ERR); });
- }
- });
- }, function () { fail && fail(FileError.NOT_FOUND_ERR); });
- },
-
- copyTo:function(success,fail,args) { // ["fullPath","parent", "newName"]
- var srcPath = args[0];
- var parentFullPath = args[1];
- var name = args[2];
-
- //name can't be invalid
- if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(name)) {
- fail && fail(FileError.ENCODING_ERR);
- return;
- }
- // copy
- var copyFiles = "";
- Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(
- function (sFile) {
- copyFiles = function (srcPath, parentPath) {
- var storageFileTop = null;
- Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(function (storageFile) {
- storageFileTop = storageFile;
- return Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath);
- }, function () {
-
- fail && fail(FileError.NOT_FOUND_ERR);
- }).then(function (storageFolder) {
- storageFileTop.copyAsync(storageFolder, name, Windows.Storage.NameCollisionOption.failIfExists).then(function (storageFile) {
-
- success(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
-
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- });
- }, function () {
-
- fail && fail(FileError.NOT_FOUND_ERR);
- });
- };
- var copyFinish = function (srcPath, parentPath) {
- copyFiles(srcPath, parentPath);
- };
- copyFinish(srcPath, parentFullPath);
- },
- function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(
- function (sFolder) {
- copyFiles = function (srcPath, parentPath) {
- var coreCopy = function (storageFolderTop, complete) {
- storageFolderTop.createFolderQuery().getFoldersAsync().then(function (folderList) {
- var folderPromiseArr = [];
- if (folderList.length === 0) { complete(); }
- else {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function (storageFolderTarget) {
- var tempPromiseArr = [];
- var index = 0;
- for (var j = 0; j < folderList.length; j++) {
- tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function (targetFolder) {
- folderPromiseArr.push(copyFiles(folderList[j].path, targetFolder.path));
- });
- }
- WinJS.Promise.join(tempPromiseArr).then(function () {
- WinJS.Promise.join(folderPromiseArr).then(complete);
- });
- });
- }
- });
- };
-
- return new WinJS.Promise(function (complete) {
- var storageFolderTop = null;
- var filePromiseArr = [];
- var fileListTop = null;
- Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function (storageFolder) {
- storageFolderTop = storageFolder;
- return storageFolder.createFileQuery().getFilesAsync();
- }).then(function (fileList) {
- fileListTop = fileList;
- if (fileList) {
- return Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath);
- }
- }).then(function (targetStorageFolder) {
- for (var i = 0; i < fileListTop.length; i++) {
- filePromiseArr.push(fileListTop[i].copyAsync(targetStorageFolder));
- }
- WinJS.Promise.join(filePromiseArr).then(function () {
- coreCopy(storageFolderTop, complete);
- });
- });
- });
- };
- var copyFinish = function (srcPath, parentPath) {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function (storageFolder) {
- storageFolder.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists).then(function (newStorageFolder) {
- //can't copy onto itself
- if (srcPath == newStorageFolder.path) {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- return;
- }
- //can't copy into itself
- if (srcPath == parentPath) {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- return;
- }
- copyFiles(srcPath, newStorageFolder.path).then(function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(newStorageFolder.path).done(
- function (storageFolder) {
- success(new DirectoryEntry(storageFolder.name, storageFolder.path));
- },
- function () { fail && fail(FileError.NOT_FOUND_ERR); }
- );
- });
- }, function () { fail && fail(FileError.INVALID_MODIFICATION_ERR); });
- }, function () { fail && fail(FileError.INVALID_MODIFICATION_ERR); });
- };
- copyFinish(srcPath, parentFullPath);
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- }
- );
- },
-
- moveTo:function(success,fail,args) {
- var srcPath = args[0];
- var parentFullPath = args[1];
- var name = args[2];
-
-
- //name can't be invalid
- if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(name)) {
- fail && fail(FileError.ENCODING_ERR);
- return;
- }
-
- var moveFiles = "";
- Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(
- function (sFile) {
- moveFiles = function (srcPath, parentPath) {
- var storageFileTop = null;
- Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(function (storageFile) {
- storageFileTop = storageFile;
- return Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath);
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }).then(function (storageFolder) {
- storageFileTop.moveAsync(storageFolder, name, Windows.Storage.NameCollisionOption.replaceExisting).then(function () {
- success(new FileEntry(name, storageFileTop.path));
- }, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- });
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- });
- };
- var moveFinish = function (srcPath, parentPath) {
- //can't copy onto itself
- if (srcPath == parentPath + "\\" + name) {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- return;
- }
- moveFiles(srcPath, parentFullPath);
- };
- moveFinish(srcPath, parentFullPath);
- },
- function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(
- function (sFolder) {
- moveFiles = function (srcPath, parentPath) {
- var coreMove = function (storageFolderTop, complete) {
- storageFolderTop.createFolderQuery().getFoldersAsync().then(function (folderList) {
- var folderPromiseArr = [];
- if (folderList.length === 0) {
- // If failed, we must cancel the deletion of folders & files.So here wo can't delete the folder.
- complete();
- }
- else {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function (storageFolderTarget) {
- var tempPromiseArr = [];
- var index = 0;
- for (var j = 0; j < folderList.length; j++) {
- tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function (targetFolder) {
- folderPromiseArr.push(moveFiles(folderList[j].path, targetFolder.path));
- });
- }
- WinJS.Promise.join(tempPromiseArr).then(function () {
- WinJS.Promise.join(folderPromiseArr).then(complete);
- });
- });
- }
- });
- };
- return new WinJS.Promise(function (complete) {
- var storageFolderTop = null;
- Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function (storageFolder) {
- storageFolderTop = storageFolder;
- return storageFolder.createFileQuery().getFilesAsync();
- }).then(function (fileList) {
- var filePromiseArr = [];
- Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function (dstStorageFolder) {
- if (fileList) {
- for (var i = 0; i < fileList.length; i++) {
- filePromiseArr.push(fileList[i].moveAsync(dstStorageFolder));
- }
- }
- WinJS.Promise.join(filePromiseArr).then(function () {
- coreMove(storageFolderTop, complete);
- }, function () { });
- });
- });
- });
- };
- var moveFinish = function (srcPath, parentPath) {
- var originFolderTop = null;
- Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function (originFolder) {
- originFolderTop = originFolder;
- return Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath);
- }, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- }).then(function (storageFolder) {
- return storageFolder.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists);
- }, function () {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- }).then(function (newStorageFolder) {
- //can't move onto directory that is not empty
- newStorageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
- newStorageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
- if (fileList.length !== 0 || folderList.length !== 0) {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- return;
- }
- //can't copy onto itself
- if (srcPath == newStorageFolder.path) {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- return;
- }
- //can't copy into itself
- if (srcPath == parentPath) {
- fail && fail(FileError.INVALID_MODIFICATION_ERR);
- return;
- }
- moveFiles(srcPath, newStorageFolder.path).then(function () {
- var successCallback = function () {
- success(new DirectoryEntry(name, newStorageFolder.path));
- };
- var temp = new DirectoryEntry(originFolderTop.name, originFolderTop.path).removeRecursively(successCallback, fail);
-
- }, function () { console.log("error!"); });
- });
- });
- }, function () { fail && fail(FileError.INVALID_MODIFICATION_ERR); });
-
- };
- moveFinish(srcPath, parentFullPath);
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- }
- );
- },
- tempFileSystem:null,
-
- persistentFileSystem:null,
-
- requestFileSystem:function(win,fail,args) {
- var type = args[0];
- var size = args[1];
-
- var filePath = "";
- var result = null;
- var fsTypeName = "";
-
- switch (type) {
- case LocalFileSystem.TEMPORARY:
- filePath = Windows.Storage.ApplicationData.current.temporaryFolder.path;
- fsTypeName = "temporary";
- break;
- case LocalFileSystem.PERSISTENT:
- filePath = Windows.Storage.ApplicationData.current.localFolder.path;
- fsTypeName = "persistent";
- break;
- }
-
- var MAX_SIZE = 10000000000;
- if (size > MAX_SIZE) {
- fail && fail(FileError.QUOTA_EXCEEDED_ERR);
- return;
- }
-
- var fileSystem = new FileSystem(fsTypeName, new DirectoryEntry(fsTypeName, filePath));
- result = fileSystem;
- win(result);
- },
-
- resolveLocalFileSystemURI:function(success,fail,args) {
- var uri = args[0];
-
- var path = uri;
-
- // support for file name with parameters
- if (/\?/g.test(path)) {
- path = String(path).split("?")[0];
- }
-
- // support for encodeURI
- if (/\%5/g.test(path)) {
- path = decodeURI(path);
- }
-
- // support for special path start with file:///
- if (path.substr(0, 8) == "file:///") {
- path = Windows.Storage.ApplicationData.current.localFolder.path + "\\" + String(path).substr(8).split("/").join("\\");
- Windows.Storage.StorageFile.getFileFromPathAsync(path).then(
- function (storageFile) {
- success(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(
- function (storageFolder) {
- success(new DirectoryEntry(storageFolder.name, storageFolder.path));
- }, function () {
- fail && fail(FileError.NOT_FOUND_ERR);
- }
- );
- }
- );
- } else {
- Windows.Storage.StorageFile.getFileFromPathAsync(path).then(
- function (storageFile) {
- success(new FileEntry(storageFile.name, storageFile.path));
- }, function () {
- Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(
- function (storageFolder) {
- success(new DirectoryEntry(storageFolder.name, storageFolder.path));
- }, function () {
- fail && fail(FileError.ENCODING_ERR);
- }
- );
- }
- );
- }
- }
-
-};
-
-require("cordova/commandProxy").add("File",module.exports);