예제 #1
0
        private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e = new DrawItemEventArgs(e.Graphics,
                                          e.Font,
                                          e.Bounds,
                                          e.Index,
                                          e.State ^ DrawItemState.Selected,
                                          e.ForeColor,
                                          Color.Yellow);//Choose the color
            }
            // Draw the background of the ListBox control for each item.
            e.DrawBackground();

            Brush myBrush = Brushes.Black;

            PatchSet ps = lstFeatures.Items[e.Index] as PatchSet;

            if (ps != null)
            {
                if (ps.Enabled)
                {
                    myBrush = Brushes.Blue;
                }

                e.Graphics.DrawString(string.Format("{0} {1}", ps.Enabled?"*":" ", ps.Name),
                                      e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
            }
            e.DrawFocusRectangle();
        }
예제 #2
0
        private void PatchFileButton_Click(object sender, EventArgs e)
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Title = "Select Nikon firmware .bin file to patch";

            // Set filter options and filter index.
            openFileDialog1.Filter      = "Binary Files (.bin)|*.bin|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = false;

            // Call the ShowDialog method to show the dialog box.
            var userClickedOK = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == DialogResult.OK)
            {
                //SendEvent("TryFile", openFileDialog1.File.Name);

                var ext = Path.GetExtension(openFileDialog1.FileName).ToLower();
                if (ext == ".dmg")
                {
                    MessageBox.Show("Please open the DMG file and select the .BIN file inside");
                    return;
                }
                if (ext == ".exe")
                {
                    MessageBox.Show("Please open the .EXE file and select the .BIN file inside");
                    return;
                }
                if (ext != ".bin")
                {
                    MessageBox.Show("The files to be a Nikon Firmware .BIN file");
                    return;
                }

                Clear();

                // Open the selected file to read.
                System.IO.Stream fileStream = File.OpenRead(openFileDialog1.FileName);

                //SendEvent("OpenFile", openFileDialog1.File.Name);

                if (fileStream.Length > (48 * 1024 * 1024))
                {
                    fileStream.Close();
                    return;
                }

                byte[] data = new byte[fileStream.Length];

                if (data == null)
                {
                    fileStream.Close();
                    return;
                }

                fileStream.Read(data, 0, (int)fileStream.Length);
                fileStream.Close();

                // Test in valid
                firm = PatchControl.FirmwareMatch(data, PatchLevel.DevOnly);

                if (firm != null)
                {
                    tFirmwareName.Text    = firm.Model;
                    tFirmwareVersion.Text = firm.Version;
                    firm.ModelVersion     = $"{firm.Model}_{firm.Version}";

                    if (firm.Patches.Count == 0)
                    {
                        tFeature.Text = "No Patches presently exist for this 'Model/Firmware Version'";
                    }
                    else
                    {
                        var text = firm.TestPatch();
                        if (text == "")
                        {
                            lstFeatures.DataSource    = firm.Patches;
                            lstFeatures.DisplayMember = "DispalyString";
                            PatchSet.SetListBox(lstFeatures);
                            tFeature.Text = "";
                        }
                        else
                        {
                            // hash matched, but patches did not match
                            tFeature.Text = "A sub-patch failed to map to this 'Model/Firmware Version' - Please Report " + text;
                        }
                    }

                    foreach (var p in firm.Patches)
                    {
                        p.PropertyChanged += PatchSetChanged;
                    }
                }
                else
                {
                    tFeature.Text = "No matching 'Model/Firmware Versions' were found";
                }
            }
        }