Exemplo n.º 1
0
        static public string BuildPatchMatrix()
        {
            StringBuilder sb    = new StringBuilder();
            string        alpha = "ALPHA";
            string        beta  = "BETA";

            foreach (var hm in hashMap)
            {
                Firmware f = hm.Value;
                sb.AppendFormat("<li>{0} {1}<ul>\n", f.Model, f.Version);
                foreach (var p in f.Patches)
                {
                    switch (p.PatchStatus)
                    {
                    case PatchLevel.Alpha:
                        sb.AppendFormat("<li>{1} - {0}</li>\n", p.Name, alpha); break;

                    case PatchLevel.Beta:
                        sb.AppendFormat("<li>{1} - {0}</li>\n", p.Name, beta); break;

                    case PatchLevel.Released:
                        sb.AppendFormat("<li>{0}</li>\n", p.Name); break;
                    }
                }
                sb.AppendFormat("</ul></li>\n");
            }

            //Debug.WriteLine(sb.ToString());
            return(sb.ToString());
        }
Exemplo n.º 2
0
        static public Firmware FirmwareMatch(byte[] data, PatchLevel allowLevel)
        {
            var hash = MD5Core.GetHash(data);

//#if DEBUG
            string s = "";

            foreach (byte b in hash)
            {
                s += string.Format("0x{0:X2}, ", b);
            }
            System.Diagnostics.Debug.WriteLine(s);
//#endif

            Firmware firm = null;

            foreach (var h in hashMap)
            {
                if (HashSame(h.Key, hash))
                {
                    firm = h.Value;
                    break;
                }
            }

            if (firm != null)
            {
                int i = 0;
                do
                {
                    for (i = 0; i < firm.Patches.Count; i++)
                    {
                        if (firm.Patches[i].PatchStatus < allowLevel)
                        {
                            firm.Patches.RemoveAt(i);
                            break;
                        }
                    }
                } while (i < firm.Patches.Count);

                firm.LoadData(data);
            }

            return(firm);
        }
Exemplo n.º 3
0
        private void bOpenFileDialog_Click(object sender, RoutedEventArgs e)
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // 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.
            bool? userClickedOK = openFileDialog1.ShowDialog();

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

                var ext = openFileDialog1.File.Extension.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 = openFileDialog1.File.OpenRead();

                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, App.AllowedPatchLevel);

                if (firm != null)
                {
                    tFirmwareName.Text = firm.Model;
                    tFirmwareVersion.Text = firm.Version;
                    firm.ModelVersion = string.Format("{0}_{1}", 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.ItemsSource = firm.Patches;
                            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";
                }
            }
        }
Exemplo n.º 4
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";
                }
            }
        }