예제 #1
0
        protected void UrlRequested(object sender, UrlRequestedArgs args)
        {
            Stream s = help_tree.GetImage(args.Url);

            if (s == null)
            {
                s = GetBrowserResourceImage("monodoc.png");
            }
            byte [] buffer = new byte [8192];
            int     n, m;

            m = 0;
            while ((n = s.Read(buffer, 0, 8192)) != 0)
            {
                args.Handle.Write(buffer, n);
                m += n;
            }
            args.Handle.Close(HTMLStreamStatus.Ok);
        }
예제 #2
0
        // Substitute the src of the images with the appropriate path
        string ProcessImages(string html_code)
        {
            //If there are no Images return fast
            int pos = html_code.IndexOf("<img", 0, html_code.Length);

            if (pos == -1)
            {
                return(html_code);
            }

            StringBuilder html = new StringBuilder();

            html.Append(html_code.Substring(0, pos));
            int    srcIni, srcEnd;
            string Img;
            Stream s;
            string path, img_name;

            while (pos != -1)
            {
                //look for the src of the img
                srcIni = html_code.IndexOf("src=\"", pos);
                srcEnd = html_code.IndexOf("\"", srcIni + 6);
                Img    = html_code.Substring(srcIni + 5, srcEnd - srcIni - 5);

                path = "NO_IMG";
                //is the img cached?
                if (cache_imgs.Contains(Img))
                {
                    path = (string)cache_imgs[Img];
                }
                else
                {
                    //obtain the stream from the compressed sources
                    s = help_tree.GetImage(Img);
                    if (s == null)
                    {
                        s = help_tree.GetImage(Img.Substring(Img.LastIndexOf("/") + 1));
                    }
                    if (s != null)
                    {
                        //write the file to a tmp directory
                        img_name = Img.Substring(Img.LastIndexOf(":") + 1);
                        path     = Path.Combine(tmpPath, img_name);
                        Directory.CreateDirectory(Path.GetDirectoryName(path));
                        FileStream file   = new FileStream(path, FileMode.Create);
                        byte[]     buffer = new byte [8192];
                        int        n;

                        while ((n = s.Read(buffer, 0, 8192)) != 0)
                        {
                            file.Write(buffer, 0, n);
                        }
                        file.Flush();
                        file.Close();
                        //Add the image to the cache
                        cache_imgs[Img] = path;
                    }
                }
                //Add the html code from <img until src="
                html.Append(html_code.Substring(pos, srcIni + 5 - pos));
                //Add the Image path
                html.Append(path);
                //Look for the next image
                pos = html_code.IndexOf("<img", srcIni);

                if (pos == -1)
                {
                    //Add the rest of the file
                    html.Append(html_code.Substring(srcEnd));
                }
                else
                {
                    //Add from " to the next <img
                    html.Append(html_code.Substring(srcEnd, pos - srcEnd)); //check this
                }
            }

            foreach (string cached in cache_imgs.Keys)
            {
                html.Replace("\"" + cached + "\"", "\"" + (string)cache_imgs[cached] + "\"");
            }

            return(html.ToString());
        }