Ejemplo n.º 1
0
        public bool packFirmware(IMessageLogger messageLogger)
        {
            try
            {
                if (ScriptHolder == null)
                {
                    messageLogger.logMessage("Нужно выбрать папку сборки.");
                    return(false);
                }

                Dictionary <string, Partition> partitionsToPack = new Dictionary <string, Partition>();
                foreach (ImagePanel panel in ImagePanels)
                {
                    if (panel.Checked)
                    {
                        partitionsToPack.Add(panel.Partition.Name, panel.Partition);
                    }
                }

                StringListLogger taskLogger = new StringListLogger();

                var  firmwareBuilder = new FirmwareBuilder(FirmwareDir, ProgramConfiguration.FirmwareTitle);
                Task packing         = new Task(delegate()
                {
                    firmwareBuilder.pack(ScriptHolder, partitionsToPack, taskLogger);
                });

                PackageFolderChooseButton.Enabled = false;
                UnpackButton.Enabled = false;

                PackingProcessing = true;
                packing.Start();

                TextBoxPointsProgressIndicator progressIndicator = new TextBoxPointsProgressIndicator(PackingProtocolTextBox);
                while (!packing.Wait(100))
                {
                    Application.DoEvents();

                    if (taskLogger.hasNewMessages())
                    {
                        progressIndicator.hide();
                        taskLogger.exportMessages(messageLogger);
                    }
                    else
                    {
                        messageLogger.logMessage(progressIndicator.getNextState(), false);
                    }
                }
                progressIndicator.hide();
                taskLogger.exportMessages(messageLogger);

                return(true);
            }
            catch (Exception error)
            {
                messageLogger.logMessage(error.ToString());
                return(false);
            }
            finally {
                PackageFolderChooseButton.Enabled = true;
                PackingProcessing    = false;
                UnpackButton.Enabled = FirmwareChooseComboBox.Items.Count > 0;
            }
        }
Ejemplo n.º 2
0
        private void UnpackButton_Click(object sender, EventArgs e)
        {
            try
            {
                UnpackingProtocolTextBox.Clear();
                Application.DoEvents();

                List <Partition> partitionsToUnpack = new List <Partition>();
                foreach (Control control in PartitionsTablePanel.Controls)
                {
                    if (control is PartitionPanel partitionPanel && partitionPanel.Checked)
                    {
                        partitionsToUnpack.Add(partitionPanel.Partition);
                    }
                }

                if (partitionsToUnpack.Count > 0)
                {
                    UnpackButton.Enabled = false;
                    PackButton.Enabled   = false;
                    PackageFolderChooseButton.Enabled = false;

                    UnpackingProcessing = true;

                    FirmwareDir = Path.Combine(WorkDirectory, Path.GetFileNameWithoutExtension(SourceFirmwareFilename));
                    if (!Directory.Exists(FirmwareDir))
                    {
                        Directory.CreateDirectory(FirmwareDir);
                    }

                    if (Directory.GetFiles(FirmwareDir, ".Header").Length == 0)
                    {
                        ScriptHolder.saveTo(Path.Combine(FirmwareDir, ".Header"));
                    }

                    bool             successfully = true;
                    StringListLogger taskLogger   = new StringListLogger();

                    Task unpacking = new Task(delegate()
                    {
                        try
                        {
                            using (FileStream fileStream = new FileStream(SourceFirmwareFilename, FileMode.Open, FileAccess.Read))
                            {
                                foreach (Partition partition in partitionsToUnpack)
                                {
                                    if (!partition.unpack(FirmwareDir, fileStream, taskLogger))
                                    {
                                        successfully = false;
                                    }
                                }
                            }
                        }
                        catch (Exception error)
                        {
                            UnpackLogger.logMessage(error.ToString());
                            successfully = false;
                        }
                    });

                    unpacking.Start();

                    TextBoxPointsProgressIndicator progressIndicator = new TextBoxPointsProgressIndicator(UnpackingProtocolTextBox);
                    while (!unpacking.Wait(100))
                    {
                        Application.DoEvents();
                        if (taskLogger.hasNewMessages())
                        {
                            progressIndicator.hide();
                            taskLogger.exportMessages(UnpackLogger);
                        }
                        else
                        {
                            UnpackLogger.logMessage(progressIndicator.getNextState(), false);
                        }
                    }
                    progressIndicator.hide();
                    taskLogger.exportMessages(UnpackLogger);

                    //try
                    //{
                    //    using (FileStream fileStream = new FileStream( SourceFirmwareFilename, FileMode.Open, FileAccess.Read ))
                    //    {
                    //        foreach (Partition partition in partitionsToUnpack)
                    //        {
                    //            if (!partition.unpack( FirmwareDir, fileStream, UnpackLogger ))
                    //                successfully = false;
                    //        }
                    //    }
                    //}
                    //catch (Exception error)
                    //{
                    //    UnpackLogger.logMessage( error.ToString() );
                    //    successfully = false;
                    //}

                    if (successfully)
                    {
                        UnpackLogger.logMessage("Успешно распаковалось.");
                    }

                    PackageFolderLabel.Text = "Папка сборки : " + FirmwareDir;
                    fillImagesPanel(ScriptHolder.getPartitions());

                    PackButton.Enabled = true;
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(this, error.ToString(), "Разбор прошивки завершился с ошибкой");
            }
            finally
            {
                UnpackingProcessing  = false;
                UnpackButton.Enabled = true;
                PackButton.Enabled   = true;
                PackageFolderChooseButton.Enabled = true;
            }
        }