使用 cordova-plugin-file 复制 SQLite 数据库 cordova-sqlite-storage in Windows 10

Using cordova-plugin-file to copy SQLite database cordova-sqlite-storage in Windows 10

我需要一些有关 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 复制文件的正确位置?

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

backupDatabase(名称:字符串):承诺 {

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

How do I get the right location for Windows to copy the file?

您使用了错误的方案ms-appx:///指的是package installed location

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

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