Beispiel #1
0
        public CriAcbFile(FileStream fs, long offset, bool includeCueIdInFileName)
        {
            // initialize UTF
            this.Initialize(fs, offset);

            // initialize ACB specific items
            this.InitializeCueList(fs);
            this.InitializeCueNameToWaveformMap(fs, includeCueIdInFileName);

            // initialize internal AWB
            if (this.InternalAwbFileSize > 0)
            {
                if (CriAfs2Archive.IsCriAfs2Archive(fs, (long)this.InternalAwbFileOffset))
                {
                    this.InternalAwb = new CriAfs2Archive(fs, (long)this.InternalAwbFileOffset);
                }
                else if (CriCpkArchive.IsCriCpkArchive(fs, (long)this.InternalAwbFileOffset))
                {
                    this.InternalCpk = new CriCpkArchive();
                    this.InternalCpk.Initialize(fs, (long)this.InternalAwbFileOffset, true);
                }
            }

            // initialize external AWB

            // @TODO: This isn't correct for files with CPKs
            if ((this.StreamAwbAfs2HeaderSize > 0) ||
                (!ByteConversion.IsZeroFilledByteArray(this.StreamAwbHash)))
            {
                // get external file name
                this.StreamfilePath = this.GetStreamfilePath();

                // get file type
                using (FileStream awbFs = File.Open(this.StreamfilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    // AWB
                    if (CriAfs2Archive.IsCriAfs2Archive(awbFs, 0))
                    {
                        this.ExternalAwb = new CriAfs2Archive(awbFs, 0);
                    }
                    // CPK
                    else if (CriCpkArchive.IsCriCpkArchive(awbFs, 0))
                    {
                        this.ExternalCpk = new CriCpkArchive();
                        this.ExternalCpk.Initialize(awbFs, 0, true);
                    }
                }
            }
        }
Beispiel #2
0
        protected CriAfs2Archive InitializeExternalAwbArchive()
        {
            CriAfs2Archive afs2 = null;

            string awbDirectory;
            string awbMask;
            string acbBaseFileName;

            string[] awbFiles;

            byte[] awbHashStored;
            byte[] awbHashCalculated;

            awbDirectory = Path.GetDirectoryName(this.SourceFile);

            // try format 1
            acbBaseFileName = Path.GetFileNameWithoutExtension(this.SourceFile);
            awbMask         = String.Format(AWB_FORMAT1, acbBaseFileName);
            awbFiles        = Directory.GetFiles(awbDirectory, awbMask, SearchOption.TopDirectoryOnly);

            if (awbFiles.Length < 1)
            {
                // try format 2
                awbMask  = String.Format(AWB_FORMAT2, acbBaseFileName);
                awbFiles = Directory.GetFiles(awbDirectory, awbMask, SearchOption.TopDirectoryOnly);
            }

            if (awbFiles.Length < 1)
            {
                // try format 3
                awbMask  = String.Format(AWB_FORMAT3, acbBaseFileName);
                awbFiles = Directory.GetFiles(awbDirectory, awbMask, SearchOption.TopDirectoryOnly);
            }

            // file not found
            if (awbFiles.Length < 1)
            {
                throw new FileNotFoundException(String.Format("Cannot find AWB file. Please verify corresponding AWB file is named '{0}', '{1}', or '{2}'.",
                                                              String.Format(AWB_FORMAT1, acbBaseFileName), String.Format(AWB_FORMAT2, acbBaseFileName), String.Format(AWB_FORMAT3, acbBaseFileName)));
            }

            if (awbFiles.Length > 1)
            {
                throw new FileNotFoundException(String.Format("More than one matching AWB file for this ACB. Please verify only one AWB file is named '{1}' or '{2}'.",
                                                              String.Format(AWB_FORMAT1, acbBaseFileName), String.Format(AWB_FORMAT2, acbBaseFileName)));
            }

            // initialize AFS2 file
            using (FileStream fs = File.Open(awbFiles[0], FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                awbHashStored = this.StreamAwbHash;

                if (awbHashStored.Length == 0x10) // MD5, hash in newer format unknown
                {
                    // validate MD5 checksum
                    awbHashCalculated = ByteConversion.GetBytesFromHexString(ChecksumUtil.GetMd5OfFullFile(fs));

                    if (!ParseFile.CompareSegment(awbHashCalculated, 0, awbHashStored))
                    {
                        throw new FormatException(String.Format("AWB file, <{0}>, did not match checksum inside ACB file.", Path.GetFileName(fs.Name)));
                    }
                }

                afs2 = new CriAfs2Archive(fs, 0);
            }

            return(afs2);
        }