コード例 #1
0
        void DataGridView1RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            dataGridView1.ClearSelection();

            int nRowIndex = dataGridView1.Rows.Count - 1;
            if (nRowIndex > 0) {
                dataGridView1.Rows[nRowIndex].Selected = true;
                dataGridView1.FirstDisplayedScrollingRowIndex = nRowIndex;
            }

            // print the label
            if (checkBox1.Checked) {
                if (((HostCommandStub) PluginContext.HostCommandStub).DoTrackPluginPresetFileFormat) {
                    TrackPresetTextBox.Text = "";
                    byte[] trackedBytes = ((HostCommandStub) PluginContext.HostCommandStub).TrackPluginPresetFileBytes;

                    BinaryFile.ByteOrder bOrder = BinaryFile.ByteOrder.BigEndian;
                    bool invert = false;
                    if (LittleEndianCheckBox.Checked) {
                        bOrder = BinaryFile.ByteOrder.LittleEndian;
                        invert = true;
                    }
                    TrackPresetTextBox.Text = StringUtils.ToHexAndAsciiString(trackedBytes, invert);

                    int i = BinaryFile.ByteArrayToInt32(trackedBytes, bOrder);
                    float f = BinaryFile.ByteArrayToSingle(trackedBytes, bOrder);
                    double d = BinaryFile.ByteArrayToDouble(trackedBytes, bOrder);
                    ValueTextBox.Text = String.Format("int: {0} float: {1:0.####E+000} double: {2:0.0000}", i, f, d);

                    // store these values in a tracking list together with the ParameterDisplay Value
                    string paramName = dataGridView1["ParameterName", nRowIndex].Value.ToString();
                    string paramValue = dataGridView1["ParameterDisplay", nRowIndex].Value.ToString().Trim();
                    InvestigatedPluginPresetFileFormat row = new InvestigatedPluginPresetFileFormat(0, 0, paramName, "", paramValue, String.Format("{0:00.0000}",f));

                    // store this in a xml ouput file.
                    string xmlFilePath = "track-chunk-dump.xml";
                    if (File.Exists(xmlFilePath)) {
                        // add to existing xml document if the entry does not exist from before.
                        XDocument xmlDoc = XDocument.Load(xmlFilePath);

                        var query = from r in xmlDoc.Element("TrackedPresetFileChanges")
                            .Elements("Row")
                            where r.Element("ParameterName").Value == paramName
                            && r.Element("ParameterDisplay").Value == paramValue
                            && Convert.ToSingle(r.Element("FloatValue").Value, CultureInfo.InvariantCulture) == f
                            && Convert.ToInt32(r.Element("IntValue").Value) == i
                            select r;

                        if (query.Count() == 0) {
                            xmlDoc.Element("TrackedPresetFileChanges").Add(
                                new XElement("Row",
                                             new XElement("ParameterName", paramName),
                                             new XElement("ParameterDisplay", paramValue),
                                             new XElement("FloatValue", f),
                                             new XElement("IntValue", i)));

                            xmlDoc.Save(xmlFilePath);
                        }
                    } else {
                        // create xml document first
                        XDocument xmlDoc =
                            new XDocument(
                                new XElement("TrackedPresetFileChanges",
                                             new XElement("Row",
                                                          new XElement("ParameterName", paramName),
                                                          new XElement("ParameterDisplay", paramValue),
                                                          new XElement("FloatValue", f),
                                                          new XElement("IntValue", i))
                                            )
                            );
                        xmlDoc.Save(xmlFilePath);
                    }
                }
            }
        }
        void DataGridView1RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            dataGridView1.ClearSelection();

            int nRowIndex = dataGridView1.Rows.Count - 1;

            if (nRowIndex > 0)
            {
                dataGridView1.Rows[nRowIndex].Selected        = true;
                dataGridView1.FirstDisplayedScrollingRowIndex = nRowIndex;
            }

            // print the label
            if (checkBox1.Checked)
            {
                if (((HostCommandStub)PluginContext.HostCommandStub).DoTrackPluginPresetFileFormat)
                {
                    TrackPresetTextBox.Text = "";
                    byte[] trackedBytes = ((HostCommandStub)PluginContext.HostCommandStub).TrackPluginPresetFileBytes;

                    BinaryFile.ByteOrder bOrder = BinaryFile.ByteOrder.BigEndian;
                    bool invert = false;
                    if (LittleEndianCheckBox.Checked)
                    {
                        bOrder = BinaryFile.ByteOrder.LittleEndian;
                        invert = true;
                    }
                    TrackPresetTextBox.Text = StringUtils.ToHexAndAsciiString(trackedBytes, invert);

                    int    i = BinaryFile.ByteArrayToInt32(trackedBytes, bOrder);
                    float  f = BinaryFile.ByteArrayToSingle(trackedBytes, bOrder);
                    double d = BinaryFile.ByteArrayToDouble(trackedBytes, bOrder);
                    ValueTextBox.Text = String.Format("int: {0} float: {1:0.####E+000} double: {2:0.0000}", i, f, d);

                    // store these values in a tracking list together with the ParameterDisplay Value
                    string paramName  = dataGridView1["ParameterName", nRowIndex].Value.ToString();
                    string paramValue = dataGridView1["ParameterDisplay", nRowIndex].Value.ToString().Trim();
                    var    row        = new InvestigatedPluginPresetFileFormat(0, 0, paramName, "", paramValue, String.Format("{0:00.0000}", f));

                    // store this in a xml ouput file.
                    string xmlFilePath = "track-chunk-dump.xml";
                    if (File.Exists(xmlFilePath))
                    {
                        // add to existing xml document if the entry does not exist from before.
                        XDocument xmlDoc = XDocument.Load(xmlFilePath);

                        var query = from r in xmlDoc.Element("TrackedPresetFileChanges")
                                    .Elements("Row")
                                    where r.Element("ParameterName").Value == paramName &&
                                    r.Element("ParameterDisplay").Value == paramValue &&
                                    Convert.ToSingle(r.Element("FloatValue").Value, CultureInfo.InvariantCulture) == f &&
                                    Convert.ToInt32(r.Element("IntValue").Value) == i
                                    select r;

                        if (query.Count() == 0)
                        {
                            xmlDoc.Element("TrackedPresetFileChanges").Add(
                                new XElement("Row",
                                             new XElement("ParameterName", paramName),
                                             new XElement("ParameterDisplay", paramValue),
                                             new XElement("FloatValue", f),
                                             new XElement("IntValue", i)));

                            xmlDoc.Save(xmlFilePath);
                        }
                    }
                    else
                    {
                        // create xml document first
                        var xmlDoc =
                            new XDocument(
                                new XElement("TrackedPresetFileChanges",
                                             new XElement("Row",
                                                          new XElement("ParameterName", paramName),
                                                          new XElement("ParameterDisplay", paramValue),
                                                          new XElement("FloatValue", f),
                                                          new XElement("IntValue", i))
                                             )
                                );
                        xmlDoc.Save(xmlFilePath);
                    }
                }
            }
        }
コード例 #3
0
        void BtnAutoAllAutomatedClick(object sender, EventArgs e)
        {
            // time how long this takes
            Stopwatch stopwatch = Stopwatch.StartNew();

            string paramDisplay = null;

            var processedParameters = new Dictionary <string, int>();
            int paramCount          = PluginContext.PluginInfo.ParameterCount;

            for (int paramIndex = 0; paramIndex < paramCount; paramIndex++)
            {
                string paramName  = PluginContext.PluginCommandStub.GetParameterName(paramIndex);
                string paramLabel = PluginContext.PluginCommandStub.GetParameterLabel(paramIndex);

                // check if this plugin has more than one parameter with the same name
                if (!processedParameters.ContainsKey(paramName))
                {
                    processedParameters.Add(paramName, 1);
                }
                else
                {
                    processedParameters[paramName]++;
                    paramName = paramName + processedParameters[paramName];
                }

                // initialize
                PluginContext.PluginCommandStub.SetParameter(paramIndex, 0);

                // step through the steps
                for (float paramValue = 1.0f; paramValue >= 0.0f; paramValue -= 0.010f)
                {
                    byte[] previousChunkData = PluginContext.PluginCommandStub.GetChunk(true);

                    // set the parameters
                    PluginContext.PluginCommandStub.SetParameter(paramIndex, paramValue);

                    byte[] chunkData = PluginContext.PluginCommandStub.GetChunk(true);

                    // and read the display back
                    paramDisplay = PluginContext.PluginCommandStub.GetParameterDisplay(paramIndex);

                    Console.Out.WriteLine("Measuring {0}/{1} {2} at value {3:0.00} ({4}) ...", paramIndex, paramCount, paramName, paramValue, paramDisplay);

                    DetectChunkChanges(previousChunkData, chunkData, paramName, paramLabel, paramDisplay, String.Format("{0:0.00}", paramValue));

                    // wait
                    System.Threading.Thread.Sleep(5);
                }

                // wait a bit longer
                System.Threading.Thread.Sleep(5);
            }

            // store to xml file
            //set formatting options
            var settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = "\t";
            string outputFile = "\\output2.xml";

            using (XmlWriter writer = XmlWriter.Create(Application.StartupPath + outputFile, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("TrackedPresetFileChanges");

                for (int i = 0; i < InvestigatedPluginPresetFileFormatList.Count; i++)
                {
                    InvestigatedPluginPresetFileFormat row = InvestigatedPluginPresetFileFormatList[i];
                    writer.WriteStartElement("Row");
                    writer.WriteElementString("IndexInFile", "" + row.IndexInFile);
                    writer.WriteElementString("ByteValue", "" + row.ByteValue);
                    writer.WriteElementString("ByteValueHexString", row.ByteValueHexString);
                    writer.WriteElementString("ParameterName", row.ParameterName);
                    writer.WriteElementString("ParameterNameFormatted", row.ParameterNameFormatted);
                    writer.WriteElementString("ParameterLabel", row.ParameterLabel);
                    writer.WriteElementString("ParameterDisplay", row.ParameterDisplay);
                    writer.WriteElementString("ParameterValue", row.ParameterValue);
                    writer.WriteElementString("TextChanges", row.TextChanges);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
                MessageBox.Show("Information in the the table is successfully saved in the following location: \n" + Application.StartupPath + outputFile, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }