Exemplo n.º 1
0
        //Firmware downloader entry point
        // Attach events to 'web' before calling
        public string download(FirmwareVersion version)
        {
            Uri    uri  = new Uri(version.DownloadUrl);
            string file = Application.UserAppDataPath + "\\" + uri.Segments[uri.Segments.Length - 1];

            web.DownloadFileAsync(uri, file);
            return(file);
        }
Exemplo n.º 2
0
        //Firmware downloader entry point
        // Attach events to 'web' before calling
        public string download(FirmwareVersion version)
        {
            Uri    uri  = new Uri(version.DownloadUrl);
            string file = Application.UserAppDataPath + "\\" + uri.Segments[uri.Segments.Length - 1];

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
            web.DownloadFileAsync(uri, file);
            return(file);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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();
                }
            }
        }