Esempio n. 1
0
        public override IEnumerable <TexturePackage> CreatePackages(IEnumerable <string> sourceRoots, IEnumerable <string> additionalPackages, IEnumerable <string> blacklist, IEnumerable <string> whitelist)
        {
            // Sprite provider ignores the black/whitelists
            var dirs = sourceRoots.Union(additionalPackages).Where(Directory.Exists).Select(Path.GetFullPath).Select(x => x.ToLowerInvariant()).Distinct().ToList();
            var tp   = new TexturePackage(String.Join(";", dirs), "sprites", this)
            {
                IsBrowsable = false
            };

            foreach (var dir in dirs)
            {
                var sprs = Directory.GetFiles(dir, "*.spr", SearchOption.AllDirectories);
                if (!sprs.Any())
                {
                    continue;
                }

                foreach (var spr in sprs)
                {
                    var size = GetSize(spr);
                    var rel  = Path.GetFullPath(spr).Substring(dir.Length).TrimStart('/', '\\').Replace('\\', '/');
                    tp.AddTexture(new TextureItem(tp, rel.ToLowerInvariant(), TextureFlags.Transparent, size.Width, size.Height));
                }
            }
            if (!tp.Items.Any())
            {
                yield break;
            }
            yield return(tp);
        }
Esempio n. 2
0
 public TextureItem(TexturePackage package, string name, int width, int height)
 {
     Package = package;
     Name = name;
     Width = width;
     Height = height;
 }
Esempio n. 3
0
 public TextureItem(TexturePackage package, string name, TextureFlags flags)
 {
     Package   = package;
     Name      = name;
     Flags     = flags;
     _subItems = new Dictionary <TextureSubItemType, TextureSubItem>();
 }
Esempio n. 4
0
 public TextureItem(TexturePackage package, string name, TextureFlags flags)
 {
     Package = package;
     Name = name;
     Flags = flags;
     _subItems = new Dictionary<TextureSubItemType, TextureSubItem>();
 }
Esempio n. 5
0
 public TextureItem(TexturePackage package, string name)
 {
     Package        = package;
     Name           = name;
     PrimarySubItem = null;
     _allSubItems   = new List <TextureSubItem>();
 }
Esempio n. 6
0
 public override TexturePackage CreatePackage(string package)
 {
     var tp = new TexturePackage(package, this);
     var list = new List<TextureItem>();
     try
     {
         HLLib.Initialize();
         using (var pack = new HLLib.Package(package))
         {
             var folder = pack.GetRootFolder();
             var items = folder.GetItems();
             list.AddRange(items
                 .Select(item => new HLLib.WADFile(item))
                 .Where(wad => IsValidLumpType(wad.GetLumpType()))
                 .Select(wad => new TextureItem(tp, StripExtension(wad.Name), wad.Width, wad.Height)));
         }
     }
     finally
     {
         HLLib.Shutdown();
     }
     foreach (var ti in list)
     {
         tp.AddTexture(ti);
     }
     return tp;
 }
Esempio n. 7
0
 public TextureItem(TexturePackage package, string name, TextureFlags flags, string primarySubItemName, int width, int height)
 {
     Package = package;
     Name = name;
     Flags = flags;
     var baseItem = new TextureSubItem(TextureSubItemType.Base, this, primarySubItemName, width, height);
     _subItems = new Dictionary<TextureSubItemType, TextureSubItem> {{TextureSubItemType.Base, baseItem}};
 }
Esempio n. 8
0
        private bool LoadFromCache(TexturePackage package)
        {
            if (CachePath == null || !Directory.Exists(CachePath))
            {
                return(false);
            }

            var fi        = new FileInfo(package.PackageRoot);
            var cacheFile = Path.Combine(CachePath, fi.Name + "_" + (fi.LastWriteTime.Ticks));

            if (!File.Exists(cacheFile))
            {
                return(false);
            }

            var lines = File.ReadAllLines(cacheFile);

            if (lines.Length < 3)
            {
                return(false);
            }
            if (lines[0] != fi.FullName)
            {
                return(false);
            }
            if (lines[1] != fi.LastWriteTime.ToFileTime().ToString(CultureInfo.InvariantCulture))
            {
                return(false);
            }
            if (lines[2] != fi.Length.ToString(CultureInfo.InvariantCulture))
            {
                return(false);
            }

            try
            {
                var items = new List <TextureItem>();
                foreach (var line in lines.Skip(3))
                {
                    var spl       = line.Split(NullCharacter);
                    var reference = spl[0];
                    var name      = reference.Substring("textures/".Length);
                    name = name.Substring(0, name.Length - 4);
                    items.Add(new TextureItem(package, name, GetFlags(spl[0]), int.Parse(spl[1], CultureInfo.InvariantCulture), int.Parse(spl[2], CultureInfo.InvariantCulture))
                    {
                        Reference = reference
                    });
                }
                items.ForEach(package.AddTexture);
            }
            catch
            {
                // Cache file is no good...
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
 public TextureItem(TexturePackage package, string name, string primarySubItemName, int width, int height)
 {
     Package        = package;
     Name           = name;
     PrimarySubItem = new TextureSubItem(this, primarySubItemName, width, height);
     _allSubItems   = new List <TextureSubItem> {
         PrimarySubItem
     };
 }
Esempio n. 10
0
 public override TexturePackage CreatePackage(IFile package)
 {
     var tp = new TexturePackage(package, this);
     var items = package.GetFiles(".*\\.spr$", true)
         .Select(x => CreateTextureItem(tp, x));
     foreach (var ti in items)
     {
         tp.AddTexture(ti);
     }
     return tp;
 }
Esempio n. 11
0
        public TextureItem(TexturePackage package, string name, TextureFlags flags, string primarySubItemName, int width, int height)
        {
            Package = package;
            Name    = name;
            Flags   = flags;
            var baseItem = new TextureSubItem(TextureSubItemType.Base, this, primarySubItemName, width, height);

            _subItems = new Dictionary <TextureSubItemType, TextureSubItem> {
                { TextureSubItemType.Base, baseItem }
            };
        }
Esempio n. 12
0
 public override TexturePackage CreatePackage(string package)
 {
     var tp = new TexturePackage(package, this);
     var items = Directory.GetFiles(package, "*.spr", SearchOption.AllDirectories)
         .Select(x => CreateTextureItem(tp, x));
     foreach (var ti in items)
     {
         tp.AddTexture(ti);
     }
     return tp;
 }
Esempio n. 13
0
        private void SaveToCache(TexturePackage package)
        {
            if (CachePath == null || !Directory.Exists(CachePath))
            {
                return;
            }
            var fi        = new FileInfo(package.PackageRoot);
            var cacheFile = Path.Combine(CachePath, fi.Name + "_" + (fi.LastWriteTime.Ticks));
            var lines     = new List <string>();

            lines.Add(fi.FullName);
            lines.Add(fi.LastWriteTime.ToFileTime().ToString(CultureInfo.InvariantCulture));
            lines.Add(fi.Length.ToString(CultureInfo.InvariantCulture));
            foreach (var ti in package.Items.Values)
            {
                lines.Add(ti.Name + NullCharacter + ti.Width.ToString(CultureInfo.InvariantCulture) + NullCharacter + ti.Height.ToString(CultureInfo.InvariantCulture));
            }
            File.WriteAllLines(cacheFile, lines);
        }
Esempio n. 14
0
        public override IEnumerable<TexturePackage> CreatePackages(IEnumerable<string> sourceRoots, IEnumerable<string> additionalPackages, IEnumerable<string> blacklist, IEnumerable<string> whitelist)
        {
            // Sprite provider ignores the black/whitelists
            var dirs = sourceRoots.Union(additionalPackages).Where(Directory.Exists).Select(Path.GetFullPath).Select(x => x.ToLowerInvariant()).Distinct().ToList();
            var tp = new TexturePackage(String.Join(";", dirs), "sprites", this) {IsBrowsable = false};
            foreach (var dir in dirs)
            {
                var sprs = Directory.GetFiles(dir, "*.spr", SearchOption.AllDirectories);
                if (!sprs.Any()) continue;

                foreach (var spr in sprs)
                {
                    var size = GetSize(spr);
                    var rel = Path.GetFullPath(spr).Substring(dir.Length).TrimStart('/', '\\').Replace('\\', '/');
                    tp.AddTexture(new TextureItem(tp, rel.ToLowerInvariant(), TextureFlags.Transparent, size.Width, size.Height));
                }
            }
            if (!tp.Items.Any()) yield break;
            yield return tp;
        }
Esempio n. 15
0
        private TexturePackage CreatePackage(string package)
        {
            try
            {
                var fi = new FileInfo(package);
                if (!fi.Exists)
                {
                    return(null);
                }

                var tp = new TexturePackage(package, Path.GetFileNameWithoutExtension(package), this);
                if (LoadFromCache(tp))
                {
                    return(tp);
                }

                var pack = _roots.Values.FirstOrDefault(x => x.Package.PackageFile.FullName == fi.FullName);
                if (pack == null)
                {
                    _roots.Add(tp, pack = new Pk3Stream(new ZipPackage(fi)));
                }

                foreach (var file in pack.Package.SearchFiles("textures", @"\.(jpg|png|tga)$", true))
                {
                    var size  = GetImageSize(pack.StreamSource, file);
                    var fname = file.Substring("textures/".Length);
                    fname = fname.Substring(0, fname.Length - 4);
                    var ti = new TextureItem(tp, fname, GetFlags(fname), size.Width, size.Height)
                    {
                        Reference = file
                    };
                    tp.AddTexture(ti);
                }
                SaveToCache(tp);
                return(tp);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 16
0
        private TexturePackage CreatePackage(string package)
        {
            try
            {
                var fi = new FileInfo(package);
                if (!fi.Exists)
                {
                    return(null);
                }

                var tp = new TexturePackage(package, Path.GetFileNameWithoutExtension(package), this);
                if (LoadFromCache(tp))
                {
                    return(tp);
                }

                var list = new List <TextureItem>();

                var pack = _roots.Values.FirstOrDefault(x => x.Package.PackageFile.FullName == fi.FullName);
                if (pack == null)
                {
                    _roots.Add(tp, pack = new WadStream(new WadPackage(fi)));
                }

                list.AddRange(pack.Package.GetEntries().OfType <WadEntry>().Select(x => new TextureItem(tp, x.Name, GetFlags(x.Name), (int)x.Width, (int)x.Height)));
                foreach (var ti in list)
                {
                    tp.AddTexture(ti);
                }
                SaveToCache(tp);
                return(tp);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 17
0
 private void SaveToCache(TexturePackage package)
 {
     if (CachePath == null || !Directory.Exists(CachePath)) return;
     var fi = new FileInfo(package.PackageFile.FullPathName);
     var cacheFile = Path.Combine(CachePath, fi.Name + "_" + (fi.LastWriteTime.Ticks));
     var lines = new List<string>();
     lines.Add(fi.FullName);
     lines.Add(fi.LastWriteTime.ToFileTime().ToString(CultureInfo.InvariantCulture));;
     lines.Add(fi.Length.ToString(CultureInfo.InvariantCulture));
     foreach (var ti in package.Items.Values)
     {
         lines.Add(ti.Name + NullCharacter + ti.Width.ToString(CultureInfo.InvariantCulture) + NullCharacter + ti.Height.ToString(CultureInfo.InvariantCulture));
     }
     File.WriteAllLines(cacheFile, lines);
 }
Esempio n. 18
0
        private bool LoadFromCache(TexturePackage package)
        {
            if (CachePath == null || !Directory.Exists(CachePath)) return false;

            var fi = new FileInfo(package.PackageFile.FullPathName);
            var cacheFile = Path.Combine(CachePath, fi.Name + "_" + (fi.LastWriteTime.Ticks));
            if (!File.Exists(cacheFile)) return false;

            var lines = File.ReadAllLines(cacheFile);
            if (lines.Length < 3) return false;
            if (lines[0] != fi.FullName) return false;
            if (lines[1] != fi.LastWriteTime.ToFileTime().ToString(CultureInfo.InvariantCulture)) return false;
            if (lines[2] != fi.Length.ToString(CultureInfo.InvariantCulture)) return false;

            try
            {
                var items = new List<TextureItem>();
                foreach (var line in lines.Skip(3))
                {
                    var spl = line.Split(NullCharacter);
                    items.Add(new TextureItem(package, spl[0], int.Parse(spl[1], CultureInfo.InvariantCulture), int.Parse(spl[2], CultureInfo.InvariantCulture)));
                }
                items.ForEach(package.AddTexture);
            }
            catch
            {
                // Cache file is no good...
                return false;
            }
            return true;
        }
Esempio n. 19
0
        private TexturePackage CreatePackage(string package)
        {
            try
            {
                var fi = new FileInfo(package);
                if (!fi.Exists) return null;

                var tp = new TexturePackage(package, Path.GetFileNameWithoutExtension(package), this);
                if (LoadFromCache(tp)) return tp;

                var list = new List<TextureItem>();

                var pack = _roots.Values.FirstOrDefault(x => x.Package.PackageFile.FullName == fi.FullName);
                if (pack == null) _roots.Add(tp, pack = new WadStream(new WadPackage(fi)));

                list.AddRange(pack.Package.GetEntries().OfType<WadEntry>().Select(x => new TextureItem(tp, x.Name, GetFlags(x.Name), (int) x.Width, (int) x.Height)));
                foreach (var ti in list)
                {
                    tp.AddTexture(ti);
                }
                SaveToCache(tp);
                return tp;
            }
            catch
            {
                return null;
            }
        }
Esempio n. 20
0
 private TextureItem CreateTextureItem(TexturePackage package, string name)
 {
     var bmp = Parse(new FileInfo(name));
     return new TextureItem(package, name.Substring(package.PackageFile.Length).TrimStart(Path.DirectorySeparatorChar), bmp.Width, bmp.Height);
 }
Esempio n. 21
0
 private string GetFileName(TexturePackage package, IFile file)
 {
     var path = file.GetRelativePath(package.PackageFile).ToLower();
     path = path.Replace('\\', '/');
     return path;
 }
Esempio n. 22
0
 private TextureItem CreateTextureItem(TexturePackage package, IFile file)
 {
     var size = GetSize(file);
     return new TextureItem(package, GetFileName(package, file), size.Width, size.Height);
 }