Пример #1
0
 void downloader_GotVersionsEvent(object sender, RunWorkerCompletedEventArgs e)
 {
     versions = (FirmwareVersions)e.Result;
     if (versions.Result != "")
     {
         txtConsole.AppendText("\r\n" + versions.Result);
         cbxVersion.Text      = "Not Available";
         rbnLocalFile.Checked = true;
     }
     else
     {
         cbxVersion.Enabled = true;
         cbxVersion.Items.Clear();
         foreach (FirmwareVersion version in versions.Versions)
         {
             cbxVersion.Items.Add(version.Name);
         }
         if (cbxVersion.Items.Count > 0)
         {
             cbxVersion.SelectedIndex = 0;
         }
     }
     txtReleaseNotes.Enabled = true;
     btnFlash.Enabled        = (cbxPort.Text != "None");
 }
Пример #2
0
        void firmwareWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            FirmwareVersions versions = (FirmwareVersions)e.Result;

            if (versions.Result != "")
            {
                textBox.Rtf = txtBox_Text.Trim('}') + @"\par " + versions.Result.Replace("\n", @"\par ") + "}";
            }
            else
            {
                FirmwareVersion newVersion = null;
                string          result     = @"\par ";
                foreach (FirmwareVersion version in versions.Versions)
                {
                    if (version.Version > frmPixSettings.MavpixelVersion &&
                        (newVersion == null || newVersion.Version < version.Version))
                    {
                        newVersion = version;
                    }
                }
                if (newVersion != null)
                {
                    result += @"{\qc\b\fs20" + UpdateWorker.imageRtf + @" A newer version of Mavpixel (v" + newVersion.Version.ToString() + @") is available.\b0\par\ql" +
                              UpdateWorker.horizontalBarRtf + @"\fs16\par Use the Firmware Flasher to upgrade to the new version.\par\par The firmware image is available from: " + newVersion.DownloadUrl + @"\par";
                    if (newVersion.ReleaseNotes != null)
                    {
                        result += @"\par\b Notes for v" + newVersion.Version.ToString() + @":\b0\par " + newVersion.ReleaseNotes.Replace("\n", @"\par ") + "}";
                    }
                    else
                    {
                        result += "}";
                    }
                }
                else
                {
                    result += UpdateWorker.tickRtf + @" Mavpixel firmware is up to date.}";
                }
                textBox.Rtf = txtBox_Text.Trim('}') + result;
            }
        }
Пример #3
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            FirmwareVersion  currentVersion = null;
            FirmwareVersions versions       = new FirmwareVersions();

            e.Result = versions;
            XmlTextReader reader = null;

            try
            {
                reader = new XmlTextReader((string)e.Argument);
                reader.MoveToContent();
                string elementName = "";
                if ((reader.NodeType == XmlNodeType.Element) &&
                    (reader.Name == "Mavpixel"))
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "Release")
                        {
                            currentVersion          = new FirmwareVersion();
                            currentVersion.Filename = "";
                            versions.Versions.Add(currentVersion);
                        }
                        else if (reader.NodeType == XmlNodeType.Element)
                        {
                            elementName = reader.Name;
                        }
                        else
                        {
                            if ((reader.NodeType == XmlNodeType.Text) &&
                                (reader.HasValue) && (currentVersion != null))
                            {
                                // we check what the name of the node was
                                switch (elementName)
                                {
                                case "name":
                                    currentVersion.Name = reader.Value;
                                    break;

                                case "version":
                                    currentVersion.Version = new Version(reader.Value);
                                    break;

                                case "url":
                                    currentVersion.DownloadUrl = reader.Value;
                                    break;

                                case "notes":
                                    //fix line endings
                                    currentVersion.ReleaseNotes = reader.Value.Replace("\r", "").Replace("\n", "\r\n");
                                    break;
                                }
                            }
                        }
                    }
                }
                if (currentVersion == null)
                {
                    throw new Exception("Version information not found in versions.xml!");
                }
            }
            catch (Exception ex)
            {
                versions.Result = "Error fetching version list: " + ex.Message + "\r\n";
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }