static void Main(string[] args)
        {
            EepromChecko();
            return;

            string camid = FindNikonCamera();
            if (camid == "")
            {
                Debug.WriteLine("** Failed to find Nikon Camera");
                Console.WriteLine("Failed to find Nikon Camera");
                return;
            }

            SN = camid.Split('#')[2];

            DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = camid };
            cam = new BaseMTPCamera();
            bool i = cam.Init(descriptor);
            var rep = cam.ExecuteReadDataEx(MTP_OPERATION_GET_DEVICE_INFO);

            if (rep.ErrorCode == ErrorCodes.MTP_OK)
            {
                //DumpTests();

                Dump_Eeprom_LANG_Test1(SN);
              
            }
        }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            DeviceInfo = new XmlDeviceData();
            SelectDevice wnd = new SelectDevice();
            wnd.ShowDialog();
            if (wnd.DialogResult == true && wnd.SelectedDevice != null)
            {
                try
                {
                    SelectedDevice = wnd.SelectedDevice;
                    DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = SelectedDevice.DeviceId};
                    MtpProtocol device = new MtpProtocol(descriptor.WpdId);
                    device.ConnectToDevice("MTPTester", 1, 0);
                    descriptor.StillImageDevice = device;
                    MTPCamera = new BaseMTPCamera();
                    MTPCamera.Init(descriptor);
                    LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x1001));
                    //LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x9108));
     
                    PopulateProperties();
                }
                catch (DeviceException exception)
                {
                    MessageBox.Show("Error getting device information" + exception.Message);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("General error" + exception.Message);
                }
                if (DefaultDeviceInfo != null)
                {
                    foreach (XmlCommandDescriptor command in DeviceInfo.AvaiableCommands)
                    {
                        command.Name = DefaultDeviceInfo.GetCommandName(command.Code);
                    }
                    foreach (XmlEventDescriptor avaiableEvent in DeviceInfo.AvaiableEvents)
                    {
                        avaiableEvent.Name = DefaultDeviceInfo.GetEventName(avaiableEvent.Code);
                    }
                    foreach (XmlPropertyDescriptor property in DeviceInfo.AvaiableProperties)
                    {
                        property.Name = DefaultDeviceInfo.GetPropName(property.Code);
                    }
                }
                InitUi();
            }

        }
 private void btn_get_value_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (MTPCamera == null || MTPCamera.IsConnected == false)
         {
             DeviceInfo = new XmlDeviceData();
             SelectDevice wnd = new SelectDevice();
             wnd.ShowDialog();
             if (wnd.DialogResult == true && wnd.SelectedDevice != null)
             {
                 SelectedDevice = wnd.SelectedDevice;
                 DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = SelectedDevice.DeviceId};
                 MTPCamera = new BaseMTPCamera();
                 MTPCamera.Init(descriptor);
             }
             else
             {
                 return;
             }
         }
         XmlPropertyDescriptor propertyDescriptor = lst_prop.SelectedItem as XmlPropertyDescriptor;
         MTPDataResponse resp = MTPCamera.ExecuteReadDataEx(BaseMTPCamera.CONST_CMD_GetDevicePropValue,
                                                             propertyDescriptor.Code);
         long val = GetValue(resp, 0, GetDataLength(propertyDescriptor.DataType));
         XmlPropertyValue selected = null;
         foreach (XmlPropertyValue xmlPropertyValue in propertyDescriptor.Values)
         {
             if (xmlPropertyValue.Value == val)
                 selected = xmlPropertyValue;
         }
         if(selected!=null)
         {
             lst_values.BeginInit();
             lst_values.SelectedItem = selected;
             lst_values.EndInit();
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error to get value " + exception.Message);
     }
 }
        static void Main(string[] args)
        {
            LogIt("Nikon Flags v1.1");

            string camid = FindNikonCamera();

            if (camid == "")
            {
                LogIt("Failed to find Nikon Camera");
                return;
            }


            SN = camid.Split('#')[2];

            DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = camid };
            cam = new BaseMTPCamera();
            bool i = cam.Init(descriptor);
            var rep = cam.ExecuteReadDataEx(MTP_OPERATION_GET_DEVICE_INFO);

            if (rep.ErrorCode != ErrorCodes.MTP_OK)
            {
                var s = "Failed to initialise";
                LogIt(s);
                return;
            }

            var version = Get_Version_FirmB();
            var model = Get_CameraModel();

            var cam_obj = CameraBase.GetCameraObject(model, version);

            LogIt(model);
            LogIt(version);

            if (cam_obj == null)
            {
                var s = "Camera model/version not recognised, please email: [email protected] with the details";

                LogIt(s);
                return;
            }

            if (cam_obj.DoChecks(cam) == false)
            {
                var s = "Camera model/version checks failed, please email: [email protected] with the details";

                LogIt(s);
                return;
            }

            var flagAddr = cam_obj.GetKnownAddresss(KnownAddressList.Set04Ram);
            var flagLen = cam_obj.GetKnownLenght(KnownAddressList.Set04Ram);

            //var flagAddr = cam_obj.GetKnownAddresss(KnownAddressList.Set26);
            //var flagLen = cam_obj.GetKnownLenght(KnownAddressList.Set26);

            LogIt("");
            LogIt("Flag Opp [Value]");

            LogIt("   Flag - byte between 0 - 0x{0:X} inclusive", flagLen - 1);
            LogIt("   Opp - A and, O or, C clear, D display, Q quit (no flag needed)");
            LogIt("   Value - hex value used in A, O, C operations");
            LogIt(" '0 A 0x01' will apply AND 0x01 with currnet set04ram[0x00]");
            LogIt(" '0x12 O 0x10' will apply OR 0x10 with current set04ram[0x12]");
            LogIt(" '0x11 C 0x01' will apply AND 0xFE (~0x01), aka clear current set04ram[0x11]");
            LogIt(" '15 D' will display current set04ram[0x15]");
           
            uint offset = 0;
            while (offset < flagLen)
            {
                var line = Console.ReadLine().ToLower().Trim();
                var parts = line.Split(' ');

                if (line == "q") break;

                if (parts.Length < 2) continue;
                var a = parts[0].ToLower().Trim();
                if (a.StartsWith("0x")) a = a.Substring(2);
                if (uint.TryParse(a, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out offset) &&
                    offset < flagLen)
                {
                    var b = parts[1].ToLower().Trim();
                    if (b.Length >= 1)
                    {
                        var opp = b[0];
                        if (opp != 'a' && opp != 'o' && opp != 'c' && opp != 'd')
                        {
                            LogIt("Bad operation character.");
                            break;
                        }

                        byte value = 0;
                        if (opp == 'a' || opp == 'o' || opp == 'c')
                        {
                            if (parts.Length != 3)
                            {
                                LogIt("Value missing");
                                continue;
                            }

                            var c = parts[2].ToLower().Trim();
                            if (c.StartsWith("0x")) c = c.Substring(2);

                            if (byte.TryParse(c, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value) == false)
                            {
                                LogIt("Bad value input");
                                continue;
                            }
                        }

                        var data = cam_obj.ReadBytes(cam, flagAddr + offset, 1);

                        if (data.Length != 1)
                        {
                            LogIt("Bad data read.");
                            break;
                        }

                        if (opp == 'd')
                        {
                            LogIt("Set04ram[0x{0:X}] = 0x{1:X}", offset, data[0]);
                            continue;
                        }

                        if (opp == 'a')
                            data[0] &= value;

                        if (opp == 'o')
                            data[0] |= value;

                        if (opp == 'c')
                            data[0] &= (byte)(~value);

                        LogIt("write: Set04ram[0x{0:X}] = 0x{1:X}", offset, data[0]);
                        cam_obj.WriteBytes(cam, flagAddr + offset, data);

                    }

                }
            }
        }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (MTPCamera == null || MTPCamera.IsConnected == false)
         {
             DeviceInfo = new XmlDeviceData();
             SelectDevice wnd = new SelectDevice();
             wnd.ShowDialog();
             if (wnd.DialogResult == true && wnd.SelectedDevice != null)
             {
                 SelectedDevice = wnd.SelectedDevice;
                 DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = SelectedDevice.DeviceId};
                 MTPCamera = new BaseMTPCamera();
                 MTPCamera.Init(descriptor);
             }
             else
             {
                 return;
             }
         }
         XmlPropertyValue property = lst_values.SelectedItem as XmlPropertyValue;
         XmlPropertyDescriptor propertyDescriptor = lst_prop.SelectedItem as XmlPropertyDescriptor;
         if (property != null)
         {
             MTPCamera.SetProperty(BaseMTPCamera.CONST_CMD_SetDevicePropValue,
                                   BitConverter.GetBytes(property.Value), propertyDescriptor.Code);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error set property " + exception.Message);
     }
 }