private void hexTableToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (m_isHexTable)
     {
         return;
     }
     hexForm = new HexForm(this);
     hexForm.Show();
     m_isHexTable = true;
 }
 private void toolStripButton12_Click(object sender, EventArgs e)
 {
     if (m_isHexTable)
     {
         return;
     }
     hexForm = new HexForm(this);
     hexForm.Show();
     m_isHexTable = true;
 }
        private void OpenDecompression()
        {
            switch (STRFormatClip(m_FileName))
            {
            case "LIB":
                Package pckge   = new Package();
                string  hdrFile = dlg.FileName.Substring(0, dlg.FileName.Length - dlg.SafeFileName.Length) +
                                  dlg.SafeFileName.Substring(0, dlg.SafeFileName.Length - 4) + ".HDR";
                pckge.InitializeDump(dlg.FileName, hdrFile);
                pckge.VIDump();
                m_TemporaryFolderPath = pckge.TempFolderPath;
                m_LibFileName         = dlg.FileName;

                m_isLib = true;         // flag to indicate lib unpacking
                dlg1.InitialDirectory = m_TemporaryFolderPath;
                dlg1.RestoreDirectory = true;
                dlg1.Title            = "Select the library file to work on";
                dlg1.Filter           = "Unpacked Library Text Files (*._sy)|*._sy";
                while (true)
                {
                    if (dlg1.ShowDialog() == DialogResult.OK)
                    {
                        m_FileName = dlg1.FileName;
                        CalcCenter(dlg1.SafeFileName);
                        break;
                    }
                }
                goto case "_sy";

            case "_sy":
                VIDecrypt vDecrypt = new VIDecrypt();
                vDecrypt.Initialize(m_FileName, m_FileName.Substring(0, m_FileName.LastIndexOf('\\')) +
                                    m_FileName.Substring(m_FileName.LastIndexOf('\\'), m_FileName.Length - m_FileName.LastIndexOf('\\') - 3) + "txt"); // = path + name + .txt
                if (vDecrypt.Decrypt())
                {
                    m_FileName = m_FileName.Substring(0, m_FileName.LastIndexOf('\\')) +
                                 m_FileName.Substring(m_FileName.LastIndexOf('\\'), m_FileName.Length - m_FileName.LastIndexOf('\\') - 3) + "txt";
                    vDecrypt.WriteFile();
                    m_is_SY = true;
                }
                else
                {
                    MessageBox.Show("There was an error decompressing this system file. Try again", "oopsy");
                    try
                    {
                        if (m_TemporaryFolderPath != "" && m_TemporaryFolderPath != null)
                        {
                            System.IO.Directory.Delete(m_TemporaryFolderPath, true);
                        }
                    }
                    catch (Exception delexe)
                    {
                        MessageBox.Show("Couldn't delete all of the temporary files: " + delexe.Message, "Oops");
                    }
                    m_FileName            = "";
                    m_TemporaryFolderPath = "";
                    m_is_SY = false;
                    m_isLib = false;
                    return;
                }
                goto case "txt";

            case "txt":
                if (m_FileName.Contains("itemlist"))
                {
                    ItemsSplitter splitter = new ItemsSplitter();
                    splitter.Initialize(m_FileName, m_FileName.Substring(0, m_FileName.Length - 4) + "split.txt");
                    splitter.Split();
                    m_FileName = m_FileName.Substring(0, m_FileName.Length - 4) + "split.txt";
                    m_isSplit  = true;
                    goto default;
                }
                Parser parse = new Parser();
                parse.Initialize(m_FileName, m_FileName.Substring(0, m_FileName.Length - 4) + "parsed.txt");
                if (!parse.TryParse())
                {
                    parse.Parse();
                    m_FileName = m_FileName.Substring(0, m_FileName.Length - 4) + "parsed.txt";
                    m_isParsed = true;
                }
                else
                {
                    parse.CloseOut();
                    System.IO.File.Delete(m_FileName.Substring(0, m_FileName.Length - 4) + "parsed.txt");
                }
                goto default;

            default:
                CalcCenter(m_FileName.Substring(m_FileName.LastIndexOf('\\') + 1, m_FileName.Length - (m_FileName.LastIndexOf('\\') + 1)));
                FileInfo   info   = new FileInfo(m_FileName);
                FileStream stream = info.OpenRead();
                binRead      = new BinaryReader(stream);
                m_ReadBuffer = binRead.ReadBytes((int)stream.Length);
                Encoding enc = Encoding.GetEncoding(932);
                //stream.Close();
                info = new FileInfo(m_FileName);
                TextReader streamr = info.OpenText();

                stream.Close();

                for (int i = 0; i < m_ReadBuffer.Length; i++)
                {
                    if (m_ReadBuffer[i] == 0x00)                   // 0x00 is read as a string termination
                    {
                        m_ReadBuffer[i] = 0x40;                    // 0x40 is unlikely (impossible) to occur in a script file
                    }
                }
                textBox1.Text = enc.GetString(m_ReadBuffer);
                IntelliText();
                if (m_isHexTable)
                {
                    return;
                }
                hexForm = new HexForm(this);
                hexForm.Show();
                m_isHexTable = true;
                m_enc        = enc;
                stream.Close();
                streamr.Close();
                binRead = null;
                break;
            }
        }