Ejemplo n.º 1
0
        public PsbFile(string psbFilePath)
        {
            try
            {
                compressedPsbFile = new MdfPsbFile(psbFilePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not successfully read PSB file: " + ex.Message);
                return;
            }

            // Get the psb data from the file decompressed by the MdfPsbFile
            header  = new PsbHeader(compressedPsbFile.DecompressedPath);
            psbData = File.ReadAllBytes(compressedPsbFile.DecompressedPath);

            names   = new List <string>();
            strings = new List <string>();

            //Console.WriteLine(header.ToString());

            // Unpack the structures of the file
            UnpackNames();

            UnpackStrings();

            UnpackChunks();

            UnpackEntries();

            // Attempt to read in the alldata.bin file
            string binPath = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(psbFilePath)) + ".bin";

            Console.WriteLine("Checking for PSB data file " + binPath + "...");

            if (!File.Exists(binPath))
            {
                throw new FileNotFoundException("Could not find PSB data file at " + binPath + ". Please ensure that your filename is correct.");
            }

            binData  = File.ReadAllBytes(binPath);
            subfiles = new List <byte[]>();

            SplitSubfiles();

            if (romData != null && !String.IsNullOrEmpty(romPath))
            {
                Console.WriteLine("Decompressing rom...");

                // Remove the temp file if it exists
                if (File.Exists(romPath))
                {
                    File.Delete(romPath);
                }

                File.WriteAllBytes(romPath, romData);

                MdfPsbFile romMdfFile = new MdfPsbFile(romPath);

                decompressedPath = romMdfFile.DecompressedPath;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PsbFile"/> class.
        /// </summary>
        /// <param name="psbFilePath">path to the PSB file.</param>
        /// <param name="verbose">whether to provide verbose output.</param>
        public PsbFile(string psbFilePath, bool verbose = false)
        {
            try
            {
                if (verbose)
                {
                    Console.WriteLine("Attempting to read PSB file from {0}...", psbFilePath);
                }

                this.compressedPsbFile = new MdfPsbFile(psbFilePath, verbose);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not successfully read PSB file: " + ex.Message);
                return;
            }

            // Get the psb data from the file decompressed by the MdfPsbFile
            this.header  = new PsbHeader(this.compressedPsbFile.DecompressedPath);
            this.psbData = File.ReadAllBytes(this.compressedPsbFile.DecompressedPath);

            this.names   = new List <string>();
            this.strings = new List <string>();

            if (verbose)
            {
                Console.WriteLine("PSB Header information:\n{0}", this.header.ToString());
            }

            // Unpack the structures of the file
            this.UnpackNames();

            this.UnpackStrings();

            this.UnpackChunks();

            this.UnpackEntries();

            // Attempt to read in the alldata.bin file
            string absolutePath = Path.GetFullPath(psbFilePath);
            string binPath      = Path.Combine(Path.GetDirectoryName(absolutePath), Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(psbFilePath)) + ".bin");

            Console.WriteLine("Checking for PSB data file " + binPath + "...");

            if (!File.Exists(binPath))
            {
                throw new FileNotFoundException("Could not find PSB data file at " + binPath + ". Please ensure that your filename is correct.");
            }

            this.binData  = File.ReadAllBytes(binPath);
            this.subfiles = new List <byte[]>();

            this.SplitSubfiles(verbose);

            if (this.romData != null && !string.IsNullOrEmpty(this.romName))
            {
                Console.WriteLine("Decompressing rom...");

                this.romPath = Path.Combine(Path.GetDirectoryName(absolutePath), this.romName);

                // Remove the temp file if it exists
                if (File.Exists(this.romPath))
                {
                    File.Delete(this.romPath);
                }

                File.WriteAllBytes(this.romPath, this.romData);

                MdfPsbFile romMdfFile = new MdfPsbFile(this.romPath);

                this.decompressedPath = romMdfFile.DecompressedPath;
            }
        }