Esempio n. 1
0
        }// Shutdown

        //-------------------------------------------------
        // GenHTMLFile
        //
        // This function will load an HTML file, parse it,
        // save it into a temporary file, and return that
        // temporary file's name.
        // The function will look for <*-#-*> where # can be
        // any number. It is then substituted with that phrase
        // found in that index in the String array passed into it.
        //-------------------------------------------------
        static internal String GenHTMLFile(String sFilename, String[] args)
        {
            String sHTMLContents = CResourceStore.GetHTMLFile(sFilename);

            if (args != null)
            {
                // Let's do some escaping....
                // We don't want to escape any '<!--' or '-->' blocks, but everything
                // else is open game

                // Ok, this is a semi-hack, but we don't want to do this for the
                // 'intro' page of the UI. We dynamically generate some HTML links
                // that can't be stomped on by this.

                if (!sFilename.Equals("NET_HTML"))
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] != null && !args[i].Equals("<!--") && !args[i].Equals("-->"))
                        {
                            args[i] = HttpUtility.HtmlEncode(args[i]);
                        }
                    }
                }


                // Run through the strings we're supposed to add in looking for any international characters
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] != null)
                    {
                        for (int j = 0; j < args[i].Length; j++)
                        {
                            if (((uint)args[i][j]) > 255)
                            {
                                // Ok, so we want to put in an international character. Generally, the font
                                // that the HTML renderer uses does not support international characters,
                                // so we'll tell the renderer to use a different font for this string.

                                //args[i] = "<span style='font-family:\"MS Mincho\"'>" + args[i] + "</span>";
                                args[i] = "<span style='font-family:\"MS UI Gothic\"'>" + args[i] + "</span>";
                                // We don't need to look at this string anymore... let's go
                                // look at the next one.
                                break;
                            }
                        }
                    }
                }
            }

            // Make our substitutions
            StringBuilder sb = new StringBuilder(sHTMLContents);

            if (args != null)
            {
                int iLen = args.Length;
                for (int i = 0; i < iLen; i++)
                {
                    sb.Replace("<*-" + i + "-*>", args[i]);
                }
            }

            // Now run through and add in any GIFs we have laying around
            // The GIF filenames will all be marked with negative numbers
            int iNumGifs = m_scGifs.Count;

            for (int i = -1; i >= iNumGifs * -1; i--)
            {
                // We do the funky (i*-1)-1 to make our i postive, zero
                // based... so if i = -1, then we go to the 0 index, if i = -2,
                // we go to the 1 index, and so on.
                sb.Replace("<*-" + i + "-*>", m_scGifs[(i * -1) - 1]);
            }


            String sOutFileName = Path.GetTempFileName().ToLower(CultureInfo.InvariantCulture);

            // Replace the <*-9999-*> with the name of this file
            sb.Replace("<*-9999-*>", sOutFileName);



            // Write Parsed HTMLFile
            StreamWriter sw = new StreamWriter(File.Create(sOutFileName));

            sw.Write(sb.ToString());
            sw.Close();
            m_scPages.Add(sOutFileName);

            return(sOutFileName);
        }// GenHTMLFile