Example #1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Saves CAS file
        public static void CASSave(Stream in_file, ProgramStorage in_storage)
        {
            using (BinaryWriter cas_file = new BinaryWriter(in_file))
            {
                CASUPMHeaderType         upm_header     = CreateUPMHeader(in_storage);
                CASProgramFileHeaderType program_header = CreateProgramFileHeader(in_storage);

                cas_file.Write(upm_header);
                cas_file.Write(program_header);
                cas_file.Write(in_storage.Data, 0, in_storage.Length);
            }
        }
Example #2
0
        ///////////////////////////////////////////////////////////////////////////////
        // Initizes UPM header
        public static CASUPMHeaderType CreateUPMHeader(ProgramStorage in_storage)
        {
            CASUPMHeaderType header = new CASUPMHeaderType();

            ushort cas_length = (ushort)(in_storage.Length + Marshal.SizeOf(typeof(CASUPMHeaderType)) + Marshal.SizeOf(typeof(CASProgramFileHeaderType)));

            header.FileType       = CASBlockHeaderFileUnbuffered;
            header.CopyProtect    = (byte)((in_storage.CopyProtect) ? 0xff : 0x00);
            header.BlockNumber    = (byte)(cas_length / 128);
            header.LastBlockBytes = (byte)(cas_length % 128);

            return(header);
        }
Example #3
0
        ///////////////////////////////////////////////////////////////////////////////
        // Loads CAS file
        public static void CASLoad(Stream in_file, ProgramStorage in_storage)
        {
            CASUPMHeaderType         upm_header     = new CASUPMHeaderType();
            CASProgramFileHeaderType program_header = new CASProgramFileHeaderType();

            // open CAS file
            using (BinaryReader cas_file = new BinaryReader(in_file))
            {
                // load UPM header
                cas_file.Read(upm_header);

                // load program header
                cas_file.Read(program_header);

                // Check validity
                if (!CASCheckHeaderValidity(program_header))
                {
                    throw new FileFormatException("Invalid CAS header");
                }

                if (!CASCheckUPMHeaderValidity(upm_header))
                {
                    throw new FileFormatException("Invalid UPM header");
                }

                cas_file.Read(in_storage.Data, 0, program_header.FileLength);

                in_storage.Length      = program_header.FileLength;
                in_storage.CopyProtect = (upm_header.CopyProtect != 0);
                in_storage.AutoStart   = (program_header.Autorun != 0);
                in_storage.SetFileTypeByte(program_header.FileType);
            }

            // generate TVC filename
            //PCToTVCFilename(g_db_file_name, in_file_name);
        }
Example #4
0
 ///////////////////////////////////////////////////////////////////////////////
 // Checks UPM header validity
 public static bool CASCheckUPMHeaderValidity(CASUPMHeaderType in_header)
 {
     return(in_header.FileType == CASBlockHeaderFileUnbuffered);
 }