我正在尝试使用 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);
}
}
}
}