Пример #1
0
        private void PackageFolderChooseButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "Заголовки прошивок | .Header";
            ofd.DefaultExt       = ".Header";
            ofd.InitialDirectory = WorkDirectory;
            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                if (Path.GetFileName(ofd.FileName) != ".Header")
                {
                    MessageBox.Show(this, "Нужно выбрать файл .Header", "Неверно выбран файл");
                }
                else
                {
                    var newScriptHolder = new ScriptElementsHolder();
                    if (newScriptHolder.loadFrom(ofd.FileName, PackLogger))
                    {
                        ScriptHolder            = newScriptHolder;
                        FirmwareDir             = Path.GetDirectoryName(ofd.FileName);
                        PackageFolderLabel.Text = "Папка сборки : " + FirmwareDir;
                        fillImagesPanel(ScriptHolder.getPartitions());
                    }
                    PackButton.Enabled = true;
                    PackingProtocolTextBox.Clear();
                }
            }
        }
Пример #2
0
        private void FirmwareChooseComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (FirmwareChooseComboBox.SelectedIndex == -1)
            {
                return;
            }

            SourceFirmwareFilename = Path.Combine(WorkDirectory, (string)FirmwareChooseComboBox.SelectedItem);

            ScriptHolder = new ScriptElementsHolder();
            if (ScriptHolder.loadFrom(SourceFirmwareFilename, UnpackLogger))
            {
                fillPartitionsPanel(ScriptHolder.getPartitions());
            }
        }
Пример #3
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;
            }
        }