Esempio n. 1
0
        public static void Unpack(string pegFilePath)
        {
            Console.WriteLine("Unpacking {0}:", pegFilePath);
            if (!File.Exists(pegFilePath))
            {
                Console.WriteLine("peg_pc file does not exist: {0}", pegFilePath);
                return;
            }
            string extension = Path.GetExtension(pegFilePath).ToLower();
            bool   xbox      = (extension == ".peg_xbox2");

            if (!(extension == ".peg_pc" || extension == ".peg_xbox2"))
            {
                Console.WriteLine("File is not a peg_pc file: {0}", pegFilePath);
                return;
            }

            string pegDataFilePath = xbox ? Path.ChangeExtension(pegFilePath, "g_peg_xbox2") : Path.ChangeExtension(pegFilePath, "g_peg_pc");
            string pegDescFilePath = Path.ChangeExtension(pegFilePath, "peg_desc");

            if (!File.Exists(pegDataFilePath))
            {
                Console.WriteLine("g_peg_pc file does not exist: {0}", pegDataFilePath);
                Console.WriteLine("Did you copy it into the same directory as {0}?", pegFilePath);
                return;
            }

            PegFile    pegFile           = new PegFile(xbox);
            FileStream pegFileStream     = new FileStream(pegFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            FileStream pegDataFileStream = new FileStream(pegDataFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            pegFile.Read(pegFileStream);

            string extractionPath = Path.GetDirectoryName(pegFilePath);

            Console.Write("Writing peg description to: {0}... ", pegDescFilePath);
            Console.WriteLine(" done.");
            WritePegDescription(pegFile, pegDescFilePath);
            Console.WriteLine("Unpacking images:");
            UnpackImages(pegFile, extractionPath, pegDataFileStream);
            pegFileStream.Close();
            pegDataFileStream.Close();
            Console.WriteLine();
            Console.WriteLine("Finished unpacking.");
        }
Esempio n. 2
0
        public void ReadFormatData()
        {
            switch (FileType)
            {
            case RfgFileTypes.None:
                return;

            case RfgFileTypes.Packfile:
                PackfileData = new Packfile(false);
                PackfileData.ReadMetadata(FilePath);
                PackfileData.DirectoryEntries.Sort((entry1, entry2) => string.Compare(entry1.FileName, entry2.FileName, StringComparison.Ordinal));
                PackfileData.ParseAsmFiles($"{CachePath}{Filename}\\");
                break;

            case RfgFileTypes.Container:
                PackfileData = new Packfile(false);
                PackfileData.ReadMetadata(FilePath);
                break;

            case RfgFileTypes.Primitive:
                string extension = Path.GetExtension(Filename);
                if (extension == ".cpeg_pc" || extension == ".cvbm_pc")
                {
                    if (!PathHelpers.TryGetGpuFileNameFromCpuFile(FilePath, out string gpuFileName))
                    {
                        return;
                    }

                    string basePath    = Path.GetDirectoryName(FilePath);
                    string gpuFilePath = $"{basePath}\\{gpuFileName}";

                    //Todo: Change this to check editor or project cache depending on CacheFile location
                    //Ensure gpu file is extracted
                    if (!ProjectManager.TryGetCacheFile(gpuFileName, ParentName, out _, true))
                    {
                        return;
                    }

                    PegData = new PegFile();
                    PegData.Read(FilePath, gpuFilePath);
                }
                //Todo: Add checks for primitive type, and primitive handling code
                break;
            }
        }
        private void OpenTextureFile_OnClick(object sender, RoutedEventArgs e)
        {
            _fileBrowser.IsFolderPicker = false;
            if (_fileBrowser.ShowDialog() == CommonFileDialogResult.Ok)
            {
                string cpuFilePath = _fileBrowser.FileName;
                if (!File.Exists(cpuFilePath))
                {
                    return;
                }

                var cpuFileInfo = new FileInfo(cpuFilePath);

                if (cpuFileInfo.Extension == ".cpeg_pc")
                {
                    var gpuFileInfo = new FileInfo(cpuFileInfo.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(cpuFilePath) + ".gpeg_pc");
                    _peg = new PegFile(cpuFilePath, gpuFileInfo.FullName);
                    _peg.Read();
                }
                else if (cpuFileInfo.Extension == ".cvbm_pc")
                {
                    var gpuFileInfo = new FileInfo(cpuFileInfo.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(cpuFilePath) + ".gvbm_pc");
                    _peg = new PegFile(cpuFilePath, gpuFileInfo.FullName);
                    _peg.Read();
                }
                else
                {
                    throw new Exception($"{cpuFileInfo.Extension} is an invalid file extension for peg files!");
                }

                UpdateWindowTitle();
                PopulateTreeView();
                SetSelectedTexture(0);
                UpdateInfoPanel();
            }
        }