Beispiel #1
0
        /// <summary>
        /// Fixes all Invalid Markers found in the specified core
        /// </summary>
        private void FixCore()
        {
            if (_invalidMarkerTable.Rows.Count > 0)
            {
                bool   FixIsPresent = false;
                string OldMessage   = StatusLabel.Text;

                FileStream CoreStream = null;
                try
                {
                    StatusLabel.Text = "Fixing Core...";
                    // Open CoreFile
                    CoreStream = File.Open(CoreFileTextBox.Text, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
                    // Loop through Markers
                    foreach (DataRow Row in _invalidMarkerTable.Rows)
                    {
                        // Skip unchecked markers
                        if ((bool)Row["Fix"] == false)
                        {
                            continue;
                        }

                        FixIsPresent = true;

                        long   Address  = (long)Row["Address"];
                        byte[] Data     = null;
                        object Expected = Row["ExpectedValue"];

                        // Grab the bytes of the expected value
                        if (Expected is byte)
                        {
                            Data = new byte[1] {
                                (byte)Expected
                            };
                        }
                        else if (Expected is short)
                        {
                            Data = ByteConversion.ToBytes((short)Expected);
                        }
                        else if (Expected is ushort)
                        {
                            Data = ByteConversion.ToBytes((ushort)Expected);
                        }
                        else if (Expected is int)
                        {
                            Data = ByteConversion.ToBytes((int)Expected);
                        }
                        else if (Expected is uint)
                        {
                            Data = ByteConversion.ToBytes((uint)Expected);
                        }
                        else if (Expected is long)
                        {
                            Data = ByteConversion.ToBytes((long)Expected);
                        }

                        // Seek to Address
                        CoreStream.Seek(Address, SeekOrigin.Begin);

                        // Write value
                        CoreStream.Write(Data, 0, Data.Length);
                    }
                    if (FixIsPresent)
                    {
                        StatusLabel.Text = "Core fixing complete";
                        MessageBox.Show(this, "All selected Invalid Markers have been corrected", "IGC Core Validator", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ClearForm();
                    }
                    else
                    {
                        StatusLabel.Text = OldMessage;
                        MessageBox.Show(this, "There is nothing to fix! Please check markers to fix", "IGC Core Validator", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception e)
                {
                    StatusLabel.Text = "Error fixing core!";
                    MessageBox.Show("Error fixing core!\r\n" + e.Message, "IGCCore Validator", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    // Close CoreFile
                    if (CoreStream != null)
                    {
                        CoreStream.Close();
                    }
                }
            }
        }