[英]Using cordova-plugin-file to copy SQLite database cordova-sqlite-storage in Windows 10
I need some help with cordova-plugin-file to backup a database used by cordova-sqlite-storage in Windows 10 App. 我需要关于cordova-plugin-file的帮助,以备份Windows 10 App中cordova-sqlite-storage使用的数据库。 My Code works fine on Android platform.
我的代码可以在Android平台上正常运行。 Database can be copied in both directions (backup and restore).
可以双向复制数据库(备份和还原)。 Database used by the App seems to be the following:
该应用程序使用的数据库似乎如下:
C:\\Users\\myuser\\AppData\\Local\\Packages\\io.cordova.hellocordova_h35559jr9hy9m\\LocalState\\sample.db C:\\ Users \\ myuser \\ AppData \\ Local \\ Packages \\ io.cordova.hellocordova_h35559jr9hy9m \\ LocalState \\ sample.db
The App tries to use this Location to locate the file, but it's not found: 该应用程序尝试使用此位置来定位文件,但未找到:
ms-appx:///databases/sample.db ms-appx:///databases/sample.db
How do I get the right location for Windows to copy the file? 如何获得Windows复制文件的正确位置?
This is the Code I use to copy the file: 这是我用来复制文件的代码:
backupDatabase(name: string): Promise { backupDatabase(name:string):承诺{
return new Promise<boolean>((resolve, reject) =>
{
var fileName: string = window.cordova.file.applicationStorageDirectory + 'databases/' + name;
var directoryName: string = window.cordova.file.externalRootDirectory;
window.resolveLocalFileSystemURL(fileName, (file: FileEntry) => {
console.log('[!] Database exists: ' + fileName);
console.log('[!] Storage: ' + directoryName);
window.resolveLocalFileSystemURL(directoryName, (directory: DirectoryEntry) => {
console.log('[!] Directory: ' + directory.toURL());
directory.getDirectory("Backup", {create: true, exclusive: false}, (directoryBackup: DirectoryEntry) => {
console.log('[!] Directory: ' + directoryBackup.toURL());
file.copyTo(directoryBackup, name, (copiedFile: Entry) => {
console.log('[!] Copy success');
resolve(true);
}, (error: FileError) => {
console.log('[!] Copy failed: ' + error.code);
reject(error);
});
}, (error: FileError) => {
console.log('[!] Backup Directory not found: ' + directoryName + 'Backup' + ' errorcode: ' + + error.code);
reject(error);
})
}, (error: FileError) => {
console.log('[!] Directory not found: ' + directoryName + ' errorcode: ' + + error.code);
reject(error);
});
}, (error: FileError) => {
console.log('[!] Database not found: ' + fileName + ' errorcode: ' + + error.code);
reject(error);
});
});
The App tries to use this Location to locate the file, but it's not found:
该应用程序尝试使用此位置来定位文件,但未找到:
ms-appx:///databases/sample.db
ms-appx:///databases/sample.db
How do I get the right location for Windows to copy the file?
如何获得Windows复制文件的正确位置?
Your are using the wrong scheme ms-appx:///
refers to the package installed location . 您使用错误的方案
ms-appx:///
指向软件包的安装位置 。
For C:\\Users\\myuser\\AppData\\Local\\Packages\\io.cordova.hellocordova_h35559jr9hy9m\\LocalState\\sample.db
对于
C:\\Users\\myuser\\AppData\\Local\\Packages\\io.cordova.hellocordova_h35559jr9hy9m\\LocalState\\sample.db
you need to use ms-appdata:///local/sample.db
. 您需要使用
ms-appdata:///local/sample.db
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.