static void Main() { var devices = new PortableDeviceCollection(); devices.Refresh(); var kindle = devices.First(); kindle.Connect(); var root = kindle.GetContents(); foreach (var resource in root.Files) { DisplayResourceContents(resource); } PortableDeviceFolder documents = (from r in ((PortableDeviceFolder)root.Files[0]).Files where r.Name.Contains("documents") select r).First() as PortableDeviceFolder; var books = from b in documents.Files where b.Name.Contains("Kindle_Users_Guide") select b; foreach (PortableDeviceFile book in books) { Console.WriteLine(book.Id); kindle.DeleteFile(book); } kindle.Disconnect(); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
// public static string STORAGE_ES = "Almacenamiento interno compartido"; public static PortableDevice getCurrentDevice() { PortableDevice currentDevice = null; try { var devices = new PortableDeviceCollection(); //if (null == devices) //{ //} //else //{ devices.Refresh(); currentDevice = devices.First(); /*if (null == currentDevice) * { * Console.Error.WriteLine("Dispositivo no encontrado!"); * } * else * { * Console.WriteLine("Dispositivo encontrado: " + currentDevice.FriendlyName); * }*/ //} } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } return(currentDevice); }
public static void TransferFilesFromWpdToHardDrive(string path) { _copyPath = path; var collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var device in collection) { device.Connect(); var folder = device.GetContents(); var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("camera") || x.Name.ToLower().Equals("tablet")); if (item == null) { continue; } NavigateObject(device, item); device.Disconnect(); } }
private void SetupDevice() { var devices = new PortableDeviceCollection(); devices.Refresh(); this.Device = devices.First(); }
public static void ConnectDevice() { var devices = new PortableDeviceCollection(); devices.Refresh(); gopro = devices.First(); gopro.Connect(); currentDeviceId = gopro.DeviceId; }
static void Main() { //Connect to MTP devices and pick up the first one var devices = new PortableDeviceCollection(); devices.Refresh(); Tablet = devices.First(); Tablet.Connect(); //Getting root directory var root = Tablet.GetContents(); //Displayinh directory content in console foreach (var resource in root.Files) { DisplayResourceContents(resource); } //Finding neccessary folder inside the root var folder = (root.Files.FirstOrDefault() as PortableDeviceFolder). Files.FirstOrDefault(x => x.Name == "Folder") as PortableDeviceFolder; //Finding file inside the folder var file = (folder as PortableDeviceFolder)?.Files?.FirstOrDefault(x => x.Name == "File"); //Transfering file into byte array var fileIntoByteArr = Tablet.DownloadFileToStream(file as PortableDeviceFile); //Transfering file into file system Tablet.DownloadFile(file as PortableDeviceFile, "\\LOCALPATH"); //Transfering file rom file system into device folder Tablet.TransferContentToDevice("\\LOCALPATH", folder.Id); //Transfering file from stream into device folder var imgPath = "\\LOCALPATH"; var image = Image.FromFile(imgPath); byte[] imageB; using (var ms = new MemoryStream()) { image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); imageB = ms.ToArray(); } Tablet.TransferContentToDeviceFromStream("FILE NAME", new MemoryStream(imageB), folder.Id); //Close the connection Tablet.Disconnect(); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
/* * Return list of available devices * */ public LinkedList<string> devicesList() { LinkedList<string> devices = new LinkedList<string>(); collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var dev in collection) { dev.Connect(); devices.AddLast(dev.FriendlyName); dev.Disconnect(); } return devices; }
private void RefreshDevicesList() { DevicesListBox.Items.Clear(); collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var device in collection) { device.Connect(); DevicesListBox.Items.Add(device.FriendlyName); device.Disconnect(); } DevicesListBox.Items.Add("Load from disk"); }
void Init() { Devices = new PortableDeviceCollection(); if (null == Devices) { throw new Exception("デバイスを取得できませんでした。"); } else { Devices.Refresh(); Device = Devices.First(); } //devices.Clear(); }
private void connectWithDevice(object state) { if (detected) { return; } detected = true; Console.WriteLine("Device detected"); var devices = new PortableDeviceCollection(); devices.Refresh(); device = devices.First(); device.Connect(); Console.WriteLine("Connected to: " + device.FriendlyName); var root = device.GetContents(); servicePlatformFolder = (PortableDeviceFolder)device.getServicePlatformFolder(); if (servicePlatformFolder == null) { Console.WriteLine("Could not find ServicePlatform folder, have you installed ServicePlatform mobile app? Disconnecting..."); device.Disconnect(); return; } getServicesList(device, servicePlatformFolder); if (!servicesFileDetected) { Console.WriteLine("Could not detect services! Disconnecting..."); device.Disconnect(); return; } BeginInvoke(new MethodInvoker(delegate { Show(); //MessageBox.Show("Connected to: " + device.FriendlyName); })); cleanup(device, servicePlatformFolder); //device.Disconnect(); }
public static (int?, PortableDevice) GetDevice(string deviceId) { var devices = new PortableDeviceCollection(); devices.Refresh(); var deviceCollection = devices.ToList(); var device = deviceCollection.SingleOrDefault(d => string.Equals(deviceId, d.DeviceId, StringComparison.Ordinal)); if (device == null) { Console.WriteLine($"[{nameof(EXIT_CODE_DEVICE_NOT_FOUND)}]"); return(EXIT_CODE_DEVICE_NOT_FOUND, null); } return(null, device); }
/// <summary> /// get all devices connected to computer /// </summary> /// <returns></returns> private IEnumerable <Device> GetConnectedDevices() { if (System.Threading.Thread.CurrentThread.IsBackground) { Utility.LogMessage("[GetConnectedDevices] [IsBackground]"); } var devices = new List <Device>(); try { _connectedDeviceCollection.Clear(); _connectedDeviceCollection.Refresh(); foreach (var connectedDevice in _connectedDeviceCollection) { try { connectedDevice.Connect(); var deviceObj = new Device() { Id = connectedDevice.DeviceId, DisplayName = connectedDevice.FriendlyName, }; if (!devices.Contains(deviceObj)) { devices.Add(deviceObj); } } catch { } finally { connectedDevice.Disconnect(); } } } catch { throw; } return(devices); }
static void Main() { var devices = new PortableDeviceCollection(); devices.Refresh(); var kindle = devices.First(); kindle.Connect(); kindle.TransferContentToDevice( @"d:\temp\Kindle_Users_Guide.azw", @"g:\documents"); kindle.Disconnect(); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
static void Main() { var collection = new PortableDeviceCollection(); collection.Refresh(); foreach(var device in collection) { //Console.WriteLine(device.DeviceId); device.Connect(); Console.WriteLine(device.FriendlyName); device.Disconnect(); } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
public static void DeleteFromWpdToHardDrive() { var collection = new PortableDeviceCollection(); collection.Refresh(); foreach (var device in collection) { device.Connect(); var folder = device.GetContents(); var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("camera")); NavigateObjectForDelete(device, item); device.Disconnect(); } }
/// <summary> /// get all devices connected to computer /// </summary> /// <returns></returns> private IEnumerable <Device> GetConnectedDevices() { var devices = new List <Device>(); try { _connectedDeviceCollection.Clear(); _connectedDeviceCollection.Refresh(); foreach (var connectedDevice in _connectedDeviceCollection) { try { connectedDevice.Connect(); var deviceObj = new Device() { Id = connectedDevice.DeviceId, DisplayName = connectedDevice.FriendlyName, }; if (!devices.Contains(deviceObj)) { devices.Add(deviceObj); } } catch { } finally { connectedDevice.Disconnect(); } } } catch { throw; } return(devices); }
public static int SystemInfoCommand(CommandLineItemCollection commandLine) { PrintCommandName(); var includeFriendlyName = commandLine.HasFlag("friendlyName"); var devices = new PortableDeviceCollection(); devices.Refresh(); Console.WriteLine("[Devices]"); foreach (var device in devices) { string deviceFriendlyName; if (includeFriendlyName) { try { device.Connect(); deviceFriendlyName = device.FriendlyName; } finally { device.Disconnect(); } } else { deviceFriendlyName = "-"; } Console.WriteLine($"{deviceFriendlyName}\t{device.DeviceId}"); } Console.WriteLine($"[{nameof(EXIT_CODE_OK)}]"); return(EXIT_CODE_OK); }
static void Main() { var collection = new PortableDeviceCollection(); collection.Refresh(); foreach(var device in collection) { device.Connect(); Console.WriteLine(device.FriendlyName); var folder = device.GetContents(); foreach(var item in folder.Files) { DisplayObject(item); } device.Disconnect(); } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
//---------------------------------------------------------------------------------------------- private static void OnTimedEvent(object source, ElapsedEventArgs e) { //Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime); readCfg(); if(outputDir == "") { Console.WriteLine("invalid output path, check the cfg file"); return; } var collection = new PortableDeviceCollection(); collection.Refresh(); PortableDevice myCamera = null; // foreach(var device in collection) for (int i = 0; i < collection.Count; i++) { collection[i].Connect(); if (collection[i].FriendlyName == "D5000") { myCamera = collection[i]; break; } collection[i].Disconnect(); } if (myCamera == null) { Console.WriteLine("nothing is connected?"); collection = null; return; } //Console.WriteLine(myCamera.FriendlyName); var folder = myCamera.GetContents(); foreach (var item in folder.Files) { DisplayObject(myCamera, item); } Console.WriteLine("--------------------------"); myCamera.Disconnect(); collection = null; myCamera = null; }
static void Main(string[] args) { var collection = new PortableDeviceCollection(); bool another; int? depth = null; bool folderOnly = false; collection.Refresh(); var device = collection.First(); device.Connect(); do { //Console.Write("Enter depth: "); //if (int.TryParse(Console.ReadLine(), out int depthInt)) // depth = depthInt; //Console.WriteLine(); //Console.Write("Folder Only? (y/n): "); //if (Console.ReadLine().ToLower().Equals("y")) // folderOnly = true; //collection.Refresh(); //foreach (var device in collection) //{ // device.Connect(); // Console.WriteLine("-------------------------\n" + device.FriendlyName + "\n-------------------------"); // DisplayFolderContents(device.GetContents(depth, folderOnly)); // device.DisConnect(); //} //device.TransferToDevice(@"F:\LDPlayer\Garulea Continent.record", "o2"); //var content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\Garulea Continent.record"); var content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\A.txt"); device.DeleteFile(content.Id, true); content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\Q.txt"); device.DeleteFile(content.Id, true); Console.Write("Another? (y/n) "); if (!Console.ReadLine().ToLower().Equals("n")) { another = true; } else { another = false; } } while (another); device.DisConnect(); //var device2 = collection.GetDeviceByName("HM NOTE 1LTEW"); //device2.Connect(); ////Console.WriteLine("Enter folder name and folder parent id"); ////var folder = device2.NewFolder(Console.ReadLine(), Console.ReadLine()); //var folder = device2.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android"); //Console.WriteLine(folder.Id + " ||| " + folder.Name); //device2.DisConnect(); //manager.CreateDirectory(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2"); //Console.WriteLine(manager.Exist(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2").Id); //manager.Delete(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test", true); //Console.WriteLine(manager.Exist(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2")?.Id ?? "NotFound"); Console.ReadKey(true); }