Example #1
0
        static void Main(String[] args)
        {
            // If no arguments, show the GUI
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new PVFS21Form());
            }
            // Operate in command line mode
            else
            {
                // Make sure we got at least 3 parameters
                if (args.Length < 3)
                {
                    MessageBox.Show(
                        "Usage: WEBFS [options] <SourceDir> <ProjectDir> <OutputFile>\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.",
                        "WEBFS 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
                PVFSOutputFormat fmt     = PVFSOutputFormat.BIN;
                byte             version = 2;
                int    reserveBlock      = 64;
                String htmlTypes         = "*.htm, *.html, *.xml, *.cgi, *.bin, *.txt";
                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
                    fmt     = PVFSOutputFormat.BIN;
                    version = 2;

                    // Check for string parameters
                    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.",
                                        "WEBFS Console Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                // Set up an appropriate builder
                PVFSBuilder builder;
                // This is a dummy string , will be initialized when MDD is supported from command line
                String dummy = "Dummy";
                if (version == 2)
                {
                    builder = new PVFS2Builder(projectDir, outputFile);
                    ((PVFS2Builder)builder).DynamicTypes = htmlTypes;
                    ((PVFS2Builder)builder).NonGZipTypes = noGZipTypes;
                }
                else
                {
                    builder = new PVFSClassicBuilder(projectDir, outputFile);
                    ((PVFSClassicBuilder)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;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles the generation when clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            // Disable the button
            btnGenerate.Enabled = false;

            // Build an image
            if (radStartDir.Checked)
            {
                //// Make sure the project directory is correct
                //if(txtProjectDir.Text.Contains(txtSourceDir.Text))
                //{
                //    generationResult = false;
                //    generateLog = new List<string>();
                //    generateLog.Add("ERROR: The project directory is located in the source " +
                //        "directory.  The generator cannot run if the image is to be placed " +
                //        "in the source directory.  Please select the base MPLAB project " +
                //        "directory before continuing.");
                //    generationResult = false;
                //    ShowResultDialog("The image could not be built.");
                //    return;
                //}

                // Set up an appropriate builder
                PVFSBuilder builder;
                if (Settings.Default.OutputVersion == 2)
                {
                    builder = new PVFS2Builder(txtProjectDir.Text, txtImageName.Text);
                    ((PVFS2Builder)builder).DynamicTypes = Settings.Default.DynamicFiles;
                    ((PVFS2Builder)builder).NonGZipTypes = Settings.Default.NoCompressFiles;
                }
                else
                {
                    builder = new PVFSClassicBuilder(txtProjectDir.Text, txtImageName.Text);
                    ((PVFSClassicBuilder)builder).ReserveBlock = (UInt32)Settings.Default.ReserveBlockClassic;
                }

                // Add the files to the image
                myStatusMsg.Text = "Adding source files to image...";
                builder.AddDirectory(txtSourceDir.Text, "");

                // Generate the image
                myStatusMsg.Text = "Generating output image...";
                myProgress.Value = (chkUpload.Checked) ? 20 : 70;
                generationResult = builder.Generate(PVFSOutputFormat.BIN);

                // Indicate full progress for non-uploads
                myProgress.Value = (chkUpload.Checked) ? 20 : 120;
                Thread.Sleep(10);

                // Retrieve the log
                generateLog = builder.Log;

                // Perform the upload if needed
                if (chkUpload.Checked && generationResult)
                {
                    UploadImage(builder.GeneratedImageFileName);
                }
                else
                {
                    if (generationResult)
                    {
                        ShowResultDialog("The WEBFS image was successfully generated.");
                    }
                    else
                    {
                        ShowResultDialog("Errors were encountered while generating the PVFS image.");
                    }
                }

/*
 *              // Show a warning if index has changed
 *              if (builder.IndexUpdated)
 *              {
 *                  MessageBox.Show("The dynamic variables in your web pages have changed!\n\n" +
 *                                  "Remember to recompile your MPLAB project before continuing\n" +
 *                                  "to ensure that the project is in sync.",
 *                                  "PVFS2 Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
 *              } */
            }
            // This is just an upload
            else
            {
                generationResult = true;
                generateLog      = new List <string>();
                UploadImage(txtSourceImage.Text);
            }
        }