private void DumpLibFiles()
        {
            DirectoryInfo dinfo;

            try
            {
                if (Directory.Exists(Environment.GetEnvironmentVariable("TEMP") + @"\\B4LIB\\"))
                {
                    System.IO.Directory.Delete(Environment.GetEnvironmentVariable("TEMP") + @"\\B4LIB\\", true);
                }
                dinfo            = Directory.CreateDirectory(Environment.GetEnvironmentVariable("TEMP") + @"\\B4LIB");
                m_TempFolderPath = dinfo.FullName.ToString();
            }
            catch (Exception dumpexe)
            {
                MessageBox.Show("Please run this script editor as administrator to ensure all files can be appropriately unpackaged into your temporary folder\r\n" + dumpexe.Message);
            }
            ProgressForm.ShowProgressForm(m_NoFiles, "Unpacking library...");
            m_FileInfo   = new FileInfo(m_LibFilePath);
            m_FileStream = m_FileInfo.OpenRead();
            binRead      = new BinaryReader(m_FileStream);
            for (int i = 0; i < m_NoFiles; i++)
            {
                m_ReadBuffer          = new byte[m_SizeBuffer[i]];
                m_FileStream.Position = m_OffsetBuffer[i];
                m_ReadBuffer          = binRead.ReadBytes((int)m_SizeBuffer[i]);

                m_oFileInfo   = new FileInfo(m_TempFolderPath + "\\" + m_NameBuffer[i].Substring(0, m_NameBuffer[i].IndexOf('\0')));
                m_oFileStream = m_oFileInfo.OpenWrite();
                binWrite      = new BinaryWriter(m_oFileStream);
                binWrite.Write(m_ReadBuffer);

                binWrite.Flush();
                m_oFileStream.Close();
                ProgressForm.UpdateStatusp(m_NameBuffer[i]);
            }

            m_FileStream.Close();
            m_oFileStream.Close();
        }
        private void WriteLibFiles()
        {
            // start by writing the HDR file
            // write the header in the buffer to the actual HDR out file
            for (int q = 0; q < 16; q++)
            {
                binWrite.Write(m_WriteBuffer[q]);
            }
            // write the file info for the HDR file
            string s = "";

            byte[] b = new byte[16];
            for (int i = 0; i < m_NoFiles; i++)
            {
                // 16 bytes
                s = m_NameBuffer[i];
                b = Encoding.ASCII.GetBytes(s);

                binWrite.Write(b, 0, 16);             // strings start with a byte indicating how long they are; we have to get rid of that
                binWrite.Write(m_OffsetBuffer[i]);    // 4 bytes
                binWrite.Write(m_SizeBuffer[i]);      // 4 bytes
                binWrite.Write((uint)0);              // write this for the 8 bytes of padding after the size bytes = 32 bytes total per file
                binWrite.Write((uint)0);
                //ProgressForm.UpdateStatusp(true, 0);
            }

            // now switch to writing the LIB file
            // first figure out the out lib file path
            int    index      = m_FileOutPath.IndexOf(m_SafeOutName);
            string lbFilePath = m_FileOutPath.Substring(0, index);
            string lbName     = m_SafeOutName.Substring(0, m_SafeOutName.Length - 4);
            string libPath    = lbFilePath + lbName + @".LIB";

            // make sure previous buffers are closed
            m_FileStream.Flush();
            m_oFileStream.Flush();
            //m_FileStream.Close();
            //m_oFileStream.Close();
            binRead.Close();
            binWrite.Close();

            // now start reading into buffers to copy over
            FileInfo   inInfo    = null;
            FileStream inStream  = null;
            FileInfo   outInfo   = new FileInfo(libPath);
            FileStream outStream = outInfo.OpenWrite();

            binWrite      = new BinaryWriter(outStream);
            m_WriteBuffer = new byte[m_OffsetBuffer[m_NoFiles - 1] + m_SizeBuffer[m_NoFiles - 1]];
            // copy data from each file byte for byte into the new lib file
            ProgressForm.ShowProgressForm((int)(m_OffsetBuffer[m_NoFiles - 1] + m_SizeBuffer[m_NoFiles - 1]), "Packaging new B4 files...");           // start a progress bar cause this will be the majority of the package function
            int    topicInt  = 0;
            string topicName = "";

            for (int l = 0; l < m_NoFiles; l++)
            {
                topicInt  = m_NameBuffer[l].IndexOf('\0');
                topicName = m_NameBuffer[l].Substring(0, topicInt);
                inInfo    = new FileInfo(m_LibFilePath + topicName);
                inStream  = inInfo.OpenRead();
                binRead   = new BinaryReader(inStream);
                // read info into new file read buffer
                m_ReadBuffer = new byte[inInfo.Length];
                for (int k = 0; k < inInfo.Length; k++)
                {
                    m_ReadBuffer[k] = binRead.ReadByte();
                }

                // copy buffered data into new file
                for (int m = 0; m < m_ReadBuffer.Length; m++)
                {
                    binWrite.Write(m_ReadBuffer[m]);
                    ProgressForm.UpdateStatusp("packing " + topicName);
                }

                m_ReadBuffer = null;
                inStream.Flush();
                binRead.Close();
            }
            outStream.Flush();
            binWrite.Close();
        }
        private void IntelliText()
        {
            if (!m_isIntelliText)
            {
                return;
            }
            if (textBox1.Text == "")
            {
                return;
            }
            string[] searchText = new string[] { "@", "", "", "(", "<", "", "x" };
            int[]    textLength = new int[] { 1, 1, 2, 3, 3, 2, 2 };
            Color[]  cArray     = new Color[] { Color.LightBlue, Color.LightPink, Color.PaleVioletRed, Color.LightGreen, Color.CornflowerBlue, Color.LightCoral, Color.Yellow };
            ProgressForm.ShowProgressForm(10500 + 10500, "Identifying Formatting...");
            for (int j = 0; j < 7; j++)
            {
                int[] newLineArray1 = new int[1500];                // could be a misnomer--not really sure if this is a newline
                int   m_readPos     = 0;
                for (int i = 0; m_readPos < textBox1.Text.Length; i++)
                {
                    newLineArray1[i] = textBox1.Text.IndexOf(searchText[j], m_readPos + 1, (textBox1.Text.Length - 1) - m_readPos);
                    if (newLineArray1[i] == -1)
                    {                                       //    i > 0 && newLineArray1[i] < newLineArray1[i - 1])
                        m_readPos        = textBox1.Text.Length;
                        newLineArray1[i] = 0;
                    }
                    else
                    {
                        m_readPos = newLineArray1[i];
                    }
                    ProgressForm.UpdateStatusp("Searching for     " + searchText[j]);
                }
                int holder = 0;
                for (int i = 0; i < newLineArray1.Length; i++)              // resize the array
                {
                    if (newLineArray1[i] != 0)
                    {
                        holder++;
                    }
                }
                ProgressForm.UpdateStatusp(false, 1500 - holder);
                ProgressForm.UpdateStatusp(false, 1500 - holder);
                int[] newLineArray = new int[holder];
                for (int i = 0; i < newLineArray.Length; i++)
                {
                    newLineArray[i] = newLineArray1[i];
                }
                for (int i = 0; i < newLineArray.Length; i++)
                {
                    textBox1.SelectionStart     = newLineArray[i];
                    textBox1.SelectionLength    = textLength[j];
                    textBox1.SelectionBackColor = cArray[j];
                    ProgressForm.UpdateStatusp("Searching for     " + searchText[j]);
                }
            }
            textBox1.SelectionStart  = 0;
            textBox1.SelectionLength = 0;

            /*if (!m_isColorTable)
             * {
             *  colorForm = new ColorFormatTable(this);
             *  colorForm.Show();
             *  m_isColorTable = true;
             * }*/
        }