示例#1
0
        private static int RunCommand(InfoOption opts)
        {
            using (MediaDevice device = MediaDevice.GetDevices().FirstOrDefault(opts))
            {
                if (device != null)
                {
                    Console.WriteLine($"Device Friendly Name is {device.FriendlyName}");
                    Console.WriteLine($"Device Manufacturer is {device.Manufacturer}");
                    device.Connect();
                    Console.WriteLine($"Device Serial Number is {device.SerialNumber}");
                    var root = device.GetRootDirectory();
                    Console.WriteLine($"Root Directory is {root.FullName}");

                    Console.WriteLine("Drives:");
                    foreach (var drv in device.GetDrives())
                    {
                        Console.WriteLine($"{drv.DriveType} \"{drv.RootDirectory.FullName}\" free {Extensions.SizeSuffix(drv.AvailableFreeSpace)} of {Extensions.SizeSuffix(drv.TotalSize)}");
                    }


                    foreach (var item in device.GetContentLocations(ContentType.Certificate))
                    {
                        Console.WriteLine(item);
                    }

                    device.Disconnect();
                }
                else
                {
                    Console.WriteLine("No device connected.");
                    return(1);
                }
            }
            return(0);
        }
示例#2
0
        private static int RunCommand(DirOption opts)
        {
            using (MediaDevice device = MediaDevice.GetDevices().FirstOrDefault(opts))
            {
                if (device != null)
                {
                    Console.WriteLine($"Device Friendly Name is {device.FriendlyName}");
                    Console.WriteLine($"Device Manufacturer is {device.Manufacturer}");
                    device.Connect();
                    Console.WriteLine($"Device Serial Number is {device.SerialNumber}");
                    Console.WriteLine();
                    int   fils = 0;
                    int   dirs = 0;
                    ulong size = 0;
                    try
                    {
                        foreach (var item in device.EnumerateDirectories(opts.Path))
                        {
                            dirs++;
                            var info = device.GetDirectoryInfo(item);
                            Console.WriteLine($"{info.LastWriteTime:g}   <DIR>         {info.Name}");
                        }

                        foreach (var item in device.EnumerateFiles(opts.Path))
                        {
                            fils++;
                            var info = device.GetFileInfo(item);
                            size += info.Length;
                            Console.WriteLine($"{info.LastWriteTime:g} {info.Length,15:N0} {info.Name}");
                        }

                        Console.WriteLine($"{fils,3} File(s)  {size:N0} Bytes");
                        Console.WriteLine($"{dirs,3} Dir(s)");
                    }
                    catch (System.IO.DirectoryNotFoundException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    device.Disconnect();
                }
                else
                {
                    Console.WriteLine("No device connected.");
                    return(1);
                }
            }
            return(0);
        }
示例#3
0
 private static int RunCommand(GetOption opts)
 {
     using (MediaDevice device = MediaDevice.GetDevices().FirstOrDefault(opts))
     {
         if (device != null)
         {
             device.Connect();
             device.DownloadFile(opts.Source, opts.Destination);
             device.Disconnect();
         }
         else
         {
             Console.WriteLine("No device connected.");
             return(1);
         }
     }
     return(0);
 }
示例#4
0
 private void Button2_Click(object sender, EventArgs e)
 {
     if (Device == null)
     {
         Device = Devices.ElementAt(comboBox1.SelectedIndex);
         Device.Connect();
         Device.DeviceRemoved += Device_DeviceRemoved;
         button2.Text          = "Disconnect";
         Drives = Device.GetDrives();
         foreach (MediaDriveInfo d in Drives)
         {
             comboBox2.Items.Add(d.VolumeLabel);
         }
     }
     else if (Device.IsConnected)
     {
         Device.Disconnect();
         Device       = null;
         button2.Text = "Connect";
         Drive        = null;
         Drives       = null;
         comboBox2.Items.Clear();
     }
     else
     {
         Device = Devices.ElementAt(comboBox1.SelectedIndex);
         Device.Connect();
         Device.DeviceRemoved += Device_DeviceRemoved;
         button2.Text          = "Disconnect";
         Drives = Device.GetDrives();
         if (Drives == null)
         {
             return;
         }
         if (Drives.Length == 0)
         {
             return;
         }
         foreach (MediaDriveInfo d in Drives)
         {
             comboBox2.Items.Add(d.VolumeLabel);
         }
     }
 }
示例#5
0
 private static int RunCommand(PutOption opts)
 {
     using (MediaDevice device = MediaDevice.GetDevices().FirstOrDefault(opts))
     {
         if (device != null)
         {
             device.Connect();
             string destDir = Path.GetDirectoryName(opts.Destination);
             if (!device.DirectoryExists(destDir))
             {
                 device.CreateDirectory(destDir);
             }
             device.UploadFile(opts.Source, opts.Destination);
             device.Disconnect();
         }
         else
         {
             Console.WriteLine("No device connected.");
             return(1);
         }
     }
     return(0);
 }
示例#6
0
 public void Disconnect()
 {
     _connectedDevice?.Disconnect();
     _connectedDevice = null;
 }
示例#7
0
 public void Close()
 {
     device.Disconnect();
     device.Dispose();
 }