资源简介

可选择三个(用户可自己进行扩展至多个),读取Bin文件并拼接,在每个bin文件开始添加两个字节的bin字节长度后拼接为一个Bin文件。 采用 binaryReader读取。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace combinBins
{
    public partial class Form1 : Form
    {
        List bytList = new List();


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            openFile(txtboxDispPath1);
        }

        private void button2_Click(object sender EventArgs e)
        {
            openFile(txtboxDispPath2);
        }

        private void button3_Click(object sender EventArgs e)
        {
            openFile(txtboxDispPath3);
        }

        private void openFile(TextBox txtbox)
        {
            openFileDialog1.title = “选择需要拼接的固件“;

            openFileDialog1.InitialDirectory = Application.StartupPath;
            openFileDialog1.Filter = “Bin file(*.bin)|*.bin“;
            openFileDialog1.RestoreDirectory = true;
            //string Mytext = ““;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtbox.Text = openFileDialog1.FileName;
            }
        }

        private void button4_Click(object sender EventArgs e)
        {
            saveFileDialog1.title = “保存bin文件“;
            saveFileDialog1.InitialDirectory = Application.StartupPath;
            saveFileDialog1.Filter = “Bin file(*.bin)|*.bin“;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {                
                combinBinFiles();
                createCombinBinFile(saveFileDialog1.FileName);
            }
        }

        void createCombinBinFile(string fileName)
        {
            FileStream binFile = new FileStream(fileName FileMode.Create);
            
            BinaryWriter binWriter = new BinaryWriter(binFile);

            byte[] byteTemp = new byte[bytList.Count];
            bytList.CopyTo(byteTemp0);
            binWriter.Write(byteTemp 0 byteTemp.Length);
            binWriter.Close();
            txtSaveBinFilePath.Text = fileName;
            bytList.Clear();
        }

        

        private void combinBinFiles()
        {
            try
            {

                byte[] binDataTemp1 = readBinFiles(txtboxDispPath1.Text);
                byte[] binPackLen1 = new byte[2];
                binPackLen1[0] = (byte)(binDataTemp1.Length / 256);
                binPackLen1[1] = (byte)(binDataTemp1.Length);
                bytList.AddRange(binPackLen1);
                bytList.AddRange(binDataTemp1);

                byte[] binDataTemp2 = readBinFiles(txtboxDispPath2.Text);
                byte[] binPackLen2 = new byte[2];
                binPackLen2[0] = (byte)(binDataTemp2.Length / 256);
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11776  2015-09-19 10:46  combinBins\combinBins\bin\Debug\combinBins.exe

     文件      32256  2015-09-19 10:46  combinBins\combinBins\bin\Debug\combinBins.pdb

     文件      11600  2015-09-19 10:46  combinBins\combinBins\bin\Debug\combinBins.vshost.exe

     文件        490  2015-07-10 19:01  combinBins\combinBins\bin\Debug\combinBins.vshost.exe.manifest

     文件       3829  2015-09-18 13:46  combinBins\combinBins\combinBins.csproj

     文件       5775  2015-09-18 15:24  combinBins\combinBins\Form1.cs

     文件       6689  2015-09-18 14:53  combinBins\combinBins\Form1.Designer.cs

     文件       6224  2015-09-18 14:53  combinBins\combinBins\Form1.resx

     文件        988  2015-09-19 10:46  combinBins\combinBins\obj\x86\Debug\combinBins.csproj.FileListAbsolute.txt

     文件        975  2015-09-18 14:53  combinBins\combinBins\obj\x86\Debug\combinBins.csproj.GenerateResource.Cache

     文件      11776  2015-09-19 10:46  combinBins\combinBins\obj\x86\Debug\combinBins.exe

     文件        180  2015-09-18 14:53  combinBins\combinBins\obj\x86\Debug\combinBins.Form1.resources

     文件      32256  2015-09-19 10:46  combinBins\combinBins\obj\x86\Debug\combinBins.pdb

     文件        180  2015-09-18 13:46  combinBins\combinBins\obj\x86\Debug\combinBins.Properties.Resources.resources

     文件       6584  2015-09-19 10:46  combinBins\combinBins\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        491  2015-09-18 13:35  combinBins\combinBins\Program.cs

     文件       1352  2015-09-18 13:35  combinBins\combinBins\Properties\AssemblyInfo.cs

     文件       2872  2015-09-18 13:35  combinBins\combinBins\Properties\Resources.Designer.cs

     文件       5612  2015-09-18 13:35  combinBins\combinBins\Properties\Resources.resx

     文件       1097  2015-09-18 13:35  combinBins\combinBins\Properties\Settings.Designer.cs

     文件        249  2015-09-18 13:35  combinBins\combinBins\Properties\Settings.settings

     文件        872  2015-09-18 13:35  combinBins\combinBins.sln

    ..A..H.     26112  2015-09-19 10:47  combinBins\combinBins.suo

     目录          0  2015-09-18 13:35  combinBins\combinBins\obj\x86\Debug\TempPE

     目录          0  2015-09-19 10:46  combinBins\combinBins\obj\x86\Debug

     目录          0  2015-09-18 13:46  combinBins\combinBins\bin\Debug

     目录          0  2015-09-18 13:35  combinBins\combinBins\obj\x86

     目录          0  2015-09-18 13:35  combinBins\combinBins\bin

     目录          0  2015-09-18 13:35  combinBins\combinBins\obj

     目录          0  2015-09-18 13:35  combinBins\combinBins\Properties

............此处省略5个文件信息

评论

共有 条评论