如何从 phone 下载文件? MediaDevices device.DownloadFile() 方法抛出一个 Not Implmented 异常

How can I download a file from my phone? MediaDevices device.DownloadFile() method throws a Not Implmented exception

我正在尝试使用 MediaDevices 库从我的 phone 下载文件。我能够在我的 phone 上看到文件,但是 MediaDevice.DownloadFile() 抛出 NotImplemented 异常。我有图书馆的 1.8.0 版。这是我的程序:

using System;
using System.Diagnostics;
using System.IO;
using MediaDevices;

namespace ReadPhoneFile
{
    class Program
    {
        static MediaDevice thePhone;
        
        static void Main(string[] args)
        {
            var devices = MediaDevice.GetDevices();
            foreach (MediaDevice device in devices)
            {
                try
                {
                    thePhone = device;
                    device.Connect();
                    DownloadFiles(device, "e:/pictures/Rob's Test Phone/Lightroom");
                    device.Disconnect();
                }
                catch
                {
                    // If it can't be read, don't worry.
                }
            }
            Console.WriteLine("Press any key.");
            Console.ReadKey();
        }

        static void DownloadFiles(MediaDevice device, string pcFolder)
        {
            var lightroomDir = device.GetDirectoryInfo(@"Phone\Android\data\com.adobe.lrmobile\files\carouselDocuments\a6f0275ee0b94c90b3c05f093250d4ef\Originals");
            // ProcessLightroomFolder(photoDir, pcFolder, false);
            foreach (MediaDirectoryInfo subFolder in lightroomDir.EnumerateDirectories())
            {
                ProcessLightroomFolder(subFolder, pcFolder, true);
            }
        }

        static void ProcessLightroomFolder(MediaDirectoryInfo folder, string pcFolder, bool createFolder)
        {
            Console.WriteLine($"Processing folder {folder.Name} into folder {pcFolder}");
            string pcSubFolder = $"{pcFolder}/{folder.Name}";
            if (createFolder)
            {
                Directory.CreateDirectory(pcSubFolder);
            }
            foreach (MediaFileInfo file in folder.EnumerateFiles())
            {
                ProcessLightroomFile(file, pcSubFolder);
            }
            foreach (MediaDirectoryInfo subFolder in folder.EnumerateDirectories())
            {
                ProcessLightroomFolder(subFolder, pcSubFolder, true);
            }
        }

        static void ProcessLightroomFile(MediaFileInfo file, string pcFolder)
        {
            Console.WriteLine($"Processing Lightroom file {file.Name} into folder {pcFolder}");
            DownloadFile(file, pcFolder);
        }

        static void DownloadFile(MediaFileInfo phoneFile, string destinationFolder)
        {
            try
            {
                MemoryStream memoryStream = new System.IO.MemoryStream();
                thePhone.DownloadFile(phoneFile.FullName, "c:/misc/downloadedFile.dng");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

github 上提出了一个问题来解决这个问题 (https://github.com/Bassman2/MediaDevices/issues/32)。问题是您是在 .NET Core 3.1 之上构建您的应用程序,并且此库在 .NET Framework 4 上运行良好。* 因为它们在您构建项目时发出警告:

Package 'MediaDevices 1.8.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project