Fix #362058. Check for illegal length in PPT filter.
[beagle.git] / Renderers / DataBarn.cs
blob60b37c0e29285d10ef2359c9b544774ca6ea6c71
1 //
2 // DataBarn.cs
3 //
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
25 using System;
26 using System.Collections;
27 using System.IO;
28 using System.Reflection;
30 using BU = Beagle.Util;
32 namespace Beagle {
34 public class DataBarn {
36 // Don't let anyone instantiate a DataBarn.
37 private DataBarn () { }
39 static public Stream GetStream (string name)
41 if (name.StartsWith ("file://")) {
42 string path = name.Substring ("file://".Length);
44 if (! File.Exists (path)) {
45 Console.WriteLine ("Can't get file '{0}'", path);
46 return null;
49 return new FileStream (path, FileMode.Open, FileAccess.Read);
52 if (name.StartsWith ("mime-icon:")) {
53 string mimeType = name.Substring ("mime-icon:".Length);
54 Gtk.IconSize size = (Gtk.IconSize) 48;
55 string path = BU.GnomeIconLookup.LookupMimeIcon (mimeType, size);
56 return new FileStream (path, FileMode.Open, FileAccess.Read);
59 // Otherwise, assume the data is attached to the
60 // assembly as a resource.
62 Assembly assembly = Assembly.GetExecutingAssembly ();
63 Stream s = assembly.GetManifestResourceStream (name);
64 if (s == null)
65 Console.WriteLine ("Couldn't get resource '{0}'", name);
66 return s;
69 static public StreamReader GetText (string name)
71 // FIXME: could try to sanity check this by name,
72 // warning if (for example) you tried to get a .png file
73 // as text.
74 Stream s = GetStream (name);
75 return s != null ? new StreamReader (s) : null;
78 static public Gdk.Pixbuf GetPixbuf (string name)
80 Stream s = GetStream (name);
81 return s != null ? new Gdk.Pixbuf (s) : null;
84 static public Gtk.Widget GetImageWidget (string name)
86 Gdk.Pixbuf pixbuf = GetPixbuf (name);
87 return pixbuf != null ? new Gtk.Image (pixbuf) : null;