0

我正在尝试使用 MediaDevices 库从我的手机下载文件。我可以在手机上看到这些文件,但 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);
            }
        }
    }
}
4

1 回答 1

2

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

使用 '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework, 恢复包 'MediaDevices 1.8.0' Version=v4.7.2, .NETFramework,Version=v4.8' 而不是项目目标框架 '.NETCoreApp,Version=v3.1'。此软件包可能与您的项目不完全兼容

于 2020-11-03T11:09:43.720 回答