Ejemplo n.º 1
0
        public override bool Generate(MPFSOutputFormat format)
        {
            // Start with nothing
            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);
            }

            // Generate based on format
            try
            {
                switch (format)
                {
                case MPFSOutputFormat.BIN:
                    return(GenerateBIN(localPath + localFile));

                case MPFSOutputFormat.C18:
                case MPFSOutputFormat.C32:
                    return(GenerateC(localPath + localFile));

                case MPFSOutputFormat.ASM30:
                    return(GenerateASM(localPath + localFile));

                default:
                    log.Add("\r\nERROR: Invalid output format was specified.");
                    return(false);
                }
            }
            catch (Exception e)
            {
                log.Add("\r\nERROR: " + e.Message);
                return(false);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Generates the MPFS image and any necessary support files
 /// </summary>
 public abstract bool Generate(MPFSOutputFormat format);
Ejemplo n.º 4
0
Archivo: MPFSlib.cs Proyecto: bend/PIC
        public override bool Generate(MPFSOutputFormat format)
        {
            // Start with nothing
            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;

            // Generate based on format
            try
            {
                switch (format)
                {
                    case MPFSOutputFormat.BIN:
                        return GenerateBIN(localPath + localFile);
                    case MPFSOutputFormat.C18:
                    case MPFSOutputFormat.C32:
                        return GenerateC(localPath + localFile);
                    case MPFSOutputFormat.ASM30:
                        return GenerateASM(localPath + localFile);
                    default:
                        log.Add("\r\nERROR: Invalid output format was specified.");
                        return false;
                }
            }
            catch (Exception e)
            {
                log.Add("\r\nERROR: " + e.Message);
                return false;
            }
        }
Ejemplo n.º 5
0
Archivo: MPFSlib.cs Proyecto: bend/PIC
 /// <summary>
 /// Generates the MPFS image and any necessary support files
 /// </summary>
 public abstract bool Generate(MPFSOutputFormat format);
Ejemplo n.º 6
0
Archivo: MPFSlib.cs Proyecto: bend/PIC
        /// <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;
        }
Ejemplo n.º 7
0
        static void Main(String[] args)
        {
            // If no arguments, show the GUI
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MPFS21Form());
            }
            // Operate in command line mode
            else
            {
                // Make sure we got at least 3 parameters
                if (args.Length < 3)
                {
                    MessageBox.Show(
                        "Usage: MPFS2 [options] <SourceDir> <ProjectDir> <OutputFile>\n" +
                        "    /BIN\t\t(/b)\t: Output a BIN image (Default)\n" +
                        "    /C18\t\t(/c)\t: Output a C18 image\n" +
                        "    /ASM30\t(/s)\t: Output an ASM30 image\n" +
                        "    /C32\t\t(/x)\t: Output a C32 image\n" +
                        "    /classic\t\t(/1)\t: MPFSClassic format\n" +
                        "    /mpfs2\t\t(/2)\t: MPFS2 format (Default)\n" +
                        "    /reserve #\t(/r #)\t: Reserved space for Classic BINs (Default 64)\n" +
                        "    /html \"...\"\t(/h)\t: Dynamic file types (\"*.htm, *.html, *.xml, *.cgi\")\n" +
                        "    /xgzip \"...\"\t(/z)\t: Non-compressible types (\"snmp.bib, *.inc\")\n\n" +
                        "SourceDir, ProjectDir, and OutputFile are required and should be enclosed in quotes.\n" +
                        "OutputFile is placed relative to ProjectDir and *CANNOT* be a full path name.",
                        "MPFS2 Console Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                // Locate the parameters
                String sourceDir  = args[args.Length - 3];
                String projectDir = args[args.Length - 2];
                String outputFile = args[args.Length - 1];

                // Set up some defaults
                MPFSOutputFormat fmt     = MPFSOutputFormat.BIN;
                byte             version = 2;
                int    reserveBlock      = 64;
                String htmlTypes         = "*.htm, *.html, *.xml, *.cgi";
                String noGZipTypes       = "*.inc, snmp.bib";

                // Process each command line argument
                for (int i = 0; i < args.Length - 3; i++)
                {
                    String arg = args[i].ToLower();

                    // Check for output format parameters
                    if (arg == "/bin" || arg == "/b")
                    {
                        fmt = MPFSOutputFormat.BIN;
                    }
                    else if (arg == "/c18" || arg == "/c")
                    {
                        fmt = MPFSOutputFormat.C18;
                    }
                    else if (arg == "/asm30" || arg == "/s")
                    {
                        fmt = MPFSOutputFormat.ASM30;
                    }
                    else if (arg == "/c32" || arg == "/x")
                    {
                        fmt = MPFSOutputFormat.C32;
                    }
                    else if (arg == "/classic" || arg == "/1")
                    {
                        version = 1;
                    }
                    else if (arg == "/mpfs2" || arg == "/2")
                    {
                        version = 2;
                    }

                    // Check for string parameters
                    else if (arg == "/reserve" || arg == "/r")
                    {
                        reserveBlock = Convert.ToInt32(args[++i]);
                    }
                    else if (arg == "/html" || arg == "/h")
                    {
                        htmlTypes = args[++i];
                    }
                    else if (arg == "/xgzip" || arg == "/z")
                    {
                        noGZipTypes = args[++i];
                    }

                    else
                    {
                        MessageBox.Show("The command-line option \"" + arg + "\" was not recognized.",
                                        "MPFS2 Console Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                // Set up an appropriate builder
                MPFSBuilder builder;
                // This is a dummy string , will be initialized when MDD is supported from command line
                String dummy = "Dummy";
                if (version == 2)
                {
                    builder = new MPFS2Builder(projectDir, outputFile);
                    ((MPFS2Builder)builder).DynamicTypes = htmlTypes;
                    ((MPFS2Builder)builder).NonGZipTypes = noGZipTypes;
                }
                else
                {
                    builder = new MPFSClassicBuilder(projectDir, outputFile);
                    ((MPFSClassicBuilder)builder).ReserveBlock = (UInt32)reserveBlock;
                }

                // Add the files to the image and generate the image
                builder.AddDirectory(sourceDir, "");

                // Generate the image and trap errors
                if (!builder.Generate(fmt))
                {
                    LogWindow dlg = new LogWindow();
                    dlg.Image   = SystemIcons.Error;
                    dlg.Message = "An error was encountered during generation.";
                    dlg.Log     = builder.Log;
                    dlg.ShowDialog();
                    return;
                }
            }
        }
Ejemplo n.º 8
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;
        }