Пример #1
0
        /// <summary>
        /// Generates an image in the specified format
        /// </summary>
        /// <param name="format">One of the MPFSOutputFormat constants indicating the format</param>
        /// <returns>true if generation was successful, false otherwise</returns>
        public override bool Generate(MPFSOutputFormat format)
        {
            // Start with nothing as the output name
            generatedImageName = null;

            // Make sure all paths exist
            if (!Directory.Exists(localPath))
            {
                log.Add("\r\nERROR: Output directory \"" + localPath + "\" does not exist!");
                return false;
            }

            // Make sure we have some files
            if (files.Count == 0)
                return false;

            try
            {
                // Write any index files that have changed
                indexUpdated = dynVarParser.WriteIndices();
            }
            catch (Exception e)
            {
                log.Add("ERROR: " + e.Message);
                return false;
            }

            // Determine address of each file and string
            UInt32 numFiles = (UInt32)files.Count;
            UInt32 lenHeader = 8;
            UInt32 lenHashes = 2 * numFiles;
            UInt32 lenFAT = 22 * numFiles;
            UInt32 baseAddr = lenHeader + lenHashes + lenFAT;
            foreach (MPFSFileRecord file in files)
            {
                file.locStr = baseAddr;
                baseAddr += (UInt32)file.FileName.Length + 1;
            }
            foreach (MPFSFileRecord file in files)
            {
                file.locData = baseAddr;
                baseAddr += (UInt32)file.data.Length;
            }

            // Set up the writer
            try
            {
                MPFS2Writer w;
                switch (format)
                {
                    case MPFSOutputFormat.C18:
                    case MPFSOutputFormat.C32:
                        w = new MPFS2C18Writer(localPath + localFile);
                        break;
                    case MPFSOutputFormat.ASM30:
                        w = new MPFS2ASM30Writer(localPath + localFile);
                        break;
                    default:
                        w = new MPFS2BINWriter(localPath + localFile);
                        break;
                }

                // Write the image
                w.Write("MPFS");
                w.Write((byte)0x02);
                w.Write((byte)0x01);
                w.Write((UInt16)files.Count);
                foreach (MPFSFileRecord file in files)
                    w.Write((UInt16)file.nameHash);
                UInt16 flags;
                foreach (MPFSFileRecord file in files)
                {
                    w.Write(file.locStr);
                    w.Write(file.locData);
                    w.Write((UInt32)file.data.Length);
                    w.Write((UInt32)((file.fileDate.ToUniversalTime().Ticks - 621355968000000000) / 10000000));
                    w.Write((UInt32)0);
                    flags = 0;
                    if (file.hasIndex)
                        flags |= MPFS2_FLAG_HASINDEX;
                    if (file.isZipped)
                        flags |= MPFS2_FLAG_ISZIPPED;
                    w.Write(flags);
                }
                foreach (MPFSFileRecord file in files)
                {
                    w.Write(file.FileName);
                    w.Write((byte)0x00);
                }
                foreach (MPFSFileRecord file in files)
                    w.Write(file.data);

                w.Close();
                generatedImageName = w.imageName;

                log.Add("\r\nGENERATED MPFS2 IMAGE: " + w.ImageLength + " bytes");
            }
            catch (Exception e)
            {
                log.Add("\r\nERROR: " + e.Message);
                return false;
            }

            return true;
        }
Пример #2
0
        /// <summary>
        /// Generates an image in the specified format
        /// </summary>
        /// <param name="format">One of the MPFSOutputFormat constants indicating the format</param>
        /// <returns>true if generation was successful, false otherwise</returns>
        public override bool Generate(MPFSOutputFormat format)
        {
            // Start with nothing as the output name
            generatedImageName = null;

            // Make sure all paths exist
            if (!Directory.Exists(localPath))
            {
                log.Add("\r\nERROR: Output directory \"" + localPath + "\" does not exist!");
                return(false);
            }

            // Make sure we have some files
            if (files.Count == 0)
            {
                return(false);
            }

            try
            {
                // Write any index files that have changed
                indexUpdated = dynVarParser.WriteIndices();
            }
            catch (Exception e)
            {
                log.Add("ERROR: " + e.Message);
                return(false);
            }

            // Determine address of each file and string
            UInt32 numFiles  = (UInt32)files.Count;
            UInt32 lenHeader = 8;
            UInt32 lenHashes = 2 * numFiles;
            UInt32 lenFAT    = 22 * numFiles;
            UInt32 baseAddr  = lenHeader + lenHashes + lenFAT;

            foreach (MPFSFileRecord file in files)
            {
                file.locStr = baseAddr;
                baseAddr   += (UInt32)file.FileName.Length + 1;
            }
            foreach (MPFSFileRecord file in files)
            {
                file.locData = baseAddr;
                baseAddr    += (UInt32)file.data.Length;
            }

            // Set up the writer
            try
            {
                MPFS2Writer w;
                switch (format)
                {
                case MPFSOutputFormat.C18:
                case MPFSOutputFormat.C32:
                    w = new MPFS2C18Writer(localPath + localFile);
                    break;

                case MPFSOutputFormat.ASM30:
                    w = new MPFS2ASM30Writer(localPath + localFile);
                    break;

                default:
                    w = new MPFS2BINWriter(localPath + localFile);
                    break;
                }

                // Write the image
                w.Write("MPFS");
                w.Write((byte)0x02);
                w.Write((byte)0x01);
                w.Write((UInt16)files.Count);
                foreach (MPFSFileRecord file in files)
                {
                    w.Write((UInt16)file.nameHash);
                }
                UInt16 flags;
                foreach (MPFSFileRecord file in files)
                {
                    w.Write(file.locStr);
                    w.Write(file.locData);
                    w.Write((UInt32)file.data.Length);
                    w.Write((UInt32)((file.fileDate.ToUniversalTime().Ticks - 621355968000000000) / 10000000));
                    w.Write((UInt32)0);
                    flags = 0;
                    if (file.hasIndex)
                    {
                        flags |= MPFS2_FLAG_HASINDEX;
                    }
                    if (file.isZipped)
                    {
                        flags |= MPFS2_FLAG_ISZIPPED;
                    }
                    w.Write(flags);
                }
                foreach (MPFSFileRecord file in files)
                {
                    w.Write(file.FileName);
                    w.Write((byte)0x00);
                }
                foreach (MPFSFileRecord file in files)
                {
                    w.Write(file.data);
                }

                w.Close();
                generatedImageName = w.imageName;

                log.Add("\r\nGENERATED MPFS2 IMAGE: " + w.ImageLength + " bytes");
            }
            catch (Exception e)
            {
                log.Add("\r\nERROR: " + e.Message);
                return(false);
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Generates an image in the specified format
        /// </summary>
        /// <param name="format">One of the MPFSOutputFormat constants indicating the format</param>
        /// <returns>true if generation was successful, false otherwise</returns>
        public override bool Generate(MPFSOutputFormat format)
        {
            // Start with nothing as the output name
            generatedImageName = null;

            // Make sure all paths exist
            if (!Directory.Exists(localPath))
            {
                log.Add("\r\nERROR: Output directory \"" + localPath + "\" does not exist!");
                return false;
            }

            // Make sure we have some files
            if (files.Count == 0)
                return false;

            try
            {
                // Write any index files that have changed
                indexUpdated = dynVarParser.WriteIndices();
            }
            catch (Exception e)
            {
                log.Add("ERROR: " + e.Message);
                return false;
            }

            // Determine address of each file and string
            UInt32 numFiles = (UInt32)files.Count;
            UInt32 lenHeader = 8;
            UInt32 lenHashes = 2 * numFiles;
            UInt32 lenFAT = 22 * numFiles;
            UInt32 baseAddr = lenHeader + lenHashes + lenFAT;
            UInt32 counter=0;
            UInt32 loopCntr=0;
            UInt32 numFileRecrds = 0;

            foreach (MPFSFileRecord file in files)
            {
                file.locStr = baseAddr;
                baseAddr += (UInt32)file.FileName.Length + 1;
            }
            foreach (MPFSFileRecord file in files)
            {
                file.locData = baseAddr;
                baseAddr += (UInt32)file.data.Length;
            }

            // Set up the writer
            try
            {
                MPFS2Writer w;
                switch (format)
                {
                    case MPFSOutputFormat.C18:
                    case MPFSOutputFormat.C32:
                        w = new MPFS2C18Writer(localPath + localFile);
                        WriteImage(w);
                        break;
                    case MPFSOutputFormat.ASM30:
                        w = new MPFS2ASM30Writer(localPath + localFile);
                        WriteImage(w);
                        break;
                    case MPFSOutputFormat.MDD:
                            MDDWriter(localPath);
                        break;
                    default:
                        w = new MPFS2BINWriter(localPath + localFile);
                        WriteImage(w);
                        break;
                }
            }
            catch (Exception e)
            {
                log.Add("\r\nERROR: " + e.Message);
                return false;
            }

            return true;
        }