public void VerifyRpkHeader()
        {
            var resourcePacker = new ResourceFilePacker(RPK_FILE);

            Assert.True(resourcePacker.IsRpkPackedFile());
            Assert.True(resourcePacker.IsRpkPackedFile());
        }
        public void UnpackAllFiles()
        {
            var resourcePacker  = new ResourceFilePacker(RPK_FILE);
            var packedFileInfos = resourcePacker.GetPackedFiles();

            var unpacDir = "unpacked";

            if (!Directory.Exists(unpacDir))
            {
                Directory.CreateDirectory(unpacDir);
            }
            var unpackedFiles      = resourcePacker.UnpackFiles(packedFileInfos, $"{unpacDir}");
            var sizeCorrectedFiles = ResourceFilePacker.UpdatePackedFileData(unpackedFiles);

            Assert.True(sizeCorrectedFiles.Select(i => i.size)
                        .SequenceEqual(unpackedFiles.Select(i => i.size)));

            Assert.True(unpackedFiles.All(i => i.coldStorageLocation != default));

            var newPackedFile = "..\\..\\..\\TestData\\Sound_ManualEdits.rpk";

            ResourceFilePacker.PackFile(unpackedFiles, newPackedFile);
            Directory.Delete(unpacDir, true);

            var originalFileInfo = new FileInfo(RPK_FILE);
            var myPackedFileInfo = new FileInfo(newPackedFile);

            Assert.Equal(originalFileInfo.Length, myPackedFileInfo.Length);
        }
        private void EditPackedFileClicked(object sender, EventArgs e)
        {
            if (packedFilesListView.SelectedItem is null)
            {
                MessageBox.Show("Please select an item to edit.");
                return;
            }

            if (!SetupEditor())
            {
                return;
            }

            var openFile = new OpenFileDialog();

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                var selectedFile = _packedFiles.Single(i =>
                                                       i.name == (string)packedFilesListView.SelectedItem);

                var fileData = File.ReadAllBytes(openFile.FileName);
                var fileExt  = selectedFile.extension;
                fileExt = fileExt != "" ? $".{fileExt}" : "";

                File.WriteAllBytes($"{UNPACK_DIRECTORY}{Path.DirectorySeparatorChar}{selectedFile.name}{fileExt}", fileData);
                _packedFiles = ResourceFilePacker.UpdatePackedFileData(_packedFiles);
            }

            SelectedPackedFiledChanged(default, default);
        public void TestReadFiles()
        {
            var resourcePacker = new ResourceFilePacker(RPK_FILE);
            var fileNames      = resourcePacker.GetPackedFiles();

            Trace.WriteLine(string.Join("\n", fileNames
                                        .Select(i => $"{i.name} -> Size: {i.size}, Address: {i.location}")));
        }
        public ResrouceEditorInterface(string resrouceFile)
        {
            ReLoadRegex();

            _resrouceFile = resrouceFile;
            InitializeComponent();

            _resourcePacker = new ResourceFilePacker(_resrouceFile);
            _windowTitle    = Text;
            Text            = $"{_windowTitle} - Packed '{Path.GetFullPath(_resrouceFile)}'";
        }
        private void RepackButtonClicked(object sender, EventArgs e)
        {
            _resourcePacker.Dispose();
            var runningTask      = Task.Run(() => ResourceFilePacker.PackFile(_packedFiles, _resrouceFile));
            var loadingIndicator = new LoadingIndicator($"Packing Files... '{_resrouceFile}'", runningTask);

            loadingIndicator.ShowDialog();

            _resourcePacker = new ResourceFilePacker(_resrouceFile);
            Directory.Delete(UNPACK_DIRECTORY, true);

            repackButton.Enabled = false;
            ResetDisplayLayout();
            Text = $"{_windowTitle} - Packed '{Path.GetFullPath(_resrouceFile)}'";
        }
        public void TestReadFileCount()
        {
            var resourcePacker = new ResourceFilePacker(RPK_FILE);

            _ = resourcePacker.GetFileCount();
        }