Example #1
0
        /// <summary>
        /// Get an image from the assembly; caches the image.
        /// </summary>
        public static Image GetEmbeddedImage(string file)
        {
            Image ret = null;

            try
            {
                if (pp == null)
                {
                    pp = new PlayerParser("");
                }
                if (ImageMap.ContainsKey(file))
                {
                    ret = ImageMap[file];
                }
                else
                {
                    System.IO.Stream s =
                        pp.GetType().Assembly.GetManifestResourceStream(file);
                    if (s != null)
                    {
                        ret = Image.FromStream(s);
                    }
                    sImageMap.Add(file, ret);
                }
            }
            catch (Exception)
            {
                AddError("Error getting image " + file);
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Gets an embedded text file.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static String GetEmbeddedTextFile(string file)
        {
            String ret = null;

            try
            {
                if (pp == null)
                {
                    pp = new PlayerParser("");
                }
                System.IO.Stream s      = null;
                StreamReader     reader = null;
                try
                {
                    string[] embeddedFiles = pp.GetType().Assembly.GetManifestResourceNames();
                    for (int i = 0; i < embeddedFiles.Length; i++)
                    {
                        if (embeddedFiles[i].EndsWith(file, StringComparison.InvariantCultureIgnoreCase))
                        {
                            s = pp.GetType().Assembly.GetManifestResourceStream(embeddedFiles[i]);
                            break;
                        }
                    }
                    if (s != null)
                    {
                        reader = new StreamReader(s);
                        ret    = reader.ReadToEnd();
                    }
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Dispose();
                    }
                    if (s != null)
                    {
                        s.Dispose();
                    }
                }
            }
            catch (Exception)
            {
                AddError("Error getting file " + file);
            }
            return(ret);
        }