0

我需要一些有关cordova-plugin-file 的帮助来备份Windows 10 App 中cordova-sqlite-storage 使用的数据库。我的代码在 Android 平台上运行良好。数据库可以双向复制(备份和恢复)。该应用程序使用的数据库似乎如下:

C:\Users\myuser\AppData\Local\Packages\io.cordova.hellocordova_h35559jr9hy9m\LocalState\sample.db

应用程序尝试使用此位置来定位文件,但未找到:

ms-appx:///databases/sample.db

如何获得 Windows 复制文件的正确位置?

这是我用来复制文件的代码:

备份数据库(名称:字符串):承诺 {

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);
  });
});
4

1 回答 1

0

应用程序尝试使用此位置来定位文件,但未找到:

ms-appx:///databases/sample.db

如何获得 Windows 复制文件的正确位置?

您使用的错误方案ms-appx:///是指包安装位置

为了C:\Users\myuser\AppData\Local\Packages\io.cordova.hellocordova_h35559jr9hy9m\LocalState\sample.db

你需要使用ms-appdata:///local/sample.db.

于 2017-10-10T01:40:17.410 回答