Exemplo n.º 1
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int            index = filesListView.FocusedItem.Index;
            PAKContentFile file  = pak.GetFileByIndex(index);

            pak.DeleteFile(file);
        }
Exemplo n.º 2
0
 private void selectedToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (selectFolderDialog.ShowDialog() == DialogResult.OK)
     {
         foreach (ListViewItem item in filesListView.SelectedItems)
         {
             PAKContentFile file = pak.GetFileByIndex(item.Index);
             file.SaveTo(selectFolderDialog.SelectedPath);
         }
     }
 }
Exemplo n.º 3
0
        public void AddFile(string filepath)
        {
            // Decoded filename
            string filename = Path.GetFileName(filepath);

            // Filename as bytes
            byte[] filenameAsBytes = Encoding.UTF8.GetBytes(filename);

            // Filename as array with the size 260
            byte[] filenameByteArray = new byte[260];
            for (int j = 0; j < filenameAsBytes.Length; j++)
            {
                filenameByteArray[j] = filenameAsBytes[j];
            }

            // Deletes file(s) with the same filename as the one that is added
            for (int i = contentFiles.Count() - 1; i >= 0; i--)
            {
                if (contentFiles[i].Filename == filename)
                {
                    contentFiles.RemoveAt(i);
                }
            }
            // Reads the FileContent
            byte[] FileContent = File.ReadAllBytes(filepath);

            // Placeholder - gets updated in RewriteFiles later
            int offset = 0;

            // Length of the content
            int length = FileContent.Length;

            // random byte sequence - 24 bytes
            byte[] unknown1 = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWX");

            // random int - 4 bytes
            int unknown2 = 42;

            PAKContentFile pakFileContentToAdd = new PAKContentFile
            {
                FilenameRaw = filenameByteArray,
                Filename    = filename,
                Offset      = offset,
                Length      = length,
                Unknown1    = unknown1,
                Unknown2    = unknown2,
                FileContent = FileContent,
            };

            contentFiles.Add(pakFileContentToAdd);
        }
Exemplo n.º 4
0
        private void filesListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            previewPanel.Controls.Clear(); // clears preview

            if (filesListView.FocusedItem == null)
            {
                return;
            }

            int            index = filesListView.FocusedItem.Index;
            PAKContentFile file  = pak.GetFileByIndex(index);

            if (file.IsImage())
            {
                Bitmap bmp;
                Color  bgColor;

                if (file.IsTGA())
                {
                    bmp     = file.GetBitmapFromTGA();
                    bgColor = Color.Black;
                }
                else
                {
                    bmp     = file.GetBitmapFromImage();
                    bgColor = Color.Transparent;
                }

                PictureBox box = new PictureBox
                {
                    Image     = bmp,
                    SizeMode  = PictureBoxSizeMode.AutoSize,
                    BackColor = bgColor,
                };
                previewPanel.Controls.Add(box);
            }
            else
            {
                TextBox textBox = new TextBox
                {
                    Text       = file.GetText(),
                    Dock       = DockStyle.Fill,
                    Multiline  = true,
                    ScrollBars = ScrollBars.Both,
                    WordWrap   = true,
                    ReadOnly   = true,
                };
                previewPanel.Controls.Add(textBox);
            }
        }
Exemplo n.º 5
0
        private void UpdateOffsets()
        /// Updates all offsets based on the file position in the List.
        /// Necessary because otherwise, if adding the same file over and over again,
        /// the file would increase in size.
        {
            int contentFilesLength = contentFiles.Count();

            for (int i = 0; i < contentFilesLength; i++)
            {
                PAKContentFile file = contentFiles[i];

                if (i == 0)
                {
                    file.Offset = 4 + (296 * contentFilesLength);
                }
                else
                {
                    PAKContentFile fileBefore = contentFiles[i - 1];
                    file.Offset = fileBefore.Offset + fileBefore.Length;
                }
            }
        }
Exemplo n.º 6
0
        private void ReadFile()
        {
            reader.BaseStream.Position = 0;

            // Number of files packed into the .pak
            int fileCount = BitConverter.ToInt32(reader.ReadBytes(4), 0);

            for (int i = 0; i < fileCount; i++)
            {
                byte[] nameBytes = reader.ReadBytes(260);
                string name      = NameBytesToString(nameBytes);
                int    offset    = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                int    length    = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                byte[] unknown1  = reader.ReadBytes(24);
                int    unknown2  = BitConverter.ToInt32(reader.ReadBytes(4), 0);

                // Reads content
                long currentPos = reader.BaseStream.Position;
                reader.BaseStream.Position = offset;
                byte[] fileContent = reader.ReadBytes(length);

                // Resets Stream position after reading content
                reader.BaseStream.Position = currentPos;

                PAKContentFile pakFileContent = new PAKContentFile
                {
                    FilenameRaw = nameBytes,
                    Filename    = name,
                    Offset      = offset,
                    Length      = length,
                    Unknown1    = unknown1,
                    Unknown2    = unknown2,
                    FileContent = fileContent,
                };

                contentFiles.Add(pakFileContent);
            }
        }
Exemplo n.º 7
0
 public void DeleteFile(PAKContentFile file)
 /// Deletes given file
 {
     contentFiles.Remove(file);
     RewriteFile();
 }