コード例 #1
0
        private ResourceType GetResourceType(string fileName, ResourceType type)
        {
            var ext = Path.GetExtension(fileName)?.ToLower();

            if (type == ResourceType.ImageJpeg || type == ResourceType.ImagePng)
            {
                if (ext == ".png")
                {
                    return(ResourceType.ImagePng);
                }
                else
                {
                    return(ResourceType.ImageJpeg);
                }
            }
            else if (type == ResourceType.LutCube || type == ResourceType.LutPng)
            {
                if (ext == ".png")
                {
                    return(ResourceType.LutPng);
                }
                else
                {
                    return(ResourceType.LutCube);
                }
            }
            else
            {
                return(type);
            }
        }
コード例 #2
0
        internal string AddResource(string fileName, byte[] data, ResourceType type)
        {
            var name = Path.GetFileNameWithoutExtension(fileName);

            var res = _coreData.Create <IResource>();
            var now = DateTime.UtcNow;

            res.LastUse = now;
            res.Data    = data;
            res.Info    = new ResourceInfo {
                Added = now, Type = GetResourceType(fileName, type), Name = name, DataHash = GetHash(data)
            };

            var id = IdGenerator.New();

            SaveToFile(id, data);
            lock (_cache)
                _cache[id] = data;
            _coreData.Root.Resources[id] = res;
            return(id);
        }