Пример #1
0
        private void SaveFile()
        {
            if (File.Exists(m_FileName))
            {
                File.Delete(m_FileName);
            }
            else
            {
                dlgSave.Filter = "Text File (*.txt)|*.txt";
                if (dlgSave.ShowDialog() == DialogResult.OK)
                {
                    m_FileName = dlgSave.FileName;
                    CalcCenter(dlgSave.FileName.Substring(dlgSave.FileName.LastIndexOf('\\') + 1, m_FileName.Length - (m_FileName.LastIndexOf('\\') + 1)));
                }
                else
                {
                    return;
                }
            }
            byte[] convertBuffer = m_enc.GetBytes(textBox1.Text);
            for (int a = 0; a < convertBuffer.Length; a++)
            {
                if ((convertBuffer[a] == 0x95 || convertBuffer[a] == 0x45) && convertBuffer[a + 1] == 0xFF)
                {
                    convertBuffer[a] = 0xFF;
                }
            }

            /*int j = 0;
             * for (int a = 0; a < convertBuffer.Length; a++)
             * {
             *  if (convertBuffer[a] == 0x00)
             *      j++;
             * }
             * byte[] newBuffer = new byte[convertBuffer.Length - j];
             * int c = 0;
             * for (int b = 0; b < convertBuffer.Length; b++)
             * {
             *  if(convertBuffer[b] != 0x00)
             *  {
             *      newBuffer[c] = convertBuffer[b];
             *      c++;
             *  }
             * }*/
            for (int i = 0; i < convertBuffer.Length; i++)
            {
                if (convertBuffer[i] == 0x40 && convertBuffer[i - 1] != 0x81)        // 0x00 is read as a string termination
                {
                    convertBuffer[i] = 0x00;                                         // 0x40 is unlikely (impossible) to occur in a script file
                }
            }
            FileInfo   info   = new FileInfo(m_FileName);
            FileStream stream = info.OpenWrite();

            binWrite = new BinaryWriter(stream);
            binWrite.Write(convertBuffer);
            binWrite.Close();
            string FileName = "";

            if (m_isSplit)
            {
                ItemsSplitter splitter = new ItemsSplitter();
                splitter.Initialize(m_FileName, m_FileName.Substring(0, m_FileName.Length - 9) + "joined.txt");
                splitter.Join(m_FileName.Substring(0, m_FileName.Length - 9) + ".txt");
                ItemsParser iParsed = new ItemsParser();
                iParsed.Initialize(m_FileName.Substring(0, m_FileName.Length - 9) + "joined.txt", m_FileName.Substring(0, m_FileName.Length - 9) + ".txt");
                m_FileName = m_FileName.Substring(0, m_FileName.Length - 9) + ".txt";
                if (m_is_SY)
                {
                    VICompress vCompress = new VICompress();
                    vCompress.Initialize(m_FileName, m_FileName.Substring(0, m_FileName.Length - 3) + "_sy");
                    vCompress.Compress();
                }
            }
            if (m_isParsed)
            {
                Parser parse = new Parser();
                parse.Initialize(m_FileName, m_FileName.Substring(0, m_FileName.Length - 10) + ".txt");
                if (!parse.RePack())
                {
                    MessageBox.Show("There was a problem saving this file. Make sure you're working only on files that are proven to be ready.", "Oopsy");
                    m_isSaved = false;
                    return;
                }
                else
                {
                    FileName = m_FileName.Substring(0, m_FileName.Length - 10) + ".txt";

                    if (m_is_SY)
                    {
                        VICompress vCompress = new VICompress();
                        vCompress.Initialize(FileName, FileName.Substring(0, FileName.Length - 3) + "_sy");
                        vCompress.Compress();
                    }
                }
            }
            m_isSaved = true;
            CalcCenter(m_FileName.Substring(m_FileName.LastIndexOf('\\') + 1, m_FileName.Length - (m_FileName.LastIndexOf('\\') + 1)));
        }
Пример #2
0
        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;
            }
        }