コード例 #1
0
 private void addToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var Contents = new STRING();
     foreach (var entry2 in STRINGS)
         STRINGS2.Add(entry2.Value.ID, entry2.Value);
     STRINGS.Clear();
     int y = this.listText.SelectedIndex + 1;
     int i = 0;
     listText.BeginUpdate();
     listText.Items.Clear();
     foreach (var entry in STRINGS2)
     {
         i++;
         if (i == y)
         {
             Contents.ID = 0x5500 + newentry;
             Contents.Offset = 0;
             Contents.data = new byte[] {0x01};
             Contents.lastbyte = 0;
             Contents.lastbyte2 = 0;
             Contents.text = "New entry" + newentry;
             STRINGS.Add(entry.Value.ID, entry.Value);
             this.listText.Items.Add(entry.Value.ID.ToString("X4"));
         }
         else
         {
             STRINGS.Add(entry.Value.ID, entry.Value);
             this.listText.Items.Add(entry.Value.ID.ToString("X4"));
         }
     }
     newentry++;
     nentriesStr++;
     STRINGS2.Clear();
     listText.SelectedItem = Contents.ID.ToString("X4");
     listText.EndUpdate();
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: GovanifY/EVENTVIEWER_EDITOR
        private void LoadStr(string filename, bool ro = false)
        {
            try
            {
                bar =
                    new BAR(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read,
                        System.IO.FileShare.None));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }
            fileName = System.IO.Path.GetFileName(filename);
            b = this.bar.fileList[0];
            //Now let's extract the file
            if (bar.fileCount != 2)
            {
                MessageBox.Show("This BAR files contains more than two file!\nAre you sure it is title.bar?",
                    "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }
            if (b.id != "titl")
            {
                MessageBox.Show("This BAR files don't have a file called titl!\nAre you sure it is title.bar?",
                    "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }

            string nameextractedstr = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), System.IO.Path.GetTempFileName());
            try
            {
                System.IO.File.WriteAllBytes(nameextractedstr, b.data);
            }
            catch
            {
                MessageBox.Show(
                    "Text file can't be extracted in temp folder!\nDo you have enough access to write in the TEMP folder?",
                    "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }
            //Now let's load this shit inside a dictionnary
            uint version;
            uint nentriesStr;
            long brpos = 0;
            bool jap = false;
            STRINGS.Clear();

            BinaryReader br = new BinaryReader(new FileStream(nameextractedstr, FileMode.Open));
            br.BaseStream.Position = 0;
            version = br.ReadUInt32();
            nentriesStr = br.ReadUInt32();
            for (int i = 0; i < nentriesStr; i++)
            {
                var Contents = new STRING();
                Contents.ID = br.ReadUInt32();
                brpos = br.BaseStream.Position + 4;
                br.BaseStream.Position = br.ReadUInt32();
                //Contents.Offset = (uint) br.BaseStream.Position;
                //MessageBox.Show(Contents.Offset.ToString(), nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                byte c = br.ReadByte();
                while (true)
                {
                    Contents.text = Contents.bytetotext(c, Contents.text, jap);
                        c = br.ReadByte();
                    if (c == 0)
                    {
                        goto next;
                    }
                }
                next:
                //MessageBox.Show(Contents.text, nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                if (checkBox1.Checked)
                {
                    jap = true;
                }
                STRINGS.Add(Contents.ID, Contents);
                br.BaseStream.Position = brpos;
            }
        }
コード例 #3
0
 private void openFile(string filename, bool ro = false)
 {
     try
     {
         Cleanup();
         try
         {
             bar =
                 new BAR(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read,
                     System.IO.FileShare.None));
         }
         catch (Exception e)
         {
             MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
             bar = null;
             return;
         }
         fileName = System.IO.Path.GetFileName(filename);
         b = this.bar.fileList[0];
         //Now let's extract the file
         if (bar.fileCount != 2)
         {
             MessageBox.Show("This BAR file doesn't exactly contains two files!\nAre you sure it is a text file?",
                 "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
             bar = null;
             return;
         }
                        string nameextractedtext =
             Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                 System.IO.Path.GetTempFileName());
         try
         {
             System.IO.File.WriteAllBytes(nameextractedtext, b.data);
         }
         catch
         {
             MessageBox.Show(
                 "String file can't be extracted in temp folder!\nDo you have enough access to write in the TEMP folder?",
                 "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
             bar = null;
             return;
         }
         BinaryReader br = new BinaryReader(new FileStream(nameextractedtext, FileMode.Open));
     br.BaseStream.Position = 0;
     var version = br.ReadUInt32();
     nentriesStr = br.ReadUInt32();
     bool jap = false;
     for (int i = 0; i < nentriesStr; i++)
     {
         var Contents = new STRING();
         Contents.ID = br.ReadUInt32();
         var brpos = br.BaseStream.Position + 4;
         br.BaseStream.Position = br.ReadUInt32();
         //Contents.Offset = (uint) br.BaseStream.Position;
         //MessageBox.Show(Contents.Offset.ToString(), nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
         byte c = br.ReadByte();
         while (true)
         {
             Contents.text = Contents.bytetotext(c, Contents.text, jap);
                 c = br.ReadByte();
             if (c == 0)
             {
                 goto next;
             }
         }
         next:
         //MessageBox.Show(Contents.text, nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
         if (Jap_mapping.Checked){jap = true;}
         STRINGS.Add(Contents.ID, Contents);
         br.BaseStream.Position = brpos;
         this.listText.Items.Add(Contents.ID.ToString("X4"));
     }
         SetUp();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
     }
 }