Ejemplo n.º 1
0
        public static Texture2D GetTexture(string relativePath)
        {
            if (relativePath == "")
            {
                return(null);
            }
            if (textureCache == null)
            {
                textureCache = new Dictionary <string, TexFileInfo> ();
            }

            string path = Path.GetFullPath(Path.Combine(SafeHouse.ArchiveFolder, relativePath));

            if (!path.StartsWith(SafeHouse.ArchiveFolder, StringComparison.Ordinal))
            {
                throw new KOSInvalidPathException("Path refers to parent directory", path);
            }

            TexFileInfo t;

            if (textureCache.TryGetValue(relativePath, out t))
            {
                if (t.texture != null)
                {
                    var curInfo = new FileInfo(t.info.FullName);
                    if (curInfo.LastWriteTime == t.info.LastWriteTime)
                    {
                        return(t.texture);
                    }
                }
            }
            else
            {
                t = new TexFileInfo();
                textureCache.Add(relativePath, t);
            }

            var r = new Texture2D(0, 0, TextureFormat.ARGB32, false);

            string[] exts = { ".png", "" };
            foreach (string ext in exts)
            {
                string filename = path + ext;
                if (File.Exists(filename))
                {
                    r.LoadImage(File.ReadAllBytes(filename));
                    t.texture = r;
                    t.info    = new FileInfo(filename);
                    break;
                }
            }
            return(r);
        }
Ejemplo n.º 2
0
        public static Texture2D GetTexture(string relativePath)
        {
            if (relativePath == "")
            {
                return(null);
            }
            if (textureCache == null)
            {
                textureCache = new Dictionary <string, TexFileInfo>();
            }
            TexFileInfo t;

            if (textureCache.TryGetValue(relativePath, out t))
            {
                if (t.texture != null)
                {
                    var curInfo = new FileInfo(t.info.FullName);
                    if (curInfo.LastWriteTime == t.info.LastWriteTime)
                    {
                        return(t.texture);
                    }
                }
            }
            else
            {
                t = new TexFileInfo();
                textureCache.Add(relativePath, t);
            }
            string path = Path.Combine(SafeHouse.ArchiveFolder, relativePath);
            var    r    = new Texture2D(0, 0, TextureFormat.ARGB32, false);

            string[] exts = { ".png", "" };
            foreach (string ext in exts)
            {
                string filename = path + ext;
                if (File.Exists(filename))
                {
                    r.LoadImage(File.ReadAllBytes(filename));
                    t.texture = r;
                    t.info    = new FileInfo(filename);
                    break;
                }
            }
            return(r);
        }